Welcome to the Linux Foundation Forum!
Signal handling for 3 serial interrupt.
sbm143
Posts: 9
Hi all,
I have 3 different devices Dev1, Dev2 & Dev3 connected to UART 1, UART 2 & UART 3 respectively. I am using these 3 devices alternatively.
I want to write signal handler for these 3 devices interrupts. I am able to handle one signal handler at a time.
But problem is that when I have tried to write signal handler for other (means two signal handler at a time for SIGIO signal), my programs does not work.
Can anybody tell me how to solve this problem?
Please help me.
Thanks
0
Comments
-
You can only have one handler for each signal at any particular time. You could use sigqueue() and pass some information in the sigval structure that indicates which port generated the interrupt. Then, your handler can determine what to do with the port in question.0
-
Thanks for your suggestion.
I have also one more problem in signal handling. I have connected a GPRS modem to UART1 (serial port).
In the code i am just sending "AT" command continuously and trying to check its reply. But problem is that sometimes I get reply "OK" and sometimes not.
Also after some time my code is does not get interrupted even though there is reply from modem.. I have checked this using Hyper Terminal.
Please help me out what is the prolem?0 -
Without seeing your code, I can't say what is your problem, and then I might not be able to determine what's going on. Please explain exactly what you are trying to do. There may be some conflict with system software that is detecting the GPRS modem and trying to connect with it, resulting in some sort of race condition.0
-
Hi.
In the source code I am just sending "AT" command and trying to check its "OK" response.
My code is....#include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <termios.h> #include <stdio.h> #include<sys/signal.h> #include<sys/ioctl.h> #define BAUDRATE B9600 #define Modem "/dev/ttyAM1" #define _POSIX_SOURCE 1 /* POSIX compliant source */ #define FALSE 0 #define TRUE 1 /******************************************** Functions Prototype *****************************************************/ void Modem_Interface(void); void sig_handler(int status); void serial_cnfg(void); void modemdelay(void); void modemdelay1(void); /*************************************************************************************************************************/ /************************************************* Structures **********************************************************/ struct termios oldtio,newtio; struct termios oldtio1,newtio1; /*************************************************************************************************************************/ /********************************************** Global Variables *******************************************************/ int FD_Printer, FD_Modem, FD_CM; unsigned char sig_flag; int data; int fd,cashfd,c, res,cntr=0,virus=0; unsigned int CM_rply_Cntr=0; char CM_rply_Buf[250]; char rx_data,rx_cntr=0; /*************************************************************************************************************************/ void sig_handler(int status) { read(FD_Modem,&rx_data,1); //read(FD_Modem,CM_rply_Buf,100); //CM_rply_Buf[rx_cntr++]=rx_data; printf("rx_data=%c\n",rx_data); } void modemdelay(void) { unsigned int i=0,j; for(i=0;i<5632;i++) for(j=0;j<4234;j++); } void modemdelay1(void) { unsigned int i=0,j; for(i=0;i<632;i++) for(j=0;j<234;j++); } void serial_cnfg(void) { struct sigaction sa; sa.sa_handler = sig_handler; sa.sa_flags = 0; sa.sa_restorer = NULL; sigemptyset(&sa.sa_mask); sigaction(SIGIO,&sa,NULL); fcntl(FD_Modem,F_SETOWN,getpid()); fcntl(FD_Modem,F_SETFL,FASYNC); } void Modem_Interface(void) { char cmd[]="AT",data,enter=0x0D; unsigned int i=0; printf("Transmitting \n"); while(cmd[i]!='\0') { data=cmd[i++]; write(FD_Modem,&data,1); } write(FD_Modem,0x0D,1); } int main(void) { unsigned int i; while(1) { FD_Printer = open(Printer, O_WRONLY | O_NOCTTY ); if (FD_Printer <0) {perror(Printer); exit(-1); } FD_Modem = open(Modem, O_RDWR | O_NOCTTY ); //for modem if (FD_Modem <0) {perror(Modem); exit(-1); } serial_cnfg(); tcgetattr(FD_Modem,&oldtio); bzero(&newtio, sizeof(newtio)); newtio.c_cflag = BAUDRATE | CRTSCTS | CS8 | CLOCAL | CREAD; newtio.c_iflag = IGNPAR; newtio.c_oflag = 0; newtio.c_lflag = 0; /* set input mode (non-canonical, no echo,...) */ newtio.c_cc[VTIME] = 2; /* inter-character timer unused */ tcflush(FD_Modem, TCIFLUSH); tcsetattr(FD_Modem,TCSANOW,&newtio); modemdelay(); for(i=0;i<248;i++) CM_rply_Buf[i]='\0'; rx_cntr=0; rx_data='\0'; //printf("\nIn Modem_Interface"); Modem_Interface(); modemdelay(); modemdelay(); } tcsetattr(FD_Modem,TCSANOW,&oldtio); return 0; }
I am using wavecom GPRS ( Q24PL002) modem, with 9600 baud rate. I am setting everything in while loop beacuse whenever i used while(1) for only command transmission after some time signal handler did not worked.0 -
1.Are you able to receive data properly? i mean only receiving data packet from your GPRS device?
i have done a program for my project exactly the same way which you want ?
its working for fine N0 HARDWARE control
see the file attached [file name=serail.txt size=2624]http://www.linux.com/media/kunena/attachments/legacy/files/serail.txt[/file]0 -
1.Are you able to receive data properly? i mean only receiving data packet from your GPRS device?
Not always. But sometimes i get "AT" reply from modem.I have tested this code on Hyper Terminal (instead of GPRS modem) it works fine. Sometime it also fails.0 -
how frequent you are sending AT command ?0
-
Not exactly but nearly about after every 6-9 seconds i am sending "AT" command0
-
Hi
have you done a loop test in serial port (short 2 and 3 pin )
write data in serial port and check are you getting the data in your signal handler .
if it works fine then your program is ok
then go for device .0 -
Yes i have tested my code without modem also. It works fine.0
Categories
- All Categories
- 167 LFX Mentorship
- 219 LFX Mentorship: Linux Kernel
- 795 Linux Foundation IT Professional Programs
- 355 Cloud Engineer IT Professional Program
- 179 Advanced Cloud Engineer IT Professional Program
- 82 DevOps Engineer IT Professional Program
- 127 Cloud Native Developer IT Professional Program
- 112 Express Training Courses
- 112 Express Courses - Discussion Forum
- 6.2K Training Courses
- 48 LFC110 Class Forum - Discontinued
- 17 LFC131 Class Forum
- 35 LFD102 Class Forum
- 227 LFD103 Class Forum
- 14 LFD110 Class Forum
- 39 LFD121 Class Forum
- 15 LFD133 Class Forum
- 7 LFD134 Class Forum
- 17 LFD137 Class Forum
- 63 LFD201 Class Forum
- 3 LFD210 Class Forum
- 5 LFD210-CN Class Forum
- 2 LFD213 Class Forum - Discontinued
- 128 LFD232 Class Forum - Discontinued
- 1 LFD233 Class Forum
- 2 LFD237 Class Forum
- 23 LFD254 Class Forum
- 697 LFD259 Class Forum
- 109 LFD272 Class Forum
- 3 LFD272-JP クラス フォーラム
- 10 LFD273 Class Forum
- 152 LFS101 Class Forum
- 1 LFS111 Class Forum
- 1 LFS112 Class Forum
- 1 LFS116 Class Forum
- 1 LFS118 Class Forum
- LFS120 Class Forum
- 7 LFS142 Class Forum
- 7 LFS144 Class Forum
- 3 LFS145 Class Forum
- 1 LFS146 Class Forum
- 3 LFS147 Class Forum
- 1 LFS148 Class Forum
- 15 LFS151 Class Forum
- 1 LFS157 Class Forum
- 33 LFS158 Class Forum
- 8 LFS162 Class Forum
- 1 LFS166 Class Forum
- 1 LFS167 Class Forum
- 3 LFS170 Class Forum
- 2 LFS171 Class Forum
- 1 LFS178 Class Forum
- 1 LFS180 Class Forum
- 1 LFS182 Class Forum
- 1 LFS183 Class Forum
- 29 LFS200 Class Forum
- 736 LFS201 Class Forum - Discontinued
- 2 LFS201-JP クラス フォーラム
- 14 LFS203 Class Forum
- 102 LFS207 Class Forum
- 1 LFS207-DE-Klassenforum
- 1 LFS207-JP クラス フォーラム
- 301 LFS211 Class Forum
- 55 LFS216 Class Forum
- 48 LFS241 Class Forum
- 42 LFS242 Class Forum
- 37 LFS243 Class Forum
- 15 LFS244 Class Forum
- LFS245 Class Forum
- LFS246 Class Forum
- 50 LFS250 Class Forum
- 1 LFS250-JP クラス フォーラム
- LFS251 Class Forum
- 154 LFS253 Class Forum
- LFS254 Class Forum
- LFS255 Class Forum
- 5 LFS256 Class Forum
- 1 LFS257 Class Forum
- 1.3K LFS258 Class Forum
- 10 LFS258-JP クラス フォーラム
- 111 LFS260 Class Forum
- 159 LFS261 Class Forum
- 41 LFS262 Class Forum
- 82 LFS263 Class Forum - Discontinued
- 15 LFS264 Class Forum - Discontinued
- 11 LFS266 Class Forum - Discontinued
- 20 LFS267 Class Forum
- 24 LFS268 Class Forum
- 29 LFS269 Class Forum
- 1 LFS270 Class Forum
- 199 LFS272 Class Forum
- 1 LFS272-JP クラス フォーラム
- LFS274 Class Forum
- 3 LFS281 Class Forum
- 9 LFW111 Class Forum
- 260 LFW211 Class Forum
- 182 LFW212 Class Forum
- 13 SKF100 Class Forum
- 1 SKF200 Class Forum
- 1 SKF201 Class Forum
- 782 Hardware
- 198 Drivers
- 68 I/O Devices
- 37 Monitors
- 96 Multimedia
- 174 Networking
- 91 Printers & Scanners
- 83 Storage
- 743 Linux Distributions
- 80 Debian
- 67 Fedora
- 15 Linux Mint
- 13 Mageia
- 23 openSUSE
- 143 Red Hat Enterprise
- 31 Slackware
- 13 SUSE Enterprise
- 348 Ubuntu
- 461 Linux System Administration
- 39 Cloud Computing
- 70 Command Line/Scripting
- Github systems admin projects
- 90 Linux Security
- 77 Network Management
- 101 System Management
- 46 Web Management
- 64 Mobile Computing
- 17 Android
- 34 Development
- 1.2K New to Linux
- 1K Getting Started with Linux
- 371 Off Topic
- 114 Introductions
- 174 Small Talk
- 19 Study Material
- 507 Programming and Development
- 285 Kernel Development
- 204 Software Development
- 1.8K Software
- 211 Applications
- 180 Command Line
- 3 Compiling/Installing
- 405 Games
- 309 Installation
- 97 All In Program
- 97 All In Forum
Upcoming Training
-
August 20, 2018
Kubernetes Administration (LFS458)
-
August 20, 2018
Linux System Administration (LFS301)
-
August 27, 2018
Open Source Virtualization (LFS462)
-
August 27, 2018
Linux Kernel Debugging and Security (LFD440)