Re: RS232 Redirector Program in C using Linux



On 2008-01-21, Roger Leigh <rleigh@xxxxxxxxxxxxxxxxxxxx> wrote:

I can't answer your immediate questions, but I do have a
thought: you don't need to use signals. You might be happier
if you use select/poll/epoll instead. That might simplify the
design and make it easier to track down the error, if it
doesn't eliminate the error completely.

You definitely want to avoid signals if possible. You have to
be very careful about what you're allowed to do in a signal
handler.

Use poll or select. It's a lot simpler. Another option is to
use two threads or processes (IIRC, that's how some serial
programs like kermit used to work back in the days before
poll/select). But poll/select is a lot easier.

It doesn't simulate blocking on both ends as nicely as when
using blocking I/O in two threads though, IMHO.

This example uses two PTYs to simulate two serial endpoints in
software, but it would be trivial to adapt it to link to one
or two real serial ports. The iochannel and thread stuff can
be used directly. Just fix up main() to open the ports, and
pass those fds into the iochannel constructor.

http://people.debian.org/~rleigh/ptyjoin.cc

I've always had fairly good luck with somethign like this:

#!/bin/bash
stty -F /dev/ttyS0 <whatever>
stty -F /dev/ttyS1 <whatever>
cat </dev/ttyS1 >/dev/ttyS0
cat </dev/ttyS0 >/dev/ttyS1

But, I do a lot of ASCII, line-oriented stuff.

--
Grant Edwards grante Yow! Can you MAIL a BEAN
at CAKE?
visi.com
.