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

RE: perl serial port program

Thread Previous | Thread Next
From:
Jeff Liu
Date:
March 1, 2002 12:20
Subject:
RE: perl serial port program
Message ID:
MMELJKKFCIKABOGBMODCGECFCIAA.jeff@onramp.ca

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();

-----Original Message-----
From: Papo Napolitano [mailto:papo@dosalcubo.com]
Sent: February 28, 2002 5:51 PM
To: Jeff Liu; Beginners
Subject: Re: perl serial port program


I'm using the Device::SerialPort to monitor the logs from our Panasonic
phone system ;)
Take a look at CPAN.

It's as easy as:

use Device::SerialPort;
$port = new Device::SerialPort("/dev/ttyS0");
$port->baudrate(9600);
$port->parity("none");
$port->databits(8);
$port->stopbits(1);
$port->handshake("rts");
$port->write_settings;
while (1) {
  $data = "";
  while (($data = $port->lookfor) eq "") {
    die "Device::SerialPort Aborted without match\n" unless (defined $data);
    select undef, undef, undef, 0.25; # Prevent the program to takeover the
CPU ;)
  }
}

There, in $data you have a line up to the first \n.

HTH.-


----- Original Message -----
From: Jeff Liu
To: Beginners
Sent: Thursday, February 28, 2002 19:00
Subject: perl serial port program



Hi there,

I need to cook a perl script talking to /dev/ttyS0, it will be used to
monitor a RAID device via serial port. But even spending the whole day I was
still not lucky enough to be successful. Could you please show me a way to
deal with it?

Many thanks,
Jeff Liu


--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org


--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org



Thread Previous | Thread Next


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