1
��L��       óôLª         ôôL│Â
      ôôL≥Â
         ôôL:
                      ôôL<
                                       õôL┬      õôL
┬         õôL,               õôL,          öôL÷      öôLü         öôLä       öôLç         öôLÎá
      öôLÓá
         ÷ôLâ³      ÷ôLç³         ÷ôL]æ       ÷ôL◆æ         ÷ôL≥á
      ÷ôL£á
         øôL D      øôL"D         øôLW       øôLW         øôLª  !   øôª         ùôLê÷  !    ùôLí÷         ùôL  !   ùôL          ùôL&ç         !    ùôL(ç          úôLÞ÷  !   úôLà÷         úôL<  !    úôL>         úôL»+    !   úôL¼+          úôL¢
  !    úôL¢
         ûôL  !   ûôL         ûôLJ*  !    ûôLM*         ûôL  !   ûôL         ûôLB
  !    ûôLD
         ýôLÞ   !    ýôLà          ýôL  !   ýôL         ýôLôLàÎ
         ÿôL¨   !    ÿôLª          ÿôL]␉  !   ÿôL◆␉         ÿôLø  !    ÿôLø         ÿôLÏ≠
      !   ÿôLÒ≠
          ôL¾#  !    ôLÁ#          ôL=Ù  !     ôL@Ù          ôL»
  !    ôL½
          ôL7»
                 !     ôL:»
                                        ôLð  !    ôLó         ôL└   !    ôL⎺          ôL'ñ  !   ôL*ñ         ôL¨¬  !    ôLª¬         ôL!Ù  !   ôL#Ù         ôL␍ò  !  

This is some output using cat /my/device/file for a joystick. How do I exactly read a device file? Are the above binary bytes? I just need to be able to detect what characters these are.

Tutorials/suggestions would be great!

4 Answers 4

3

A device file is just a link to kernel space. The output and how to "read" a device file depends on the device itself. You will have to consult the docs for your driver (if there are any) or read the source to figure out what its writing there.

My best guess is its binary described by a C structure in the driver source.

2
  • I am about to accept your answer, but what do you mean "read the source?" The device file itself? Nov 29, 2010 at 21:22
  • @Carlo - The source I'm talking about would be the C source code of the driver that creates this /dev entry in the linux kernel source from kernel.org
    – bot403
    Nov 29, 2010 at 22:04
1

Device files are special files, not text files like many files under /proc.

If you just want setup your joystick use a userspace program, see e.g. the instruction here. Your desktop environment might also come with dedicated software to configure it. To access them directly you will need to access them via their C API.

1
  • I know what you mean, but I think you mean more like 'Device files have special formatting'. As how they work, they're pretty similar internally, just the formatting is different. Nov 30, 2010 at 16:06
1

A 'device file' is a special node on disk that links to code within the kernel. This code is the device driver. When the device driver is loaded, you set up specific functions to be called when certain system calls (open/read/write/close/etc...) are called on the 'file'.

So, when you call 'read', it calls a specific function in the device driver code. This code can do pretty much anything in kernel mode; in this case it makes sense to take a hardware reading of the joystick, convert the voltage values to numbers, and let it be read() from the device file.

Just random guessing, I'm sure the values being sent out are just position readings of the joystick X and Y (and Z?) and some settings of buttons. Reading as text won't work, you need something that does hex and/or numeric dumps. Plug the joystick in, read the values from it, and move the joystick around mash the buttons and see how the values change.

The source code may have comments stating what the values mean, though the actual code is probably unreadable to you (unless you know what the hardware registers and the USB protocol stuff means).

0

You should make sure that the baud rate of your device is equivalent to the baud rate of your serial port.

Check the speed baud:
$ stty < /my/device/file

and equal both device and serial port speeds:
$ stty -F /my/device/file XXspeedXX

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .