charlysan / pyrfidhid

Python library to control Chinese USB HID 125Khz RFID Reader/Writer
MIT License
142 stars 36 forks source link

Read data from USB RFID reader using Python #8

Closed danialyusri95 closed 1 year ago

danialyusri95 commented 3 years ago

I'm trying to read data from USB RFID reader using Python script. The data was write into a RFID sticker using NFC tool on my phone. So when I scan the RFID sticker at the RFID reader, Python script should display the data that I write into the RFID sticker.

For example, I write a string into RFID sticker with "Hello World".

I want it to display the string.

But this does not work. I think it doesn't work because the script used for different reader model. I tried to find the RFID reader info on my Linux by using these command.

sudo lsusb -vd ffff:0035

Bus 001 Device 003: ID ffff:0035 Sycreader USB HID READER
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               1.10
  bDeviceClass            0 
  bDeviceSubClass         0 
  bDeviceProtocol         0 
  bMaxPacketSize0        64
  idVendor           0xffff 
  idProduct          0x0035 
  bcdDevice            1.10
  iManufacturer           1 Sycreader
  iProduct                2 USB HID READER
  iSerial                 3 20170320
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength       0x001b
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0 
    bmAttributes         0xa0
      (Bus Powered)
      Remote Wakeup
    MaxPower              200mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           0
      bInterfaceClass         3 Human Interface Device
      bInterfaceSubClass      0 
      bInterfaceProtocol      0 
      iInterface              4 USB VENDER HID
        HID Device Descriptor:
          bLength                 9
          bDescriptorType        33
          bcdHID               1.10
          bCountryCode           33 US
          bNumDescriptors         1
          bDescriptorType        34 Report
          wDescriptorLength      38
          Report Descriptor: (length is 38)
            Item(Global): Usage Page, data= [ 0xa0 0xff ] 65440
                            (null)
            Item(Local ): Usage, data= [ 0x01 ] 1
                            (null)
            Item(Main  ): Collection, data= [ 0x01 ] 1
                            Application
            Item(Global): Report ID, data= [ 0x01 ] 1
            Item(Local ): Usage, data= [ 0x03 ] 3
                            (null)
            Item(Global): Report Size, data= [ 0x08 ] 8
            Item(Global): Report Count, data= [ 0xff ] 255
            Item(Main  ): Feature, data= [ 0x02 ] 2
                            Data Variable Absolute No_Wrap Linear
                            Preferred_State No_Null_Position Non_Volatile Bitfield
            Item(Global): Report ID, data= [ 0x02 ] 2
            Item(Local ): Usage, data= [ 0x03 ] 3
                            (null)
            Item(Global): Report Size, data= [ 0x08 ] 8
            Item(Global): Report Count, data= [ 0xff ] 255
            Item(Main  ): Feature, data= [ 0x02 ] 2
                            Data Variable Absolute No_Wrap Linear
                            Preferred_State No_Null_Position Non_Volatile Bitfield
            Item(Global): Report ID, data= [ 0x03 ] 3
            Item(Local ): Usage, data= [ 0x03 ] 3
                            (null)
            Item(Global): Report Size, data= [ 0x08 ] 8
            Item(Global): Report Count, data= [ 0xff ] 255
            Item(Main  ): Feature, data= [ 0x02 ] 2
                            Data Variable Absolute No_Wrap Linear
                            Preferred_State No_Null_Position Non_Volatile Bitfield
            Item(Main  ): End Collection, data=none
can't get debug descriptor: Resource temporarily unavailable
Device Status:     0x0000
  (Bus Powered)

sudo tree /dev/input


/dev/input
├── by-id
│   ├── usb-Logitech_USB_Optical_Mouse-event-mouse -> ../event7
│   ├── usb-Logitech_USB_Optical_Mouse-mouse -> ../mouse0
│   ├── usb-SONiX_USB_DEVICE-event-if01 -> ../event6
│   └── usb-SONiX_USB_DEVICE-event-kbd -> ../event2
├── by-path
│   ├── pci-0000:03:00.0-usb-0:7:1.0-event-mouse -> ../event7
│   ├── pci-0000:03:00.0-usb-0:7:1.0-mouse -> ../mouse0
│   ├── pci-0000:27:00.3-usb-0:4:1.0-event-kbd -> ../event2
│   └── pci-0000:27:00.3-usb-0:4:1.1-event -> ../event6
├── event0
├── event1
├── event10
├── event11
├── event12
├── event13
├── event14
├── event15
├── event16
├── event17
├── event18
├── event2
├── event3
├── event4
├── event5
├── event6
├── event7
├── event8
├── event9
├── mice
└── mouse0

2 directories, 29 files


But this command `sudo tree /dev/input` do not showing any device related to my RFID reader.

Hardware:

 - USB RFID reader EM4100
 - RFID sticker NXP MIFARE Ultralight (Ultralight C)

From my understanding, USB should be used as serial library in Python, but the reader act as a HID device. So I tried installing Python library using this command.

> sudo pip install hid

Anyone know how to make the Python script work or any guide that might related?

Thanks.
charlysan commented 2 years ago

@danialyusri95, that is a 13.56 MHz reader; this library only supports 125 KHZ device.