riccardo airone
riccardo airone

Reputation: 506

linux command to read RFID usb port

im try to read data from an usb RFID reader.

airone@airone:~$ sudo tree /dev/input
/dev/input
├── by-id
│   ├── usb-413c_3010-event-mouse -> ../event2
│   ├── usb-413c_3010-mouse -> ../mouse0
│   ├── usb-Dell_Dell_USB_Keyboard-event-kbd -> ../event3
│   └── usb-Sycreader_RFID_Technology_Co.__Ltd_SYC_ID_IC_USB_Reader_08FF20140315-event-kbd -> ../event5
├── by-path
│   ├── pci-0000:00:1a.0-usb-0:1:1.0-event-kbd -> ../event5
│   ├── pci-0000:00:1d.1-usb-0:2:1.0-event-mouse -> ../event2
│   ├── pci-0000:00:1d.1-usb-0:2:1.0-mouse -> ../mouse0
│   └── pci-0000:00:1d.2-usb-0:1:1.0-event-kbd -> ../event3
├── event0
├── event1
├── event2
├── event3
├── event4
├── event5
├── mice
└── mouse0

2 directories, 16 files
airone@airone:~$ 

my RIFD reader is:

usb-Sycreader_RFID_Technology_Co.__Ltd_SYC_ID_IC_USB_Reader_08FF20140315-event-kbd -> ../event5

when i put the token near the RFID i get this:

2 directories, 16 files
airone@airone:~$ sudo cat -v /dev/input/by-id/usb-Sycreader_RFID_Technology_Co.__Ltd_SYC_ID_IC_USB_Reader_08FF20140315-event-kbd 
M-1ZKX~M-m^A^@^D^@^D^@'^@^G^@M-1ZKX~M-m^A^@^A^@^K^@^A^@^@^@M-1ZKX~M-m^A^@^@^@^@^@^@^@^@^@M-1ZKXM-7^L^B^@^D^@^D^@'^@^G^@M-1ZKXM-7^L^B^@^A^@^K^@^@^@^@^@M-1ZKXM-7^L^B^@^@^@^@^@^@^@^@^@M-1ZKXM-s+^B^@^D^@^D^@'^@^G^@M-1ZKXM-s+^B^@^A^@^K^@^A^@^@^@M-1ZKXM-s+^B^@^@^@^@^@^@^@^@^@M-1ZKX1K^B^@^D^@^D^@'^@^G^@M-1ZKX1K^B^@^A^@^K^@^@^@^@^@M-1ZKX1K^B^@^@^@^@^@^@^@^@^@M-1ZKXpj^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0M-B^C^@^D^@^D^@%^@^G^@M-1ZKX0M-B^C^@^A^@    ^@^@^@^@^@M-1ZKX0M-B^C^@^@^@^@^@^@^@^@^@M-1ZKXtM-a^C^@^D^@^D^@"^@^G^@M-1ZKXtM-a^C^@^A^@^F^@^A^@^@^@M-1ZKXtM-a^C^@^@^@^@^@^@^@^@^@M-1ZKXM-1^@^D^@^D^@^D^@"^@^G^@M-1ZKXM-1^@^D^@^A^@^F^@^@^@^@^@M-1ZKXM-1^@^D^@^@^@^@^@^@^@^@^@M-1ZKXM-q^_^D^@^D^@^D^@&^@^G^@M-1ZKXM-q^_^D^@^A^@
^@^A^@^@^@M-1ZKXM-q^_^D^@^@^@^@^@^@^@^@^@M-1ZKX1?^D^@^D^@^D^@&^@^G^@M-1ZKX1?^D^@^A^@
^@^@^@^@^@M-1ZKX1?^D^@^@^@^@^@^@^@^@^@M-1ZKXr^^D^@^D^@^D^@(^@^G^@M-1ZKXr^^D^@^A^@^\^@^A^@^@^@M-1ZKXr^^D^@^@^@^@^@^@^@^@^@M-1ZKXM-2}^D^@^D^@^D^@(^@^G^@M-1ZKXM-2}^D^@^A^@^\^@^@^@^@^@M-1ZKXM-2}^D^@^@^@^@^@^@^@^@^@0005665859

how I can translate this ? its possibile ? thanks a lot for helping me

Upvotes: 2

Views: 8454

Answers (2)

Raleigh L.
Raleigh L.

Reputation: 913

You already figured out how to identify the keyboard device, all you have to do is pipe your output to hexdump -- here's an example:

$ sudo cat /dev/input/by-path/pci-0000:00:14.0-usb-0:4.4.4:1.0-event-kbd | hexdump

This gives the usual hexdump output:

0000000 7b84 61d6 0000 0000 f504 0007 0000 0000
0000010 0004 0004 0027 0007 7b84 61d6 0000 0000
0000020 f504 0007 0000 0000 0001 000b 0001 0000
0000030 7b84 61d6 0000 0000 f504 0007 0000 0000
0000040 0000 0000 0000 0000 7b84 61d6 0000 0000
0000050 1422 0008 0000 0000 0004 0004 0027 0007

Upvotes: 0

Lode
Lode

Reputation: 41

Use evdump to interpret the raw data: evdump /dev/input/by-id/usb-Sycreader_RFID_Technology_Co.__Ltd_SYC_ID_IC_USB_Reader_*

I assume you'd like to read the entire RFID code. For this, use the following Python script which is largely based on https://stackoverflow.com/a/27913707/5795026:

from evdev import InputDevice, ecodes, list_devices
from select import select

keys = "X^1234567890XXXXqwertzuiopXXXXasdfghjklXXXXXyxcvbnmXXXXXXXXXXXXXXXXXXXXXXX"
dev = InputDevice("/dev/input/by-id/usb-Sycreader_RFID_Technology_Co.__Ltd_SYC_ID_IC_USB_Reader_08FF20140315-event-kbd")

barcode = ""
while True:
    r,w,x = select([dev], [], [])

    for event in dev.read():
        if event.type != 1 or event.value != 1:
            continue
        if event.code == 28:
            print(barcode)
            barcode = ""
            break
        barcode += keys[event.code]

Upvotes: 4

Related Questions