title: setting serial port interruption in linux
body: <p>I am trying to set the interruption for a serial port in ubuntu (in program written in C), but it does not work. I have checked that the serial communication works correctly without the interruption, so I may be setting something wrong.
  The code is the following:</p>
  
  <pre><code>    #include &lt;stdio.h&gt;
      #include &lt;stdlib.h&gt;
      #include &lt;string.h&gt;
      #include &lt;unistd.h&gt;
      #include &lt;sys/types.h&gt;
      #include &lt;sys/socket.h&gt;
      #include &lt;netinet/in.h&gt;
      #include &lt;fcntl.h&gt;
      #include &lt;sys/signal.h&gt;
      #include &lt;errno.h&gt;
      #include &lt;termios.h&gt;
  
      void signal_handler_IO (int status);   /* definition of signal handler */
  
      int n;
      int fd;
      int connected;
      struct termios termAttr;
      struct sigaction saio;
  
      int main(int argc, char *argv[])
      {
           fd = open("/dev/ttyUSB0", O_RDWR | O_NOCTTY | O_NDELAY);
           if (fd == -1)
           {
              perror("open_port: Unable to open /dev/ttyO1\n");
              exit(1);
           }
  
           saio.sa_handler = signal_handler_IO;
           saio.sa_flags = 0;
           saio.sa_restorer = NULL; 
           sigaction(SIGIO,&amp;saio,NULL);
  
           fcntl(fd, F_SETFL, FNDELAY);
           fcntl(fd, F_SETOWN, getpid());
  
           tcgetattr(fd,&amp;termAttr);
           baudRate = B115200; 
           cfsetispeed(&amp;termAttr,B115200);
           cfsetospeed(&amp;termAttr,B115200);
           termAttr.c_cflag &amp;= ~PARENB;
           termAttr.c_cflag &amp;= ~CSTOPB;
           termAttr.c_cflag &amp;= ~CSIZE;
           termAttr.c_cflag |= CS8;
           termAttr.c_cflag |= (CLOCAL | CREAD);
           termAttr.c_lflag &amp;= ~(ICANON | ECHO | ECHOE | ISIG);
           termAttr.c_iflag &amp;= ~(IXON | IXOFF | IXANY);
           termAttr.c_oflag &amp;= ~OPOST;
           tcsetattr(fd,TCSANOW,&amp;termAttr);
           printf("UART1 configured....\n");
  
           connected = 1;
           while(connected == 1){
                 // some code
           }
  
           close(fd);
           exit(0);             
      }
  
      void signal_handler_IO (int status)
      {
           printf("received data from UART.\n");
      }
  </code></pre>
  
  <p>So anytime time another device send a message through the configured port, the message "received data from UART." is never displayed.</p>
  
  <p>Any suggestion to solve this problem? Also, how does the system relate the interruption with the serial port?, I have read about signal.h but I have not found an answer for that. I got the interruption idea from this page: <a href="http://www.faqs.org/docs/Linux-HOWTO/Serial-Programming-HOWTO.html" rel="noreferrer">http://www.faqs.org/docs/Linux-HOWTO/Serial-Programming-HOWTO.html</a> </p>
  
  <p>Thanks in advance for any help.
  Thanks in advance.</p>