Win32 Serial Port

M

Mitchley

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 (e-mail address removed)
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
 
S

Sisyphus

Mitchley said:
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 (e-mail address removed)
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top