Government Security
Network Security Resources

Jump to content


Perl, Read/write To Serial Port

- - - - - windows perl
  • Please log in to reply
No replies to this topic

#1 shannon



  • Members
  • 1 posts

Posted 17 November 2010 - 11:28 AM

I need a way to write 3 bytes to a serial port, and then wait until 2 bytes are read from a serial port using Perl. Can use Cygwin or ActivePerl in Windows. Methods already tried listed below.

1) Method in Active Perl
$comPort = "COM4";

read from COM port
open( PORT, $comPort ) or die "Can't open COM1: $!";
$portLine = <PORT>;
close( PORT);

write to COM port
open (PORT, ">>" . $comPort) || die "Cannot open COM1";
print PORT $portLine;

Outcome: For this method you can not read and write with the same open port. As a result the write data is lost/gone before I can get the new port open.

2) Method on Cygwin
( IO-Prompt-0.997001)
use IO::Prompt;

print "1\n";
print "2\n";
print "3\n";

$output1 = prompt ("wait1: ", -1);
print "\n";
$output2 = prompt ("wait2: ", -1);
print "\n";

Outcome: This outputs 3 characters, then waits for two, but i can not get this to interact with a serial port.

3) Method on Cygwin (Expect - 1.15)
Can not figure out how to get expect to communicate with serial port

4) Method on Cygwin (Sys-PortIO-0.1)
Plug in will not install properly, after perl Makefile.PL, make I get the following:
PortIO.o: In function 'XS_Sys_PortIO_port_close':
/home/Tingers/Sys-PortIO-0.1/PortIO.xs:98: undefined reference to '_ioperm'
PortIO.o: In function 'XS_Sys_PortIO_port_open':
/home/Tingers/Sys-PortIO-0.1/PortIO.xs:98: undefined reference to '_ioperm'
make: *** [blib/arch/auto/Sys/PortIO/PortIO.dll] Error 1

Also tagged with one or more of these keywords: windows, perl