Cannot catch SIGINT while serial break condition occurs


 
Thread Tools Search this Thread
Top Forums Programming Cannot catch SIGINT while serial break condition occurs
# 8  
Old 09-17-2007
Where have you got the double fork and setting of the controlling terminal?
# 9  
Old 09-17-2007
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?

#include <sys/ioctl.h>
#include <termios.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/signal.h>
#include <errno.h>
#include <sys/types.h>
#include <unistd.h>
void signal_handler(int status);

int main(void)
{
int fd;

switch (fork()) {
case 0:
break;
case -1:
// Error
printf("Error demonizing (fork)! %d - %s\n", errno, strerror(errno));
exit(0);
break;
default:
_exit(0);
}

if (setsid() == -1)
{
printf("Error demonizing (setsid)! %d - %s\n", errno, strerror(errno));
exit(0);
}
fd = open ("/dev/ttyS0", O_RDWR, 0 );

struct sigaction saio; /* definition of signal action */
saio.sa_handler = signal_handler;
// saio.sa_mask = 0;
saio.sa_flags = 0;
saio.sa_restorer = NULL;
sigaction(SIGINT,&saio,NULL);
struct termios options;
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 (tcsetattr (fd, TCSAFLUSH, &options) == -1)
{
printf("port setup failure\n");
return -1;
}
ioctl(fd, TIOCSCTTY, (char *)NULL);
getchar();
}

void signal_handler(int status)
{
printf("received SIGINT %d signal.\n", status);
exit(0);
}

Last edited by gzz; 09-17-2007 at 09:54 AM..
# 10  
Old 10-16-2007
Is it possible to detect when the serial port is not pending on a serial break any more?
# 11  
Old 10-16-2007
Hmm. This is a VERY good guide to programming serial ports. Instead of thrashing about, use some of the examples:

Code:
http://www.easysw.com/~mike/serial/serial.html

# 12  
Old 11-13-2007
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.
# 13  
Old 11-13-2007
What platform/operating system does this have to run on?
# 14  
Old 11-23-2007
Quote:
Originally Posted by porter
What platform/operating system does this have to run on?
on linux platform
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to execute condition until an event occurs

I need a script to keep polling "receive_dir" directory till "stopfile" get written in the directory. This has to run despite empty directory. So far i have this but fails if receive_dir is empty with no files with "unary operator expected". Help !! #!/usr/bin/ksh until do for i... (1 Reply)
Discussion started by: iaav
1 Replies

2. Shell Programming and Scripting

Always pass SIGINT in ksh

The following command will run and wait for input from the user. /usr/sap/SAP/webdisp/wdispmon pf=/usr/sap/SAP/webdisp/profile What I would like to do is (in one command): - Add the above line to a ksh script - Receive the output - and send a SIGINT I have seen many posts on how to... (3 Replies)
Discussion started by: sapsid
3 Replies

3. UNIX for Dummies Questions & Answers

SIGINT issue

May i know what are the possible causes for SIGINT other than ctrl-c? Thanks (17 Replies)
Discussion started by: pandeesh
17 Replies

4. Shell Programming and Scripting

Sh script sends SIGINT to a process

Hello, What I want to accomplish is this: I have made a very simple script that runs 2 commands, polipo proxy and tor. The script runs successfully and the output of tor is visible to the screen. I am using the trap command in order to catch the ctrl+c button combo in order to stop polipo... (5 Replies)
Discussion started by: redsolja
5 Replies

5. Ubuntu

Ubuntu 9.04 Serial application to telnet to serial device

Hello! I am working on an application which reads environmental instruments which have serial ports. The application requires a serial port to be present to talk to the device (i.e. /dev/ttyS0 ). In some instances the environmental devices will be 100's of yards away from the computer, so a... (5 Replies)
Discussion started by: mvona
5 Replies

6. Shell Programming and Scripting

How to break a loop if condition is met

I am having trouble figuring this code I want to grep a text from a file and if it match certain text it break out of the loop or it should continue searching for the text Here is what I have written but it isn't working while true f=`grep 'END OF STATUS REPORT' filename` do if ... (9 Replies)
Discussion started by: Issemael
9 Replies

7. Shell Programming and Scripting

Intercepting SIGINT in a bash script

I've written a bash script which captures video with DVgrab. Because of the nature of the tapes that I am digitizing, sometimes I want to quit capturing before the time that I set for DVgrab. When this is the case I press Ctrl-c and DVgrab exits cleanly, my problem is that there is additional... (5 Replies)
Discussion started by: Starcast
5 Replies

8. Programming

[C] fgets problem with SIGINT singlal!!!

Hi all, I have this method to read a string from a STDIN: void readLine(char* inputBuffer){ fgets (inputBuffer, MAX_LINE, stdin); fflush(stdin); /* remove '\n' char from string */ if(strlen(inputBuffer) != 0) inputBuffer = '\0'; } All work fine but if i... (1 Reply)
Discussion started by: hurricane86
1 Replies

9. Solaris

Forcing OpenBoot: H/W Solution to no <BREAK> function on USB Serial

Please note: This solution does require some soldering ability. If, like me today, you really really need to get into OpenBoot on a non booting Solaris machine (in my case an Ultra 5) but your USB dongle won't send <BREAK> then here is a -really- simple hardware hack that works a treat: ... (0 Replies)
Discussion started by: HideawayStudio
0 Replies

10. Programming

Problem with handling SIGINT

For a program I am designing, which involves handling the keyboard input Ctrl^c (SIGINT), it is taking ages for the program to actually recognise and perform the corresponding action whenever I run it and hit Ctrl^C at the CL. I have to do at least 3 Ctrl^Cs before the program will actually... (3 Replies)
Discussion started by: JamesGoh
3 Replies
Login or Register to Ask a Question