![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Exiting from script when error occurs | Sreejith_VK | Shell Programming and Scripting | 4 | 04-25-2008 12:53 AM |
| How to catch the output | rpraharaj | Shell Programming and Scripting | 4 | 02-29-2008 06:47 AM |
| Problem with handling SIGINT | JamesGoh | High Level Programming | 3 | 02-24-2008 07:39 PM |
| TO find the word which occurs maximum number of times | aajan | Shell Programming and Scripting | 5 | 01-11-2008 01:11 AM |
| error occurs while some users login | rrlog | HP-UX | 0 | 08-12-2007 01:55 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Cannot catch SIGINT while serial break condition occurs
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. Thanks |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
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
|
|
#3
|
|||
|
|||
|
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. |
|
#4
|
||||
|
||||
|
Like I said: "BRKINT only works with the controlling tty."
|
|
#5
|
|||
|
|||
|
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.
|
|
#6
|
|||
|
|||
|
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? Last edited by gzz; 09-12-2007 at 04:49 AM. |
|
#7
|
|||
|
|||
|
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? #include <termios.h> #include <stdio.h> #include <unistd.h> #include <fcntl.h> #include <sys/signal.h> #include <sys/types.h> #include <sys/ioctl.h> #define BAUDRATE B38400 #define MODEMDEVICE "/dev/ttyS0" #define _POSIX_SOURCE 1 /* POSIX compliant source */ #include <unistd.h> #include <errno.h> #include <string.h> void signal_handler_SIGINT (int status); /* definition of signal handler */ main() { int fd,c, res; struct termios options; char buf[255]; int pid; fd = open(MODEMDEVICE, O_RDWR | O_NOCTTY | O_NONBLOCK); if (fd <0) {perror(MODEMDEVICE); exit(-1); } signal(SIGINT,signal_handler_SIGINT); fcntl(fd, F_SETOWN, getpid()); /* Make the file descriptor asynchronous (the manual page says only O_APPEND and O_NONBLOCK, will work with F_SETFL...) */ fcntl(fd, F_SETFL, FASYNC); memset (&options, 0x00, sizeof (options)); options.c_cflag |= (CREAD); options.c_cflag |= CLOCAL; options.c_cflag |= CS8; // Select 8 l2_data bits options.c_iflag |= (BRKINT); // options.c_cc[VMIN] = 1; options.c_cc[VTIME] = 1; if(ioctl(fd,TIOCSCTTY, 1) == -1) printf("eh %s\n",strerror(errno)); } /*************************************************************************** * signal handler. sets wait_flag to FALSE, to indicate above loop that * * characters have been received. * ***************************************************************************/ void signal_handler_SIGINT (int status) { printf("received SIGINT signal.\n"); exit(0); } |
|||
| Google The UNIX and Linux Forums |