Win32 Serial Port

Discussion in 'Perl Misc' started by Mitchley, Jun 3, 2004.

  1. Mitchley

    Mitchley Guest

    Hey,
    I'm new to Perl - so this may be extremely trivial, but anyway, here's
    my problem:

    I am trying to write a script that simply opens a Serial Port under
    Windows and enables remote execution of commands - I found a module at
    cpan.org - the code looks like this:


    #!/usr/bin/perl
    #---------------------------------------------------------------------------
    # Title:
    # Cross-Platform Demo - "use" right module on either Win32 or
    linux
    # Usage:
    # perl any_os.plx PORT
    # Author:
    # Bruce Winter
    http://members.home.net/winters
    #---------------------------------------------------------------------------

    # must be LF-only line ends to run on both platforms

    use strict;
    use vars qw($OS_win);

    BEGIN {
    $OS_win = ($^O eq "MSWin32") ? 1 : 0;

    print "Perl version: $]\n";
    print "OS version: $^O\n";

    # This must be in a BEGIN in order for the 'use' to be
    conditional
    if ($OS_win) {
    print "Loading Windows module\n";
    eval "use Win32::SerialPort";
    die "$@\n" if ($@);

    }

    } # End BEGIN

    die "\nUsage: perl any_os.plx PORT\n" unless (@ARGV);
    my $port = shift @ARGV;

    my $serial_port;

    if ($OS_win) {
    $serial_port = Win32::SerialPort->new ($port,1);
    }

    die "Can't open serial port $port: $^E\n" unless ($serial_port);

    my $baud = $serial_port->baudrate;
    print "\nopened serial port $port at $baud baud\n";

    $serial_port->close || die "\nclose problem with $port\n";
    undef $serial_port;

    --------------------------------------------------------------------------

    The methods new and close are defined in SerialPort.pm.
    I added the file SerialPort.pm to C:/Perl/site/lib/Win32 and the file
    CommPort.pm to C:/Perl/site/lib/Win32API.

    For some reason, I get this error msg:
    Error Msg:
    Perl version: 5.006001
    OS version: MSWin32
    Loading Windows module
    Can't locate Win32/API.pm in @INC <@INC contains: C:/Perl/lib
    C:/Perl/site/lib .

    Can someone tell me what's going on, or provide me with an alternative
    method?

    Thanks,
    Mahesh
     
    Mitchley, Jun 3, 2004
    #1
    1. Advertising

  2. Mitchley

    Sisyphus Guest

    Mitchley wrote:
    > Hey,
    > I'm new to Perl - so this may be extremely trivial, but anyway, here's
    > my problem:
    >
    > I am trying to write a script that simply opens a Serial Port under
    > Windows and enables remote execution of commands - I found a module at
    > cpan.org - the code looks like this:
    >
    >
    > #!/usr/bin/perl
    > #---------------------------------------------------------------------------
    > # Title:
    > # Cross-Platform Demo - "use" right module on either Win32 or
    > linux
    > # Usage:
    > # perl any_os.plx PORT
    > # Author:
    > # Bruce Winter
    > http://members.home.net/winters
    > #---------------------------------------------------------------------------
    >
    > # must be LF-only line ends to run on both platforms
    >
    > use strict;
    > use vars qw($OS_win);
    >
    > BEGIN {
    > $OS_win = ($^O eq "MSWin32") ? 1 : 0;
    >
    > print "Perl version: $]\n";
    > print "OS version: $^O\n";
    >
    > # This must be in a BEGIN in order for the 'use' to be
    > conditional
    > if ($OS_win) {
    > print "Loading Windows module\n";
    > eval "use Win32::SerialPort";
    > die "$@\n" if ($@);
    >
    > }
    >
    > } # End BEGIN
    >
    > die "\nUsage: perl any_os.plx PORT\n" unless (@ARGV);
    > my $port = shift @ARGV;
    >
    > my $serial_port;
    >
    > if ($OS_win) {
    > $serial_port = Win32::SerialPort->new ($port,1);
    > }
    >
    > die "Can't open serial port $port: $^E\n" unless ($serial_port);
    >
    > my $baud = $serial_port->baudrate;
    > print "\nopened serial port $port at $baud baud\n";
    >
    > $serial_port->close || die "\nclose problem with $port\n";
    > undef $serial_port;
    >
    > --------------------------------------------------------------------------
    >
    > The methods new and close are defined in SerialPort.pm.
    > I added the file SerialPort.pm to C:/Perl/site/lib/Win32 and the file
    > CommPort.pm to C:/Perl/site/lib/Win32API.
    >
    > For some reason, I get this error msg:
    > Error Msg:
    > Perl version: 5.006001
    > OS version: MSWin32
    > Loading Windows module
    > Can't locate Win32/API.pm in @INC <@INC contains: C:/Perl/lib
    > C:/Perl/site/lib .


    Looks like you're missing the Win32::API module. If you're running
    ActiveState-built perl try (while conected to the internet):
    ppm install Win32-API.ppd

    Cheers,
    Rob


    --
    To reply by email u have to take out the u in kalinaubears.
     
    Sisyphus, Jun 3, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    589
  2. Gabriel
    Replies:
    0
    Views:
    324
    Gabriel
    Jun 27, 2006
  3. Pom
    Replies:
    2
    Views:
    1,675
    Bas-i
    Jan 31, 2007
  4. Levin Alexander

    win32 serial port suggestions?

    Levin Alexander, Jul 19, 2005, in forum: Ruby
    Replies:
    2
    Views:
    135
    Dibya Prakash
    Jul 20, 2005
  5. msalerno
    Replies:
    3
    Views:
    412
    Ilmari Karonen
    Jul 14, 2005
Loading...

Share This Page