I setup termios structure with IGNBRK is not set and BRKINT is set.
To allow the process to receive signals I call: fcntl(fd, F_SETOWN, getpid());
I have made a signal handler to catch all signals. I can catch SIGINT when pressing ctrl+c but when I send break signal over serial then it cannot catch SIGINT.
Is there anything I'm doing wrong?
Any suggestions and code samples would be appreciated.
fcntl has nothing to do with the break key. BRKINT only works with the controlling tty. The INT character, which you have mapped to CNTL-C, also only works with the controlling TTY. So the same keyboard that is sending the cntl-c character should be able to send the break signal. If that keyboard is a PC instead of a true ascii terminal, the program in the pc make need a special operation to send a break signal out the serial port. As one example see: SUMMARY: Send Break Signal Through HyperTerminal
I use another computer to send data and break signal over serial. When my program receives data then i get SIGIO signal and i can use read to get the received data. But when I send break signal from the other computer then i receive no signal.
In manpage i can read that :" BRKINT If IGNBRK is set, a BREAK is ignored. If it is not set but RKINT is set, then a BREAK causes the input and output queues to be flushed, and if the terminal is the controlling terminal of a foreground process group, it will cause a SIGINT to be sent to this foreground process group.", but I'm not sure how to become controlling terminal of a foreground process.
I have no problem seting break condition on the serial line, but the problem is how to detect the break condition, without polling serial break counters or other things that stores information about break conditions.
Any specific functions to call to become a controlling terminal of ttyS0 for example? I have no idea how to achive that condition. Can ioctl(fd, TIOCSCTTY, (char *)NULL) or ioctl(fd, TIOCSCTTY, (char *)1) be used to become a controlling tty of ttyS0. If you have any specific suggestions then go a head.
ioctl TIOCSCTTY always returns -1 (Operation not permitted) even if I am super user.
Is it even possible to receive SIGINT from serial driver without being super user?
maybe this thread should be moevd to programming forum, but if I started this here I wont start another thread for the same pbroblem.
-------------------------------------------------------------------------------------------------------
What am I missing?
What needs to be added to receive SIGINT from serial driver?
Thanks for the tip. With this code I can receive SIGINT while break synchronization condition occurs.
Is there any suggestions that I should or should not do?
Thanks for the link but I have rad that site about 10 times and I cant find anywhere how to detect serial break condition. Can you be more specific and tell how to implement this kind of functionality without using fork() or double fork(). I admit that my posted code is not good but I wanted to show how I archived required functionality. Any better solution would be appreciated.