Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Loopback with Device::SerialPort?

Thread Tools

Loopback with Device::SerialPort?

Eric Schwartz
Posts: n/a
This is cross-posted to .misc and modules, as I'm not certain where it
belongs. Feel free to redirect the conversation to whichever group
you feel is more appropriate.

I'm trying to verify that I understand how to use Device::SerialPort
on a Linux machine correctly by connecting two serial ports on the
same machine with a crossover serial cable and sending data across the

The problem is that when the child process in the example below tries
to issue its first read() call, I this this error message:

Error #0 in Device::SerialPort::read at ./testserial line 42

I have no idea what this means, and I can't find any information on
what could cause this sort of error message anywhere in the
Device::SerialPort docs. I'm appending my test program below-- it's
not as small as I'd like, but most of that is the serial port setup
code, which has to be in there (AFAIK).

I've tried changing the code to use lookfor() in the child, with
$port2->are_match($STOP_STRING), but that results in a read of 0 bytes
and no error message.

My code:

use warnings;
use strict;
use Device::SerialPort;
use Digest::MD5 qw(md5_hex);

my $port1 = Device::SerialPort->new("/dev/ttyS1");
my $port2 = Device::SerialPort->new("/dev/ttyS2");

for my $port ($port1, $port2) {
$port->write_settings || undef $port;

my $STOP_STRING = "Seriously dude, stop this, like now, even\n";

chomp(my $uname = `uname -r`);
open my $fh, "<", "/boot/vmlinuz-$uname" or die "Can't open kernel file: $!";
if (my $pid = fork) {
my $accum;
while(read($fh, my $buf, 255)) {
$accum .= $buf;
print "In parent, md5sum is: ", md5_hex($accum), "\n";
} else {
die "cannot fork: $!" unless defined $pid;
my $buf;
while (1) {
my ($count, $line) = $port2->read(255);
next unless $count;
last if $line eq $STOP_STRING;
$buf .= $line;
print "Child read $count bytes, total: ", length $buf , "\n";
print "In child, md5sum is: ", md5_hex($buf), "\n";

Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
-- Blair Houghton.
Reply With Quote

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
Re: Catalyst 2950: front-end loopback test Brian Cisco 1 11-07-2007 09:16 PM
FIREFOX LOOPBACK CONNECTION ISSUE mimayin Firefox 4 03-06-2004 10:23 PM
how to get rid of loopback packets? kain Cisco 4 11-21-2003 04:13 AM
Ip Address Mapping Loopback Jeff Fan Cisco 1 07-25-2003 12:45 PM
Re: Nat Loopback Walter Roberson Cisco 1 07-24-2003 03:26 AM