Click here to get back home

problem with Device::SerialPort

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
problem with Device::SerialPort Michael Hellwig 11-30-2005
Posted by Michael Hellwig on November 30, 2005, 4:19 pm
Please log in for more thread options


Hi.

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
shame.

Anyway.

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.
#0002I1
and receive a value (a pressure) as an answer, which will look like
>8.496E-11
(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
whatever.

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->are_match("\r");
$ob->lookclear;

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

$ob->error_msg(1);
$ob->user_msg(1);

$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 olymp.idle.at admin
to contact me via email, use michael.hellwig@uni-ulm.de
         don't hesitate to look at http://laerm.or.at


Similar ThreadsPosted
Loopback with Device::SerialPort? March 18, 2005, 1:24 pm
Problems with Device-SerialPort May 4, 2006, 2:15 pm
Help compiling Device::SerialPort May 9, 2006, 9:50 am
tie and tie with IO::Multiplex and Device:SerialPort? March 11, 2007, 10:55 am
problem in using win32::SerialPort September 7, 2007, 2:27 am
device::serial October 2, 2007, 1:46 pm
Device::Gsm v1.34 released to CPAN August 18, 2004, 8:53 am
registering name Device::Cdio February 8, 2006, 6:30 pm
Device::Gsm v1.43 released to CPAN July 23, 2006, 11:54 am
Device::Modem v1.39 released to CPAN August 18, 2004, 8:49 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap