title: Writing to serial port on mac OSX 10.9.3 using unistd.h and C
body: <p>im trying to write some bytes to the serial port on mac OSX 10.9.3 with the unistd.h from standard C. I know there is a similar topic, but its 4 years old and there is a different problem, so please excuse me for starting a new thread.</p>
  
  <p>My problem is the write(); function, it always returns with a value of -1. The code for opening my port is as follows:</p>
  
    <pre class="lang-c prettyprint-override"><code>curByte = 0;
  numBytes = 0;
  bool blocking = false;
  //Settings structure old and new
  struct termios newtio;
  
  fd = open(port, O_RDWR | O_NOCTTY | (blocking ? 0 : O_NDELAY));
  if (fd &lt; 0)
  {
      return PORT_ERROR;
  }
  bzero(&amp;newtio, sizeof(newtio));
  
  if (cfsetispeed(&amp;newtio, BDR_ESP3) != 0)
      return PORT_ERROR;
  if (cfsetospeed(&amp;newtio, BDR_ESP3) != 0)
      return PORT_ERROR;
  
  newtio.c_cflag &amp;= ~PARENB;
  newtio.c_cflag &amp;= ~CSTOPB;
  newtio.c_cflag &amp;= ~CSIZE;
  newtio.c_cflag |= CS8;
  newtio.c_cflag &amp;= ~CRTSCTS;
  
  //Hardware control of port
  newtio.c_cc[VTIME] = blocking ? 1 : 0; // Read-timout 100ms when blocking
  newtio.c_cc[VMIN] = 0;
  
  tcflush(fd, TCIFLUSH);
  //Acquire new port settings
  if (tcsetattr(fd, TCSANOW, &amp;newtio) != 0)
      puts(strerror(errno));
  return OK;
  </code></pre>
  
  <p>I can open the port without problems, but once i try to write a byte to the port with the following method:</p>
  
   <pre class="lang-c prettyprint-override"><code>{
  int res;
  
  if (fd == -1)
      return PORT_ERROR;
      res = write(fd, &amp;u8TxByte, 1);
  if (res == -1){
      printf("Error writing to port - %s(%d).\n", strerror(errno), errno);
  }
  if (res == 1)
      printf("Writing to port succeeded!");
      return OK;
  
  return ERROR;
   }
  </code></pre>
  
  <p>I keep getting error outputs like this:</p>
  
  <blockquote>
    <p>Error writing to port - Resource temporarily unavailable(35).</p>
  </blockquote>
  
  <p>It's driving me nuts! Because the same code actually works on Linux, so where is the difference here to OSX? What does it mean the Resource is temporarily unavailable?</p>
  
  <p>I hope i was describing my problem well enough, and someone can help me!
  Thanks!</p>