The perldoc for Device::SerialPort states that the unix version
is based on the Windows serial port module and a few details are
different or not supported but the important parts are said to
work.

        Strangely enough, the only thing I have gotten to work as
described is the $port->input directive. It does echo strings
being sent to the serial device. Here is code that works:


#!/usr/bin/perl -w
use strict;
use File::Basename;
use File::Copy;
use File::Spec;
use Device::SerialPort;


sub comm {    #serialport

my $dev = "/dev/ttyS0";
my $char = "";
my $port = Device::SerialPort->new ("$dev");
$port->baudrate(9600)   || die "failed setting baudrate";
$port->parity("none")    || die "failed setting parity";
$port->databits(8)       || die "failed setting databits";
$port->handshake("none") || die "failed setting handshake";
$port->write_settings    || die "no settings";

#$port->save("~/etc/testport");
#that doesn't do anything.


 while (1) {
      if (my $c = $port->input) 
      {

print ("$c\n");
      }
        }
return;
}    #serial port

comm;

That does cause input strings to be sent to standard output.

        What is needed, however, is to be able to use the are_match
feature which fills a buffer with data until a pattern is
detected which stops the read and gives you a series of bytes
that may not necessarily end with a newline or carriage return.

        I have never yet gotten anything like the following to
work:

#!/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 comm {    #serialport

my $dev = "/dev/ttyS0";
my $c = "";
my $port = Device::SerialPort->new("$dev");
$port->baudrate(9600); $port->databits(8); $port->parity("none");
$port->stopbits(1); $port->handshake("none");
       $port->write_settings;

         until ("" ne $c) {
        my $c= $port->lookfor;
print ("$c\n") if $c;
}
return;
}    #serial port

comm;

The perldoc for Device::SerialPort indicates that are_match will
default to a newline or carriage return if one does not have
another pattern in an are_match statement such as

         $port->are_match("8");    # possible end strings

The $c string should then contain characters except for the
number 8 which would be the end of that string.

        I have tried it with and without an are_match pattern and
it just roars along, looping endlessly at the lookfor statement
and never picking up anything.

What am I missing?

Sincere thanks for any constructive suggestions.

Martin McCormick WB5AGZ

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to