title: Error : Resource temporarily unavailable Unable to receive serial data
body: <p>My C code is sending data to Uart perfectly but while receiving it gives error.
  Here is my code</p>
  
  <pre><code>#include &lt;stdio.h&gt;      // standard input / output functions
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;     // string function definitions
  #include &lt;unistd.h&gt;     // UNIX standard function definitions
  #include &lt;fcntl.h&gt;      // File control definitions
  #include &lt;errno.h&gt;      // Error number definitions
  #include &lt;termios.h&gt;   
  void main()
  {
  int USB = open( "/dev/ttyUSB0", O_RDWR| O_NONBLOCK | O_NDELAY  );       
  struct termios tty;
  struct termios tty_old;
  memset (&amp;tty, 0, sizeof tty);
  /* Error Handling */
  
  if ( USB &lt; 0 )
  {
  printf( "Error %d form tcgetattr : %s /n", errno, strerror( errno ) );
  }
  
  /* Save old tty parameters */
  tty_old = tty;
  
  /* Set Baud Rate */
  cfsetospeed (&amp;tty, (speed_t)B9600);
  cfsetispeed (&amp;tty, (speed_t)B9600);
  
  /* Setting other Port Stuff */
  tty.c_cflag     &amp;=  ~PARENB;            // Make 8n1
  tty.c_cflag     &amp;=  ~CSTOPB;
  tty.c_cflag     &amp;=  ~CSIZE;
  tty.c_cflag     |=  CS8;
  tty.c_cflag     &amp;=  ~CRTSCTS;           // no flow control
  tty.c_cc[VMIN]   =  1;                  // read doesn't block
  tty.c_cc[VTIME]  =  5;                  // 0.5 seconds read timeout
  tty.c_cflag     |=  CREAD | CLOCAL;     // turn on READ &amp; ignore ctrl lines
  
  /* Make raw */
  cfmakeraw(&amp;tty);
  
  /* Flush Port, then applies attributes */
  tcflush( USB, TCIFLUSH );
  if ( tcsetattr ( USB, TCSANOW, &amp;tty ) != 0) 
  {
  printf("Error %d from tcsetattr /n",errno);
  //   std::cout &lt;&lt; "Error " &lt;&lt; errno &lt;&lt; " from tcsetattr" &lt;&lt; std::endl;
  }
  
  /*  WRITE  */  
  unsigned char cmd[] = "YES this program is writing \r";
  int n_written = 0,spot = 0;
  do {
  n_written = write( USB, &amp;cmd[spot], 1 );
  spot += n_written;
  } while (cmd[spot-1] != '\r' &amp;&amp; n_written &gt; 0);
  
  /* READ   */
  int n = 0,spot_r =0;
  char buf = '\0';
  
  /* Whole response*/
  char response[1024];
  memset(response, '\0', sizeof response);
  
  do {
  n = read( USB, &amp;buf, 1 );
  sprintf( &amp;response[spot_r], "%c", buf );
  spot_r += n;
  } while( buf != '\r' &amp;&amp; n &gt; 0);
  
  if (n &lt; 0) {
  printf("Error reading %s",strerror(errno));
  }
    else if (n==0) {
    printf("read nothing");
    }
    else {
    printf("Response %s",response);
    }
  }
  </code></pre>
  
  <p>Error Message</p>
  
  <pre><code>Error reading Resource temporarily unavailable
  </code></pre>
  
  <p>It is sending data to UART perfectly.
  But at reception side it gives error of resource temporary unavailable.
  Should i put delay in-between? 
  Or any other function that could help me out. </p>
  
  <p>Thank you.</p>
  
  <p>Abhi</p>