Hi Martin, commenting on your code:
On Wed, 10 Jul 2019 08:51:08 -0500 "Martin McCormick" <marti...@suddenlink.net> wrote: > Before I take this too far, I want to make sure I am not > doing something wrong with use of the Device::SerialPort module > in perl. > > The code below talks to what it thinks is a RS-232 serial > port and controlls a radio scanner so that one can program the > scanner's settings and enter frequency and operational data. > Don't worry about all that. It used to work on debian stretch > which is last year's version of debian. After an upgrade to > buster which is this year's version, also known as debian 10, all > RS-232 ports appear to be dead. Interestingly enough, a debian > system running stretch, containing perl was upgraded to buster > and serial communications between that system and a native serial > port on it's mother board are fine. The very same code ported to > the buster system also fails with > Can't call method "baudrate" on an undefined value at /home/martin/etc/mm > line 121. > > It doesn't matter what serial port or whether it is > native mother board hardware or what. Serial ports are all > broken right now. > > Here is the scanner control code. I am sending it to see > if I am using some deprecated method that is wrong to set the > serial port or we really do have big trouble. > > Thanks for any and all constructive ideas. Code follows: > > > > #!/usr/bin/perl -w See https://perl-begin.org/tutorials/bad-elements/#the-dash-w-flag . > use strict; good! > use warnings::unused; > use File::Basename; > use File::Copy; > use File::Spec; > use Time::Local; > use Device::SerialPort; > Use explicit imports - https://perl-begin.org/tutorials/bad-elements/#non_explicitly_imported_symbols > sub waitfor { #Receive from serial port. > > my $received = ""; > our $port; "our" inside a function? > > until ( "" ne $received ) { double negative and perhaps use https://stackoverflow.com/questions/223393/how-do-i-get-the-length-of-a-string-in-perl > $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"; > our $instring = ""; > our $port = Device::SerialPort->new("$dev"); why our? > $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 see https://perl-begin.org/tutorials/bad-elements/#non_lexical_loop_iterators > $ONEARG =~ s/^\s+//; > $ONEARG =~ s/\s+$//; perhaps use \A and \z > $cmd = $cmd . " " . $ONEARG; use ".=" > $cmd =~ s/^\s+//; > $cmd =~ s/\s+$//; > } #each argument > > $cmd = uc $cmd; > $port->write("$cmd\r"); > $instring = waitfor; see https://perl-begin.org/tutorials/bad-elements/#declaring_all_vars_at_top . > my @chars = split( "", $instring ); > foreach my $char (@chars) { # > > #print ord($char); > if ( $char =~ /[\,\s\.\-\+\_0-9A-Za-z]/ ) { #printable > $response = $response . $char; use .= and you can use https://perldoc.perl.org/functions/join.html and regex matches. it is good that you follow https://perl-begin.org/tutorials/bad-elements/#using-character-classes-with-unicode-text . > } #printable > } # > print "$response\n"; > $instring = ""; > exit(0); > Why the assignment right before exiting? I'm not sure if any of the issues I pointed are the culprit. -- ----------------------------------------------------------------- Shlomi Fish http://www.shlomifish.org/ https://github.com/sindresorhus/awesome - curated list of lists Chuck Norris does not code; when he sits at a computer, it just does whatever he wants. — Kattana on Freenode’s #perl6 . — http://www.shlomifish.org/humour/bits/facts/Chuck-Norris/ Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/