title: Reading Serial Data From C (OSX /dev/tty)
body: <p>I am trying to read data from a bluetooth barcode scanner (KDC300) using C. Here is the code I have so far, and the program successfully establishes a bluetooth connection to the scanner, but when a barcode is scanned, no input is displayed on the screen (Eventually more will be done with the data, but we have to get it working first, right). </p>
  
  <p>Here is the program:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;fcntl.h&gt;
  #include &lt;errno.h&gt;
  #include &lt;termios.h&gt;
  #include &lt;sys/ioctl.h&gt;
  
  int main (int argc, const char * argv[]) {
  
      // define vars
      int STOP = 0;
      //char buf[255];
  
      if(argv[1])
      {
          int fd = open("/dev/tty.KDC1", O_RDONLY);
          if(fd == -1)
          {
              printf("%s", strcat("Unable to open /dev/tty.", argv[1]));
          }
  
          int res;
          while(STOP == 0)
          {
              while((res = read(fd,buf,255)) == 0);
              {
                  if(res &gt; 0)
                  {
                      buf[res]=0;
                      printf("%s:%d\n", buf, res);
                      if(buf[sizeof(buf)]=='\n') break;   
                  }
              }
          }
      }
  
      return 0;
  }
  </code></pre>
  
  <p>If anyone has any ideas, I am at a loss on this so far. If it is any help, I can run <code>screen /dev/tty.KDC1</code> and any barcodes scanned on the scanner appear in the terminal, I just can't do anything with the data. </p>
  
  <p>Jud</p>