5

Is it possible to open a serial device (such as /dev/ttyS0) and be informed via select/poll/etc... or a signal when the handshaking lines (such as CTS/RTS or DSR/DTR) change? I know at the hardware level there's an interrupt from the UART to tell the kernel it has changed, but can I be informed of that up in userland?


Edit: I am aware of TIOCMIWAIT, but that ioctl call blocks until the status lines change. I would like instead to keep processing generally and have a poll or similar be informed on change, as well as other events.

LeoNerd
  • 8,344
  • 1
  • 29
  • 36
  • possible duplicate of [How to efficiently wait for CTS or DSR of RS232 in Linux?](http://stackoverflow.com/questions/8952098/how-to-efficiently-wait-for-cts-or-dsr-of-rs232-in-linux) – Digital Trauma Dec 23 '13 at 18:08
  • Not directly - that post only talks about `TIOCMIWAIT`, which blocks until the status bits change. I'd like to be informed asynchronously, either by select/poll wakeup, or a signal. – LeoNerd Dec 23 '13 at 18:11
  • OK, good point. Now how do I unflag? I guess I can upvote to compensate ;-) – Digital Trauma Dec 23 '13 at 18:13
  • Can you do what you want by having the `ioctl TIOCMIWAIT` in a separate thread? – James Waldby - jwpat7 Dec 23 '13 at 18:52

1 Answers1

2

There's no way to wait for the DTR/RTS lines to change in userland. The only way to do this on Linux is to constantly poll the device, checking to see if the status of the RTS/DTR lines have changed. I generally steal my serial port code from gtkerm, and it polls.

You can try using TIOCMIWAIT, but if I remember correctly that's going to be very tied to the driver for the serial port that Linux is using, and so may not work from driver to driver.

rm5248
  • 2,590
  • 3
  • 17
  • 16