Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.debian.user > #188369
| From | Henning Follmann <hfollmann@itcfollmann.com> |
|---|---|
| Newsgroups | linux.debian.user |
| Subject | Re: Serial Ports and Perl |
| Date | 2017-10-27 04:00 +0200 |
| Message-ID | <uF26d-4XK-1@gated-at.bofh.it> (permalink) |
| References | <uF10t-4gy-3@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
On Thu, Oct 26, 2017 at 07:37:07PM -0500, Martin McCormick wrote:
> 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
> $port->databits(8);
> $port->parity("none");
> $port->stopbits(1);
> $port->handshake("none");
> $port->write_settings;
> #This is supposed to flush the buffers.
> $port->lookclear;
> #This causes an infinite loop so it should hang and receive
> #characters.
> while (1) {
> my $char = $port->lookfor;
> #When there is nothing, go back and keep retrying.
> if ($char) {
> print "$char\n";
> }
> }
> return;
> } #serial port
>
> #Call the subroutine.
>
> comm;
>
> 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
>
This is a good starting point:
http://www.tldp.org/HOWTO/Serial-Programming-HOWTO/
It is not perl centric (c in fact). But it tells you the general basics for
serial communication.
-H
--
Henning Follmann | hfollmann@itcfollmann.com
Back to linux.debian.user | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Serial Ports and Perl "Martin McCormick" <martin.m@suddenlink.net> - 2017-10-27 02:50 +0200
Re: Serial Ports and Perl Andy Smith <andy@strugglers.net> - 2017-10-27 03:50 +0200
Re: Serial Ports and Perl "Martin McCormick" <martin.m@suddenlink.net> - 2017-10-27 04:40 +0200
Re: Serial Ports and Perl Richard Hector <richard@walnut.gen.nz> - 2017-10-27 06:50 +0200
Re: Serial Ports and Perl "Martin McCormick" <martin.m@suddenlink.net> - 2017-10-27 18:50 +0200
Re: Serial Ports and Perl Henning Follmann <hfollmann@itcfollmann.com> - 2017-10-27 04:00 +0200
Re: Serial Ports and Perl Fred <fred@blakemfg.com> - 2017-10-27 04:20 +0200
csiph-web