Skip to contentSkip to conversation

modifying line state manually on ttyS

DISCUSSION Michael Buesch 4 participants 9 messages Apr 7, 2003

lore
Share & tools
lore
#0 lore raw

Hi.

I have asked in many other mailing-lists, but I got no good solution for my problem, so I try to ask here, although it may not be the exaclty correct list for it.

I have developed my own device, that is connected to ttyS0. To talk to my device, I need to set the state of the TxD line manually to either 0 or 1 (+12v or -12v). What I try to say is, I don't want to write a whole byte to the port, but only one single bit, that then stays persistent on the line, until I reset its state. Better sayed, I want to handle TxD line, like it's possible for DTR-line for example.

Is kernel-support by the ttyS driver present for this, or do I have to write my own driver for my device. I'm trying to implement the driver in user-space, but I didn't find a solution to set linestate of TxD.

Regards
Michael Buesch.

Signature · 2 lines
My homepage: http://www.8ung.at/tuxsoft
fighting for peace is like fu**ing for virginity
#1 lore raw
Quoted 3 lines · Michael Buesch

I have developed my own device, that is connected to ttyS0. To talk to my device, I need to set the state of the TxD line manually to either 0 or 1 (+12v or -12v). What I try to say is,

TxD is a bad choice. A lot of the hardware cannot control TXD this way. DTR is the usual one because it is easy to handle but there are other control lines you can drive directly (see TIOCGMODEM)

#2 lore raw
Quoted 3 lines · Alan Cox

TxD is a bad choice. A lot of the hardware cannot control TXD this way. DTR is the usual one because it is easy to handle but there are other control lines you can drive directly (see TIOCGMODEM)

Oh great, you have just discovered the reason, why my driver is working on my Pentium1-PC but not on my Pentium4-PC. It's simply not supported by hardware. I've spent hours and hours about this. :)

My device is actually using DTR and RTS. What line could I use instead of TxD? Is it possible to use CTS for this, although it is normally a "input-signal", but not a "output-signal" like RTS?

Regards
Michael Buesch.

Signature · 2 lines
My homepage: http://www.8ung.at/tuxsoft
fighting for peace is like fu**ing for virginity
#3 lore raw
In reply to Michael Buesch
Quoted 6 lines · Michael Buesch

Hi.

I have asked in many other mailing-lists, but I got no good solution for my problem, so I try to ask here, although it may not be the exaclty correct list for it.

Quoted 7 lines

I have developed my own device, that is connected to ttyS0. To talk to my device, I need to set the state of the TxD line manually to either 0 or 1 (+12v or -12v). What I try to say is, I don't want to write a whole byte to the port, but only one single bit, that then stays persistent on the line, until I reset its state. Better sayed, I want to handle TxD line, like it's possible for DTR-line for example.

Do ioctl(fd, TIOCSBRK, 0) / ioctl(fd, TIOCCBRK, 0) help?

Signature · 1 line
Sergei.
#4 lore raw
Quoted 1 line · Sergei Organov

Do ioctl(fd, TIOCSBRK, 0) / ioctl(fd, TIOCSBRK, 0) help?

What does it do? I haven't found a description for TIOCSBRK, TIOCSBRK.

Regards
Michael Buesch.

Signature · 2 lines
My homepage: http://www.8ung.at/tuxsoft
fighting for peace is like fu**ing for virginity
#5 lore raw
Quoted 4 lines · Michael Buesch
Quoted 1 line · Sergei Organov

Do ioctl(fd, TIOCSBRK, 0) / ioctl(fd, TIOCSBRK, 0) help?

What does it do? I haven't found a description for TIOCSBRK, TIOCSBRK.

Changes the state of TxD line, I believe. Did you hear about "break condition"? It sets/clears the "break condition", at least for me ;)

Signature · 1 line
Sergei.
#6 lore raw
Quoted 5 lines · Sergei Organov
Quoted 1 line · Michael Buesch

What does it do? I haven't found a description for TIOCSBRK, TIOCSBRK.

Changes the state of TxD line, I believe. Did you hear about "break condition"? It sets/clears the "break condition", at least for me ;)

Oh my goodness, it works. Thank you *very* much!

Regards
Michael Buesch.

Signature · 2 lines
My homepage: http://www.8ung.at/tuxsoft
fighting for peace is like fu**ing for virginity
#7 lore raw
In reply to Michael Buesch
Quoted 14 lines · Michael Buesch

Hi.

I have asked in many other mailing-lists, but I got no good solution for my problem, so I try to ask here, although it may not be the exaclty correct list for it.

I have developed my own device, that is connected to ttyS0. To talk to my device, I need to set the state of the TxD line manually to either 0 or 1 (+12v or -12v). What I try to say is, I don't want to write a whole byte to the port, but only one single bit, that then stays persistent on the line, until I reset its state. Better sayed, I want to handle TxD line, like it's possible for DTR-line for example.

Quoted 7 lines

Is kernel-support by the ttyS driver present for this, or do I have to write my own driver for my device. I'm trying to implement the driver in user-space, but I didn't find a solution to set linestate of TxD.

Regards
Michael Buesch.

Well ttyS0 is connected to the rest of the machine using a UART. This means that you can't control TxD directly. I suggest that you use the parallel printer-port. This port allows you to set individual bits and they remain <forever> in the last state set. An ordinary (old-fashioned) printer-port allows you to set or reset 8 data bits plus three control bits. The newer ones allow you to read and write up to 16 bits.

Now, if you really need the +/- 12 volts that you think you will get out of a UART, please measure it first. Many new computers use I/O chips that only provide +/- 5 volts! Anyway, you can use the modem-control bits if you need that kind of voltage swing. You can set/reset modem control bits using the TIOCMGET/TIOCMSET ioctl() calls. You probably want to disable the SIGHUP signal before you muck with those bits. Some versions of Linux will send the hangup signal to the TTY owner even though it's not the controlling terminal for the process. This could cause your program to exit for "unknown" reasons; signal(SIGHUP, SIG_IGN) prevents such problems.

Cheers,
Dick Johnson
Penguin : Linux version 2.4.20 on an i686 machine (797.90 BogoMips). Why is the government concerned about the lunatic fringe? Think about it.

#8 lore raw
Quoted 2 lines · Richard B. Johnson

This means that you can't control TxD directly. I suggest that you use the parallel printer-port. This port allows you to set

That's my problem. parallel-port is used by a printer and I don't wanna by an expensive extension card for second parport. :)

Quoted 3 lines

Now, if you really need the +/- 12 volts that you think you will get out of a UART, please measure it first. Many new computers use I/O chips that only provide +/- 5 volts! Anyway, you can use the

That's no problem, because I "down-volt" it to 4.7V before using it.

Quoted 5 lines

calls. You probably want to disable the SIGHUP signal before you muck with those bits. Some versions of Linux will send the hangup signal to the TTY owner even though it's not the controlling terminal for the process. This could cause your program to exit for "unknown" reasons; signal(SIGHUP, SIG_IGN) prevents such problems.

Thanks for this important information.

Regards
Michael Buesch.

Signature · 2 lines
My homepage: http://www.8ung.at/tuxsoft
fighting for peace is like fu**ing for virginity