1

I'm working on an embedded system which send informations through the serial port uart ttyS0. Now i would like to receive data from the same serial port. So I implemented a signal handler using sigaction. I would like to use the SIGIO signal but the problem is that there is a interruption because of the data I send. So can i put a condition in the method for blocking the output signals?

struct sigaction act;
memset(&act,0, sizeof(act));
act.sa_handler = &sigio_Handler;
//act.sa_flags=0;
//act.sa_restorer=NULL;
fcntl(this->stream_ ,F_SETFL, FNDELAY|FASYNC); 
fcntl(this->stream_,F_SETOWN,getpid());
sigaction(SIGIO,&act,0);

void DataSender::sigio_Handler(int signo){
int fd;
std::cout << "helloworld1" << "\n";
fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY);
std::cout << "helloworld2" << "\n";
    if(signo == SIGIO ){
         unsigned char rx_buffer[3];
         int  rx_length = read(fd, (void*) rx_buffer,3);
         std::string mode;
         mode+=rx_buffer[0];
         mode+=rx_buffer[1];

         std::cout << "helloworld3" << std::endl;
         std::cout << rx_buffer << std::endl;
         std::cout << mode << std::endl;
         std::cout << (int)rx_buffer[2] << std::endl;

         projectionMode = mode;
         if (rx_length  == -1 ){
         std::cout << "could not read"<< std::endl;
         }
         if (rx_buffer[2] == 1){
            std::cout << "could not read1"<< std::endl;
         }else if(rx_buffer[2] == 2){

         }else if(rx_buffer[2] == 3){

         }else if(rx_buffer[2] == 4){

         }
    }
}
A. Kriss
  • 69
  • 5
  • If you work on an embedded system you should hopefully know about interrupts and interrupt service routines (ISR). An ISR should be short and quick and do as little as possible, preferably just set a flag that it had been invoked, or increase a counter. The same goes for signal handlers. Not only for `SIGIO` but for *all* signals. – Some programmer dude Aug 18 '16 at 11:57

0 Answers0