title: How can I use the cat command to read from a character device with my own character device driver?
body: <p>I am trying to write a simple read/write character driver for a beaglebone. One of the tasks is to be able to use the cat command to read from the device, but I am unable to do so.</p>
  
  <p>Here is the code for my read function for my character device driver located inside <code>char_drvr.c</code>:</p>
  
  <pre><code>ssize_t lkm_read (struct file *pfile,
                    char __user *buffer,
                    size_t length,
                    loff_t *offset)
  {
      int device_buffer = (int)gpio_get_value(gpioIn); //gets value from gpio pin (HI or LO)
      return simple_read_from_buffer(buffer,length, offset, &amp;device_buffer, sizeof(int));     
  }
  </code></pre>
  
  <p>Read executes successfully (the correct value is returned) when I run my test application, so I know that device is able to communicate with the device driver, but nothing is returned (right away) when I run</p>
  
  <pre><code>$cat /dev/simple_char_driver
  </code></pre>
  
  <p>My full code: <a href="https://github.com/gteeger/character_driver1" rel="nofollow noreferrer">https://github.com/gteeger/character_driver1</a></p>
  
  <p>Attempted solutions:</p>
  
  <p><a href="https://stackoverflow.com/questions/31563107/cat-function-calling-read-infinite-times">cat function calling read() infinite times</a></p>
  
  <p><a href="https://stackoverflow.com/questions/26484046/c-infinite-read-from-cat-in-device-file">C - infinite read from cat in Device file</a></p>
  
  <p>and a few others.</p>
  
  <p>Any help is greatly appreciated</p>