[Top][All Lists]

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

Controlling DTR/RTS lines on a RS-232 serial port

From: Javier (a.k.a AlBundy)
Subject: Controlling DTR/RTS lines on a RS-232 serial port
Date: Sat, 27 Oct 2007 15:25:15 +0000


I've posted this question in screen-devel@ some weeks ago,
with limited success. I think it can also fit here:

Question, short version:
How can I manage RTS and/or DTR outputs of a RS-232 port from GNU screen?

Question, long version:
I need to connect a PentiumI computer (running Linux) with
a 8051 microcontroller through RS-232 port. The microcontroller has an
embedded UART with 2 dedicated pins: TD and RD (and the aid of a MAX232,
of course).

If I use a 3-wire connection (GND, TxD, RxD) with computer's COM2 port,
GNU screen (invoked as "screen /dev/ttyS1" on Linux) sends/receives
data to/from the microcontroller board with no problems.

But I need an aditional signal from the computer, *one* *output* line
from COM2 (DTR or RTS), which will be connected as input to a
general-purpose-pin of the microcontroller (through unused pins of the MAX232).
This aditional signal must operate independently of the data stream
on RxD and TxD pins, like a hardware switch, and must can be activated or
deactivated by the user, at any time, from the same "screen /dev/ttyS1" session
that sends and receives data.

These answers are *not* acceptable solutions:
-use RTS or RTR lines from other COM port.
-connect 5V-lines from parallel port to microcontroller pins,
bypassing the MAX232.
-define in microcontroller's program one character (or characters' sequence)
with a special meaning (a pseudo-escape character), which simulates
activation of the general-purpose-pin.

I am thinking in 2 ways to do it:
-(a) to program an external executable in C, which follows tty_ioctl(4) manpage
("Modem control" section):
        int serial;
        serial |= TIOCM_DTR;
        ioctl(fd, TIOCMBIS, &serial);
So this executable should be called by Screen.

-(b) integrate the above C code into Screen.

My doubts:
1) I don't know if my solutions are correct.

2) How the external program (solution a) should be invoked from Screen?
With at/exec/shell commands?

3) Could this type of hack be integrated on Screen code? (solution b).
Any problems?

4) I don't know if there are another Linux programs that can talk to a serial
port, and force the status of RTS or DTR lines. I have been playing a bit
with "minicom" and "seyon", and I think they are not the solution.

5) I am not sure if Screen's VT100 emulation will "overwrite" status of RTS
and DTR lines in any point. I don't know if VT100 emulation has some
connection with RTS/DTR status. Some references?

6) I don't know if forcing the status of RTS/CTS with a external program
will damage some program executing on another Screen's window, will
damage VT100 emulation, or will crash execution of GNU Screen.

7) In Screen's source code, RTS status is forced on "OpenTTY()" function
                #if defined(linux) && defined(TIOCMSET)
                    int mcs = 0;
                    ioctl(f, TIOCMGET, &mcs);
                    mcs |= TIOCM_RTS;
                    ioctl(f, TIOCMSET, &mcs);
and I don't know why.

I've seen that minicom-2.1 also touch RTS status in "m_setrts()" function:
                #if defined(TIOCM_RTS) && defined(TIOCMODG)
                int fd
                int mcs=0;
                ioctl(fd, TIOCMODG, &mcs);
                mcs |= TIOCM_RTS;
                ioctl(fd, TIOCMODS, &mcs);

8) All other comments and experiences are welcome :-)


reply via email to

[Prev in Thread] Current Thread [Next in Thread]