Web lists-archives.com

Serial Ports and Perl

The perl list I subscribe to seems to be on the fritz or I would
take the question there.  I want to write code that receives from
a RS-232 port and I just can't seem to get it to do anything.

	The port I am reading is connected to a scanner radio and
produces generally short lines of text such as CD13, - or +, each
followed by a carriage return so these data should be very easy
to read.

	If I use the kermit program, I do see the data when the
radio receives a signal but if I run the following script which
should hold and wait for some data, it holds and waits forever
even when data are present

#!/usr/bin/perl -w
use strict;
use Device::SerialPort;

sub comm {    #serialport

my $port = Device::SerialPort->new("/dev/ttyUSB0");
$port->baudrate(9600); # Configure this to match your device
#This is supposed to flush the buffers.
#This causes an infinite loop so it should hang and receive
while (1) {
       my $char = $port->lookfor;
#When there is nothing, go back and keep retrying.
    if ($char) {
       print "$char\n";
}    #serial port

#Call the subroutine.


	If this was working, it would show a column of all the
ASCII characters being received.  /dev/ttyUSB0 is a valid device
and works when used with kermit or even a C program I wrote.

	If anybody has gotten the perl Device::SerialPort to
work, I am interested to know what I am doing or not doing.

	Thank you for any constructive ideas.

Martin McCormick  WB5AGZ