Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.debian.user > #188364

Serial Ports and Perl

From "Martin McCormick" <martin.m@suddenlink.net>
Newsgroups linux.debian.user
Subject Serial Ports and Perl
Date 2017-10-27 02:50 +0200
Message-ID <uF10t-4gy-3@gated-at.bofh.it> (permalink)
Organization linux.* mail to news gateway

Show all headers | View raw


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

Back to linux.debian.user | Previous | Next — Next in thread | Find similar | Unroll thread


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