Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Win32 Serial Port

Reply
Thread Tools

Win32 Serial Port

 
 
Mitchley
Guest
Posts: n/a
 
      06-03-2004
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://www.velocityreviews.com/forums/(E-Mail 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
 
Reply With Quote
 
 
 
 
Sisyphus
Guest
Posts: n/a
 
      06-03-2004
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 (E-Mail 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


--
To reply by email u have to take out the u in kalinaubears.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Event objects Threading on Serial Port on Win32 Gabriel Python 0 06-27-2006 07:57 PM
Event objects Threading on Serial Port on Win32 elcinturapartida@yahoo.es Python 0 08-18-2005 12:06 PM
win32 serial port suggestions? Levin Alexander Ruby 2 07-20-2005 01:24 AM
win32 serial port listener: poll or interrupt Mountain Drew Perl Misc 1 06-23-2005 08:24 AM
Can I connect router Serial interface directly to a PC serial port? Faustino Dina Cisco 2 08-18-2004 02:30 AM



Advertisments