title: Linux - serial port read returning EAGAIN
body: <p>I am having some trouble reading some data from a serial port I opened the following way. I've used this instance of code plenty of times and all worked fine, but now, for some reason that I cant figure out, I am completely unable to read anything from the serial port.</p>
  <p>I am able to write and all is correctly received on the other end, but the replies (which are correctly sent) are never received (No, the cables are all ok ;) )</p>
  <p>The code I used to open the serial port is the following:</p>
  <pre><code>fd = open(&quot;/dev/ttyUSB0&quot;, O_RDWR | O_NONBLOCK | O_NOCTTY);
  if (fd == -1)
  {
      Aviso(&quot;Unable to open port&quot;);
      return (fd);
  }
  else
  {
      //Get the current options for the port...
      bzero(&amp;options, sizeof(options)); /* clear struct for new port settings */
      tcgetattr(fd, &amp;options);
  
      /*-- Set baud rate -------------------------------------------------------*/
      if (cfsetispeed(&amp;options, SerialBaudInterp(BaudRate))==-1)
          perror(&quot;On cfsetispeed:&quot;);
      if (cfsetospeed(&amp;options, SerialBaudInterp(BaudRate))==-1)
          perror(&quot;On cfsetospeed:&quot;);
  
      //Enable the receiver and set local mode...
      options.c_cflag |= (CLOCAL | CREAD);
      options.c_cflag &amp;= ~PARENB; /* Parity disabled */
      options.c_cflag &amp;= ~CSTOPB;
      options.c_cflag &amp;= ~CSIZE;  /* Mask the character size bits */
      options.c_cflag |= SerialDataBitsInterp(8);           /* CS8 - Selects 8 data bits */
      options.c_cflag &amp;= ~CRTSCTS;                            // disable hardware flow control
      options.c_iflag &amp;= ~(IXON | IXOFF | IXANY);           // disable XON XOFF (for transmit and receive)
      options.c_cflag |= CRTSCTS;                         /* enable hardware flow control */
      
      options.c_cc[VMIN] = 0;     //min carachters to be read
      options.c_cc[VTIME] = 0;    //Time to wait for data (tenths of seconds)
  
      //Set the new options for the port...
      tcflush(fd, TCIFLUSH);
      if (tcsetattr(fd, TCSANOW, &amp;options)==-1)
      {
          perror(&quot;On tcsetattr:&quot;);
      }
  
      PortOpen[ComPort] = fd;
  }
  
  return PortOpen[ComPort];
  </code></pre>
  <p>After the port is initializeed I write some stuff to it through simple write command...</p>
  <pre><code>int nc = write(hCom, txchar, n);
  </code></pre>
  <p>where hCom is the file descriptor (and it's ok), and (as I said) this works. But... when I do a read afterwards, I get a &quot;Resource Temporarily Unavailable&quot; error from errno.</p>
  <p>I tested select to see when the file descriptor had something t read... but it always times out!</p>
  <p>I read data like this:</p>
  <pre><code>ret = read(hCom, rxchar, n);
  </code></pre>
  <p>and I always get an EAGAIN and I have no idea why.</p>
  <h3>Update:</h3>
  <p>The HW is working fine! I can see that there is inbound data on the serial port because I've made a debug cable to read whats going on on another terminal. So...</p>
  <p>I know what nonblocking should do. My question is... why isn't anything getting read!. The same setup works fine on windows, so all hardware is working fine...</p>
  <p>This is driving me nuts! I'm sure it's something simple as hell! I even tried getting rid of O_NONBLOCK to see when I would receive something... but nothing...</p>