problem with Device::SerialPort

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!


I've been googling all afternoon now but wasn't able to find my problem
mentioned someplace, but if for some reason my google-fu was weak,
please direct me to the appropriate place and allow me to hide myself in


What I have:
PC running linux, perl installed, Device::SerialPort is installed.
There is a device (Varian Multigauge) connected via RS232, that should
be sending data to the serial port.
when using minicom, i can send a command like e.g.
and receive a value (a pressure) as an answer, which will look like
Quoted text here. Click to load it
(which only has a carriage return at the end, no linefeed, no newline).

the problem is: this works only once. i.e. I send the command, I get one
answer. What we want: continuous data logging (like e.g. once every 5
seconds) in order to be able to later plot a curve with gnuplot or

So I read the docs for Device::SerialPort and the examples and came up
with the following try to do just what is described above, i.e. send the
command once and receive an answer:

#!/usr/bin/perl -w

# black magic taken from examples that came with the distribution
BEGIN { $| = 1; print "varianlog loaded "; }
END {print "not ok 1\n" unless $loaded;}
use Device::SerialPort;
$loaded = 1;
print "ok 1\n";
# end of black magic

use strict;
my $file = "/dev/tts/0";
my $out;
my $gotit;

my $ob = Device::SerialPort->new($file) || die("Can't open $file: $!\n");

$ob->baudrate(9600)     || die("can't set baudrate\n");
$ob->parity("none")     || die("can't set parity\n");
$ob->databits(8)        || die("can't set databits\n");
$ob->stopbits(1)        || die("can't set stopbits\n");
$ob->handshake("none")  || die("can't set handshake\n");

$ob->write_settings || die("settings failed\n");


$ob->write($out) || die("writing to serial port failed: $!\n");


$gotit = "";
until ("" ne $gotit) {
        $gotit = $ob->lookfor || die("couln't read from device: $!\n");
    die("Abortet without match\n") unless(defined $gotit);
    sleep 1;

print("we have read: $gotit\n");
$ob->close || die("failed to close: $!\n");
undef $ob;

But when I run this, it gets fine up to the point of the lookfor, where
it will fail with "resource temporarily unavailable". When I removed the
lookfor and tried to do just a pure $ob->read, I got "illegal seek" as
an answer. So does anyone have any tips as to what I'm doing wrong here?

Michael Hellwig aka The Eye                 admin
         to contact me via email, use
         don't hesitate to look at

Site Timeline