title: Hardware flow control with termios (CRTSCTS) for UART Device
body: <p>right now I'm communicating with a device over UART in C++ on a Udoo Neo. For this I'm using termios to set up the connection and write data to the device.
  For this purpose I want to use hardware flow control and have set the flag (CRTSCTS) with termios.</p>
  
  <p>For the hardaware flow control I've connected the device RTS line to the boards CTS and I've also checked via oscilloscope, that the device is giving me an active high, if it is not ready to read.</p>
  
  <p>The problem is that I still loose bytes in the following example of just spamming the device with numbers, but the boards output says that everything was written correctly.</p>
  
  <p>I thought the UART would be blocked when using HW flow control, so that no information is lost. Am I not understanding this correctly - or is there an error in the code?</p>
  
  <p>Thanks for the help</p>
  
  <pre><code>const char dev[] = "/dev/ttymxc4";
  
  int main(int argc, char **argv) {
  
  int fd;
  struct termios t; ///&lt; control structure for a general asynchronous interface
  // edited code
  tcgetattr(fd, &amp;t);
  
  t.c_iflag &amp;= ~(IGNBRK | BRKINT | ICRNL |
                   INLCR | PARMRK | INPCK | ISTRIP | IXON);
  t.c_oflag = 0;
  t.c_cflag &amp;= ~(CSIZE | PARENB);
  t.c_cflag |= (CS8 | CRTSCTS);
  
  // edited code 
  t.c_cflag |= (CLOCAL | CREAD);
  
  t.c_lflag &amp;= ~(ECHO | ECHONL | ICANON | IEXTEN | ISIG);
  
  t.c_cc[VMIN]  = 0;
  t.c_cc[VTIME] = 0;
  
  cfsetispeed(&amp;t,B57600); /* normal shall be: B115200 Baud */
  
  fd = ::open(dev, O_RDWR);
  if (fd==-1) {
      printf("UART: cannot open file: %s\n",dev);
      return -1;
  }
  
  tcsetattr(fd,TCSANOW, &amp;t);
  
  // edited code
  fcntl(fd, F_SETFL, 0);
  
  int count = 0;
  while (true) {
  
      count++;
      std::stringstream output;
      output &lt;&lt; count &lt;&lt; ",";
  
      ::write(fd, output.str().c_str(), output.str().length());
      printf("%d, writing: %s\n", fd, output.str().c_str());
      usleep(10000);
  }
  return 0;
  </code></pre>
  
  <p>}</p>