title: Linux Uart Read blocking
body: <p>I am writing a linux application in the userspace to communicate to an FPGA via uart. I am using non-canonical blocking read operation with vmin and vtime specified. FPGA responds to a command sent by me on uart with fixed no of bytes. I can successfully read them for a long time, but after executing for a while, the code simply gets stuck up in the read function. For a blocking read, I would assume it to exit the routine after the vtime period specified even if it does not see any data on the uart buffer.But, it simply hangs the whole application. 
  Does anyone have an idea what must be causing this?</p>
  
  <p>following are the properties i set for my uart port:</p>
  
  <p>struct termios oldtio;
      int fd;</p>
  
  <pre><code>fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY);
  
  
  /* get old settings */
  if (tcgetattr(fd, &amp;oldtio) == -1) {
      perror("tcgetattr");
  }
  
  /* no parity, CR=&gt;NL */
  oldtio.c_iflag |= IGNPAR | ICRNL;
  /* XON/XOFF flow control off */
  oldtio.c_iflag &amp;= ~IXON;  
      oldtio.c_oflag = 0;
  /* zero the character size bits */
  oldtio.c_cflag &amp;= ~CSIZE;
  /* 8 data bits */
  oldtio.c_cflag |= CS8 | CLOCAL | CREAD;
  /* no hw flow control, no parity and 1 stop bit */
  oldtio.c_cflag &amp;= ~CRTSCTS &amp; ~PARENB &amp; ~CSTOPB;
  
  if (cfsetispeed(&amp;oldtio, B115200) == -1) {
      perror("cfsetispeed");
      exit(1);
  }
  
  if (cfsetospeed(&amp;oldtio, B115200) == -1) {
      perror("cfsetospeed");
      exit(1);
  }
  
  /* raw mode */
  //oldtio.c_lflag &amp;= ~(ICANON | ISIG);  
  oldtio.c_lflag &amp;= ~(ECHO | ICANON | ISIG);
  
  oldtio.c_cc[VTIME] = vtime_value;
  oldtio.c_cc[VMIN] = vmin_value;
  
  if (tcflush(fd, TCIFLUSH) == -1) {
      perror("tcflush");
      exit(1);
  }
  
  if (tcsetattr(fd,TCSANOW,&amp;oldtio) == -1) {
      perror("tcsetattr");
      exit(1);
  }
  
  
  baud_rate = 115200;
  vmin = 0;
  vtime=255;
  </code></pre>