I would like to be able to detect a BREAK condition on a serial port in Linux. How it's done?
I would like to know when BREAK starts and when it stops.
I was hoping that if I did:
int serial_status; ioctl(serial_fd, TIOCMGET, &serial_status);
then there will be a bit showing the BREAK condition, but it looks like there is no such thing.
I found tcsendbreak() in termios.h to post a break. I also found the tty_ioctl man page that describes how to post a break. But what about getting a break?
Note: BRKINT been suggested (which generates a SIGINT signal when a break occurs). But getting SIGINT not such a useful API, for several reasons:
- I canโt tell which serial port this comes from in a scenario with multiple serial ports.
- I can also get
SIGINT from the user pressing Ctrl-C when starting the program on the terminal. - If I run my program as a daemon, then the condition "if the terminal is the control terminal of the foreground process group" will not be true, will it?
- It is not possible to know how long the BREAK condition lasts, and when it stops.
source share