[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Reading data from serial port into pipe?

On Mon, Feb 04, 2008 at 02:09:01PM +0100, u7l11ey@mail.lrz-muenchen.de wrote:
> Hello all,
> I have Debian running on a Linksys NSLU2:
> slug:~# uname -a
> Linux slug 2.6.18-5-ixp4xx #1 Sun Dec 23 05:17:39 UTC 2007 armv5tel GNU/Linux
> With this nifty little machine, I want to log data from my solar heating
> controller. The controller send data over a serial line attached to a
> USB-to-Serial converter on the slug's USB2 port. I can read data from this
> port just fine with "cat /dev/ttyUSB0" and also write these data into a
> file using "cat /dev/ttyUSB0 > filename". So far so good.
> However, I want to process these data in "real time" by piping them into a
> script that uses sed and awk to format the data for being stored into a
> rrdtool database. This does not work, however. Even a simple "cat
> /dev/ttyUSB0 | sed 's/\x0/\n/g'" to replace the nullbytes used as record
> separators by the controller with newlines does not output anything. Using
> this simple sed script on the file filled with data from the serial port
> works just fine! I also tried using a named pipe, but reading from that
> pipe results in many characters being lost.
> Any idea why the serial port behaves in such a way and any solutions for
> my problem?

It usually has to do with the tty settings (stty can change those) of
the port such as line buffering and such.

I would however recommend looking at 'socat' for doing what you want.
It is rather neat.

Len Sorensen

Reply to: