Re: RS232 Redirector Program in C using Linux
- From: Steffen <steffen.kuehn@xxxxxxxxx>
- Date: Mon, 21 Jan 2008 23:57:31 -0800 (PST)
On 22 Jan., 13:15, Steffen <steffen.ku...@xxxxxxxxx> wrote:
On 22 Jan., 05:24, Grant Edwards <gra...@xxxxxxxx> wrote:
On 2008-01-21, Roger Leigh <rle...@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
Thanks to all for the fast response and guidance!!
I changed my program to use the "selec0"t command instead of the
signal. (based on your tips and thehttp://tldp.org/HOWTO/Serial-Programming-HOWTO/x115.html).
But sadly my problem is still existing... nothing has changed...
The thing is, like I already described... I try to transfer a file
using GtkTerm and my program. And the file gets corrupted.
How do I do this:
I have one PC, running Linux and running my program. This PC has three
serial ports available. And I have a notebook (also Linux) with one
serial port. I am using crossed-cables to connect the ports in the
following way: (GtkTerm 1) Notebook:ttyS0 <crosscable> PC:ttyS1
<program-redirecting> PC:ttyS2 <crosscable> PC:ttyS0 (GtkTerm 2)
So, If I am putting in Text.. using the keyboard in GtkTerm 1 i
receive this text on GtkTerm 2, as it is - this is working fine in
both directions... so all seems to work.
But: When I try to transfer a file (e. g. a JPEG or ODT file), using
the "File->Send raw file" function in GtkTerm... I receive all bytes
in GtkTerm 2 - but after saving the received data using "File->Save
raw file" in GtkTerm 2 the file is corrupt... means I can not open it
anymore...
So what is corrupted?? To check this I did a binary compare on the
original and the receive file (using vbindiff)... and the result is
confusing for me... there are changed bytes - yes - but always in the
first part (hex address 0000 0000 - 0000 0080), which seems to be the
header of the file...?? ...this is reproducable... I tried different
files...
I can not understand that...
Any Idear abpout that?? I am hanging and my boss is going to kill me :-
(
The Current Version of my program (only one c file) can be downloaded
here:http://steffen.kuehn.googlepages.com/RS232Redirector.c
Thank You very much for suggestions!!
Confusing is that if i am sending a normal text file.. e. g. my
sourcecode-file.... this works fine... no problems.
.
- Follow-Ups:
- Re: RS232 Redirector Program in C using Linux
- From: Bill Marcum
- Re: RS232 Redirector Program in C using Linux
- From: Steffen
- Re: RS232 Redirector Program in C using Linux
- References:
- RS232 Redirector Program in C using Linux
- From: Steffen
- Re: RS232 Redirector Program in C using Linux
- From: William Pursell
- Re: RS232 Redirector Program in C using Linux
- From: Grant Edwards
- Re: RS232 Redirector Program in C using Linux
- From: Roger Leigh
- Re: RS232 Redirector Program in C using Linux
- From: Grant Edwards
- Re: RS232 Redirector Program in C using Linux
- From: Steffen
- RS232 Redirector Program in C using Linux
- Prev by Date: Re: RS232 Redirector Program in C using Linux
- Next by Date: Re: RS232 Redirector Program in C using Linux
- Previous by thread: Re: RS232 Redirector Program in C using Linux
- Next by thread: Re: RS232 Redirector Program in C using Linux
- Index(es):
Relevant Pages
|