[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Serial Ports and Perl

Andy Smith <andy@strugglers.net> writes:
> Hi Martin,

> I have been using it successfully for a long time, but all I do is
> read whole lines from the serial device like:
> my $dev  = '/dev/ttyUSB0';
> my $port = Device::SerialPort->new($dev);
> $port->baudrate(57600);
> $port->write_settings;
> open my $fh, '<', $dev or die "Can't open $dev: $!";

> while (<$fh>) {
>     print "READ: $_\n";
> }
> So, I am only using Device::SerialPort to configure the device,
> while all reading is done by treating it as a normal file.
> I see you are using lookfor(), which I have never used before. From
> a brief look at:
> http://search.cpan.org/~cook/Device-SerialPort-1.002/SerialPort.pm#Methods_for_I/O_Processing
> it seems you should be setting are_match() if you want lookfor() to
> match anything.
> Cheers,
> Andy

I think I am going to call it a day and jump back on it in the
morning but opening the device is something I failed to do.  A
whole new rabit hole to go down and I wouldn't be surprised if
that wasn't the problem all along.

	A perldoc of Device::SerialPort says that lookfor is
supposed to block or hold until a character string emerges from
the port as in /dev/ttyUSB0 or /dev/ttyS1.  When I trace the
code, it just loops as fast as it can and never holds to wait for
anything.  I thought this was strange and if I should have opened
the device, this may explain all the weirdness.  One of the
examples I saw did have a close statement on the device.  I bet I
just missed the need to open a file handle.

	Thanks.  I'll post a message if that worked.

Martin McCormick

Reply to: