Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.debian.user > #211196
| From | David Christensen <dpchrist@holgerdanske.com> |
|---|---|
| Newsgroups | linux.debian.user |
| Subject | Re: Upgrade to Buster and perl Device::SerialPort |
| Date | 2019-07-11 05:00 +0200 |
| Message-ID | <yixtn-rv-1@gated-at.bofh.it> (permalink) |
| References | <yi6CR-xj-1@gated-at.bofh.it> <yia3L-2oh-1@gated-at.bofh.it> <yioJr-2Ut-15@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
On 7/10/19 10:39 AM, Martin McCormick wrote:
> David Christensen <dpchrist@holgerdanske.com> writes:
>> Post a console session showing the commands issued and the error messages
>> produced.
>
> I'll go you one better. I'll show the code of one of the
> programs that dies instantly. It uses /dev/ttyACM0 which is the
> device created when a Uniden scanner radio is plugged in to a usb
> port. I also have the program that controls a RS-232 modem and
> uses /dev/ttyS0 and gives the same results but contains more
> lines so let's go with the scanner program.
>
> Here's the console session short but not sweet.
>
> Script started on 2019-07-10 12:32:35-05:00 [TERM="linux" TTY="/dev/pts/7" COLUMNS="80" LINES="25"]
> 1wb5agz martin tmp $ p2 sts
> Can't call method "baudrate" on an undefined value at /home/martin/etc/p2 line 37.
> 2wb5agz martin tmp $ ls -l /dev/ttyACM0
> crw-rw---- 1 root dialout 166, 0 Jul 10 08:32 /dev/ttyACM0
> 3wb5agz martin tmp $ exit
>
> Script done on 2019-07-10 12:33:21-05:00 [COMMAND_EXIT_CODE="0"]
>
> You used to only see that kind of response if /dev/ttyXXX
> was missing. On rare occasions, the scanner radio's tty would go
> away and one would need to umplug it and reseat the plug to get
> it back and it would then work.
>
> The rest is 66 lines of code for the scanner control
> program.
>
> #!/usr/bin/perl -w
> use strict;
> use warnings::unused;
> use File::Basename;
> use File::Copy;
> use File::Spec;
> use Time::Local;
> use Device::SerialPort;
>
> sub waitfor { #Receive from serial port.
>
> my $received = "";
> our $port;
>
> until ( "" ne $received ) {
> $received = $port->lookfor;
> }
> return ($received);
> } #Receive from serial port.
>
> #no more sub routine code past this point
>
> #main global variables
> our @dbstrings;
>
> #main local variables
> my $response;
> my $cmd = "";
> my $ONEARG = "";
>
> #my $counter = 1;
>
> #Setup the comm port.
> my $dev = "/dev/ttyACM0";
I would use single quotes around the device path, as the string should
not be interpolated.
I would check for existence of the device (-e) and die if not present.
> our $instring = "";
> our $port = Device::SerialPort->new("$dev");
I would not use quotes around $dev.
Please add error checking of return value of new() and try again:
https://metacpan.org/pod/Device::SerialPort#Constructors
$PortObj = new Device::SerialPort ($PortName, $quiet, $lockfile)
|| die "Can't open $PortName: $!\n";
> $port->baudrate(115200);
> $port->databits(8);
> $port->parity("none");
> $port->stopbits(1);
> $port->handshake("none");
> $port->read_const_time(500); # 500 milliseconds = 0.5 seconds
> $port->are_match( "\r", "\n", ); # possible end strings
>
> foreach $ONEARG (@ARGV) { #each argument
> $ONEARG =~ s/^\s+//;
> $ONEARG =~ s/\s+$//;
> $cmd = $cmd . " " . $ONEARG;
> $cmd =~ s/^\s+//;
> $cmd =~ s/\s+$//;
> } #each argument
>
> $cmd = uc $cmd;
> $port->write("$cmd\r");
> $instring = waitfor;
> my @chars = split( "", $instring );
> foreach my $char (@chars) { #
>
> #print ord($char);
> if ( $char =~ /[\,\s\.\-\+\_0-9A-Za-z]/ ) { #printable
> $response = $response . $char;
> } #printable
> } #
> print "$response\n";
> $instring = "";
> exit(0);
>
Back to linux.debian.user | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Upgrade to Buster and perl Device::SerialPort "Martin McCormick" <martin.m@suddenlink.net> - 2019-07-10 00:20 +0200
Re: Upgrade to Buster and perl Device::SerialPort David Christensen <dpchrist@holgerdanske.com> - 2019-07-10 04:00 +0200
Re: Upgrade to Buster and perl Device::SerialPort "Martin McCormick" <martin.m@suddenlink.net> - 2019-07-10 19:40 +0200
Re: Upgrade to Buster and perl Device::SerialPort David Christensen <dpchrist@holgerdanske.com> - 2019-07-11 05:00 +0200
Re: Upgrade to Buster and perl Device::SerialPort <tomas@tuxteam.de> - 2019-07-11 10:30 +0200
solved! Upgrade to Buster and perl Device::SerialPort "Martin McCormick" <martin.m@suddenlink.net> - 2019-07-11 21:30 +0200
Re: solved! Upgrade to Buster and perl Device::SerialPort David <bouncingcats@gmail.com> - 2019-07-12 05:40 +0200
Re: Upgrade to Buster and perl Device::SerialPort David Christensen <dpchrist@holgerdanske.com> - 2019-07-12 02:40 +0200
Re: Upgrade to Buster and perl Device::SerialPort <tomas@tuxteam.de> - 2019-07-12 10:10 +0200
csiph-web