develooper Front page | perl.beginners | Postings from March 2002

Re: perl serial port program

Thread Previous
From:
Papo Napolitano
Date:
March 1, 2002 15:36
Subject:
Re: perl serial port program
Message ID:
003801c1c179$de2ded80$fe00000a@exodo
You should change the line

    die "Device::SerialPort Aborted without match\n" unless (defined $data);

to read

    die "Device::SerialPort Aborted without match\n" unless (defined
$bytein);

But be careful because the 'lookfor' method causes Device::SerialPort to
return an entire line (up to the first \n or \r)...
If you intend to read -only- one char, you should check Device::SerialPort
docs... There's plenty of examples =)

Later.-



----- Original Message -----
From: Jeff Liu
To: Papo Napolitano ; Beginners
Sent: Friday, March 01, 2002 17:17
Subject: RE: perl serial port program



Hi Papo,

Thank you very much for your information. I can send to serial port from my
script now. But when I try to read from the port, my script died and showed
"Device::SerialPort Aborted without match". Do you have any idea about how
can I fix the problem? My script is as followed.


#!/usr/bin/perl

use Device::SerialPort;

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

while (1)
{
  $bytein="";
  $port->lookclear;
  $port->write("Feed Me:");
  $port->write("#");

  while ($bytein eq "")
  {
    $bytein = $port->lookfor;
    die "Device::SerialPort Aborted without match\n" unless (defined $data);
    sleep 1;
  }
  print "$bytein\n";
}

$port->close();


Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About