NFC RFID Hardware – USB stick – SYC ID&IC USB Reader
USB stick voor het uitlezen van NFC RFID tags, dit is een HID device en wordt als input device gezien.
Gebruik Windows: De stick typt een (serie?)nummer in (bijvoorbeeld notepad/excel) met daarachten een ENTER
Gebruik Linux: Met een script hieronder kan het serienummer opgevangen worden in de terminal en zelfs op de achtergrond gedraaid worden.
Gegevens
1 2 3 4 5 6 7 8 9 |
[2527446.633988] usb 1-1.4: new low-speed USB device number 34 using dwc_otg [2527446.795770] usb 1-1.4: New USB device found, idVendor=ffff, idProduct=0035 [2527446.795784] usb 1-1.4: New USB device strings: Mfr=1, Product=2, SerialNumber=3 [2527446.795793] usb 1-1.4: Product: SYC ID&IC USB Reader [2527446.795801] usb 1-1.4: Manufacturer: Sycreader RFID Technology Co., Ltd [2527446.795809] usb 1-1.4: SerialNumber: 08FF20140315 [2527446.821193] input: Sycreader RFID Technology Co., Ltd SYC ID&IC USB Reader as /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.4/1-1.4:1.0/0003:FFFF:0035.0001/input/input0 [2527446.887751] hid-generic 0003:FFFF:0035.0001: input,hidraw0: USB HID v1.10 Keyboard [Sycreader RFID Technology Co., Ltd SYC ID&IC USB Reader] on usb-3f980000.usb-1.4/input0 [2527446.893301] usbhid 1-1.4:1.1: couldn't find an input interrupt endpoint |
Bus 001 Device 035: ID ffff:0035
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
Bus 001 Device 035: ID ffff:0035 Couldn't open device, some information will be missing Device Descriptor: bLength 18 bDescriptorType 1 bcdUSB 1.10 bDeviceClass 0 (Defined at Interface level) bDeviceSubClass 0 bDeviceProtocol 0 bMaxPacketSize0 8 idVendor 0xffff idProduct 0x0035 bcdDevice 1.00 iManufacturer 1 iProduct 2 iSerial 3 bNumConfigurations 1 Configuration Descriptor: bLength 9 bDescriptorType 2 wTotalLength 52 bNumInterfaces 2 bConfigurationValue 1 iConfiguration 0 bmAttributes 0xa0 (Bus Powered) Remote Wakeup MaxPower 100mA Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 0 bAlternateSetting 0 bNumEndpoints 1 bInterfaceClass 3 Human Interface Device bInterfaceSubClass 1 Boot Interface Subclass bInterfaceProtocol 1 Keyboard iInterface 4 HID Device Descriptor: bLength 9 bDescriptorType 33 bcdHID 1.10 bCountryCode 33 US bNumDescriptors 1 bDescriptorType 34 Report wDescriptorLength 65 Report Descriptors: ** UNAVAILABLE ** Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x81 EP 1 IN bmAttributes 3 Transfer Type Interrupt Synch Type None Usage Type Data wMaxPacketSize 0x0008 1x 8 bytes bInterval 10 Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 1 bAlternateSetting 0 bNumEndpoints 0 bInterfaceClass 3 Human Interface Device bInterfaceSubClass 0 No Subclass bInterfaceProtocol 0 None iInterface 5 HID Device Descriptor: bLength 9 bDescriptorType 33 bcdHID 1.10 bCountryCode 33 US bNumDescriptors 1 bDescriptorType 34 Report wDescriptorLength 35 Report Descriptors: ** UNAVAILABLE ** |
Python
RFID_reader
Designed to use with the ‘Sycreader RFID Technology Co., Ltd SYC ID&IC USB Reader’
With minor changes can be used with any RFID reader device.
The program binds the rfid reader to the terminal which started the script.
This way the terminal only accepts input from the device and can be run in the background.
You can stop the script with the Control + c key combination.
Before running the script you have to set permission of /dev/input/
by
sudo chown <user who runs the script> -R /dev/input/
After reconnecting the device or force stopping the script (Control + z) permission have to be set again.Otherwise the device won’t be seen.
– evdev python library
Voor Python:
sudo pip3 install evdev
Voor Python3:
sudo pip3 install evdev
1 2 3 4 5 6 7 8 |
Collecting evdev Downloading https://files.pythonhosted.org/packages/7e/53/374b82dd2ccec240b738 Building wheels for collected packages: evdev Running setup.py bdist_wheel for evdev ... done Stored in directory: /root/.cache/pip/wheels/f6/ad/e1/5d30bce69dba5c09b23c054a Successfully built evdev Installing collected packages: evdev Successfully installed evdev-1.1.2 |
Script
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
import evdev from evdev import categorize, ecodes class Device(): name = 'Sycreader RFID Technology Co., Ltd SYC ID&IC USB Reader' @classmethod def list(cls, show_all=False): # list the available devices devices = [evdev.InputDevice(fn) for fn in evdev.list_devices()] if show_all: for device in devices: print("event: " + device.fn, "name: " + device.name, "hardware: " + device.phys) return devices @classmethod def connect(cls): # connect to device if available try: device = [dev for dev in cls.list() if cls.name in dev.name][0] device = evdev.InputDevice(device.fn) return device except IndexError: print("Device not found.\n - Check if it is properly connected. \n - Check permission of /dev/input/ (see README.md)") exit() @classmethod def run(cls): device = cls.connect() container = [] try: device.grab() # bind the device to the script print("RFID scanner is ready....") print("Press Control + c to quit.") for event in device.read_loop(): # enter into an endeless read-loop if event.type == ecodes.EV_KEY and event.value == 1: digit = evdev.ecodes.KEY[event.code] if digit == 'KEY_ENTER': # create and dump the tag tag = "".join(i.strip('KEY_') for i in container) print(tag) container = [] else: container.append(digit) except: # catch all exceptions to be able release the device device.ungrab() print('Quitting.') Device.run() |
1 2 3 4 |
RFID scanner is ready.... Press Control + c to quit. 0980126883 0980126883 |