crtjer has asked for the wisdom of the Perl Monks concerning the following question:

Hello all I'm a newbie to Perl and I seem to be having a problem, here is the sample code:
#!C:/Program Files/ActivePerl/ActivePerl/perl/bin -w # This is an example file showing how to send data to the serial port. # # It does not include error checking. # use strict; #use Device::SerialPort; # on UNIX use Win32::SerialPort; # on Windows sub openPort($); sub closePort($); #my $DEVICE = "/dev/ttyS1"; # on UNIX my $DEVICE = "COM1"; # on Windows my $serial = openPort($DEVICE); $serial->write("Hello World"); closePort($serial); #********************************************************************* +***** #* Serial functions #********************************************************************* +***** #* Open raw serial port using: #* 8 data bits #* 1 stop bit #* 19200 bps #* no parity sub openPort($) { my ($device) = @_; #my $serial = Device::SerialPort->new ($device, 1); # on UNIX my $serial = Win32::SerialPort->new ($device, 1); # on Windows die "Can't open serial port $serial: $^E\n" unless ($serial); $serial->user_msg(1); $serial->databits(8); $serial->baudrate(19200); $serial->parity("none"); $serial->stopbits(1); $serial->handshake("rts"); return $serial; } sub closePort($) { my ($serial) = @_; $serial->close(); }
It's saying at use Win32::SerialPort. That the compilation failed in require. I have SerialPort.pm and its under the Win32 directory in my lib. Thanks a bunch.

Replies are listed 'Best First'.
Re: Win32::SerialPort - compilation failed in require
by akho (Hermit) on May 02, 2007 at 14:52 UTC
    Upd Post fixed, this is redundant.

    Please use <code> tags around your code. It will look better:

    #!C:/Program Files/ActivePerl/ActivePerl/perl/bin -w # This is an example file showing how to send data to the serial port. # # It does not include error checking. # use strict; #use Device::SerialPort; # on UNIX use Win32::SerialPort; # on Windows sub openPort($); sub closePort($); #my $DEVICE = "/dev/ttyS1"; # on UNIX my $DEVICE = "COM1"; # on Windows my $serial = openPort($DEVICE); $serial->write("Hello World"); closePort($serial); #********************************************************************* +***** #* Serial functions #********************************************************************* +***** #* Open raw serial port using: #* 8 data bits #* 1 stop bit #* 19200 bps #* no parity sub openPort($) { my ($device) = @_; #my $serial = Device::SerialPort->new ($device, 1); # on UNIX my $serial = Win32::SerialPort->new ($device, 1); # on Windows die "Can't open serial port $serial: $^E\n" unless ($serial); $serial->user_msg(1); $serial->databits(8); $serial->baudrate(19200); $serial->parity("none"); $serial->stopbits(1); $serial->handshake("rts"); return $serial; } sub closePort($) { my ($serial) = @_; $serial->close(); }
Re: Win32::SerialPort - compilation failed in require
by syphilis (Archbishop) on May 02, 2007 at 15:25 UTC
    Hi,
    IIRC, Win32::SerialPort needs Win32::API - and if you don't have Win32::API, you'll get the type of error that you described. (It's best to provide a copy'n'paste of the error message, rather than a synopsis of it - as the synopsis will often fail to include relevant pieces of information :-)

    Cheers,
    Rob
      I apologize I'm using Eclipse Perl Integration. I have Win32::API as well. I'm using Active Perl. If I run the command "perl sample.pl" I get this:
      "Can't locate loadable object for module Device::SerialPort in @INC (@ +INC contain s: C:/Program Files/ActivePerl/ActivePerl/perl/site/lib C:/Program Fil +es/ActiveP erl/ActivePerl/perl/lib .) at com.pl line 10 Compilation failed in require at com.pl line 10. BEGIN failed--compilation aborted at com.pl line 10."
        That message is telling you that, although Device/SerialPort.pm can be found, the "loadable object" (namely auto/Device/SerialPort/SerialPort.dll), which would be a critical piece of the Device::SerialPort package, cannot be found. You shouldn't need to use Device::SerialPort on Win32 - and if you do need it, then I think you're in trouble. Afaik it has never been built on Win32.

        Best thing to do is to remove all references to it from your code, and concentrate on getting things to work using just Win32::SerialPort.

        Cheers,
        Rob