title: Failed to read a USB HID RFID-Reader with C
body: <p>i have a cheap USB-RFID-Reader. This reader is a HID-Keyboard (without buttons).
  I need to capture the output of the reader without writing it to any console.
  I have found this code here:
  <a href="https://stackoverflow.com/a/7672324/4500123">https://stackoverflow.com/a/7672324/4500123</a></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;errno.h&gt;
  #include &lt;fcntl.h&gt;
  #include &lt;dirent.h&gt;
  #include &lt;linux/input.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;sys/stat.h&gt;
  #include &lt;sys/select.h&gt;
  #include &lt;sys/time.h&gt;
  #include &lt;termios.h&gt;
  #include &lt;signal.h&gt;
  
  int main(int argc, char* argv[])
  {
      struct input_event ev[64];
      int fevdev = -1;
      int result = 0;
      int size = sizeof(struct input_event);
      int rd;
      int value;
      char name[256] = "Unknown";
      char *device = "/dev/input/event3";
  
  
      fevdev = open(device, O_RDONLY);
      if (fevdev == -1) {
          printf("Failed to open event device.\n");
          exit(1);
      }
  
      result = ioctl(fevdev, EVIOCGNAME(sizeof(name)), name);
      printf ("Reading From : %s (%s)\n", device, name);
  
      printf("Getting exclusive access: ");
      result = ioctl(fevdev, EVIOCGRAB, 1);
      printf("%s\n", (result == 0) ? "SUCCESS" : "FAILURE");
  
     while (1)
      {
          if ((rd = read(fevdev, ev, size * 64)) &lt; size) {
              break;
          }
  
          value = ev[0].value;
  
          if (value != ' ' &amp;&amp; ev[1].value == 1 &amp;&amp; ev[1].type == 1) {
              printf ("Code[%d]\n", (ev[1].code));
          }
      }
  
      printf("Exiting.\n");
      result = ioctl(fevdev, EVIOCGRAB, 1);
      close(fevdev);
      return 0;
  }
  </code></pre>
  
  <p>This code should work. I have it running on my RaspberryPI without problems.
  I try now to get this code to work on my Android Tablet (with root). But very often i missing letters or the Code is incomplete.</p>
  
  <p>If i write to a text file, all letters are be transfered without problems. But with the code it wont work properly.</p>
  
  <p>What can i do to find out the problem? Is it a timing problem?</p>