Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Capturing a serial port with expect

1,744 views
Skip to first unread message

Lee Sweet

unread,
Oct 11, 1998, 3:00:00 AM10/11/98
to
I'm trying what I thought would be trivial, but doesn't seem to work: I
want to capture the input to a serial port (under Linux) and save it to
a file. cat /dev/ttyS1 >> filename in Unix works; spawn cat /dev/ttyS1
>> filename in expect doesn't. The spawn goes out, the expect buffer
has the actual input streamt, but the actual file has nothing (isn't
even created). Is this a buffer-flush issue? Or something more obscure?
I thought this would work, since all I want is to capture input from
another device; no pattern checking, no nothing. I hoped I wouldn't
have to open the device file, and read a line at a time, and how would
that work, anyway, if the input isn't all there yet? (I use timeout to
exit the script; could that have an impact on the cat output file not
being created?) Thanks for any comments!

l...@datatel.com
Lee Sweet/Datatel, Inc.


d.j.h...@acm.org

unread,
Oct 13, 1998, 3:00:00 AM10/13/98
to l...@datatel.com
In article <362139EC...@datatel.com>,

Lee Sweet <l...@datatel.com> wrote:
> I'm trying what I thought would be trivial, but doesn't seem to work: I
> want to capture the input to a serial port (under Linux) and save it to
> a file. cat /dev/ttyS1 >> filename in Unix works; spawn cat /dev/ttyS1
> >> filename in expect doesn't. The spawn goes out, the expect buffer
> has the actual input streamt, but the actual file has nothing (isn't
> even created). Is this a buffer-flush issue? Or something more obscure?

why not use the -open switch to exp_spawn and open the device directly.
I think this is discussed in Libes' book. I use the following to open
a serial port at 1200 baud to talk to a modem:

set device /dev/cua/a
exp_spawn -open [open $device w+]
exp_stty raw < $device
exp_stty -echo istrip parity 1200 crtscts hupcl < $device
. . .

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own

Lee Sweet

unread,
Oct 13, 1998, 3:00:00 AM10/13/98
to
Might work, but here's what I'm trying to do; it might change your answer...!
At about xx:00 (on the hour, that is) a device dumps a report to this serial
port. I need to capture that. I thought opening the port and doing reads
would just EOF, since I can't tell *exactly* when this is going to happen.
The original thought was to start the 'cat' at xx:55 and terminate (timeout)
at xx+1:05, and thus have the input from the port.

Can I read repeatedly, ignore EOF, and have that work?

d.j.h...@acm.org wrote:

> why not use the -open switch to exp_spawn and open the device directly.

> 8<snip>8


0 new messages