charlysan / pyrfidhid Goto Github PK
View Code? Open in Web Editor NEWPython library to control Chinese USB HID 125Khz RFID Reader/Writer
License: MIT License
Python library to control Chinese USB HID 125Khz RFID Reader/Writer
License: MIT License
https://github.com/NiceLabs/usb-125khz-idrw
I want to record to README file
I have just successfully purchased an RFID Reader/Writer (just like this one) on AliExpress: https://www.aliexpress.com/item/RFID-Copier-125KHz-EM4100-Cloner-Writer-Duplicator-Programmer-Reader-5-Pcs-EM4305-T5577-Rewritable-ID-Keyfobs/32721839667.html?spm=a2g0s.9042311.0.0.2b494c4d1v0Omv, interesting thing is that when I searched for IDRW V3 on Google Images, all photos contained the same reader but instead they all had following text on them: Microsoft Windows, FC and USB Reader. The only thing that his has is RFID Reader, should it work? Or I just purchased something not right?
Hi Charlysan,
I've install you library and trying to run it failed :
root@orangepipcplus:~/pyrfidhid-master# python examples/read.py
Initializing device...
Traceback (most recent call last):
File "examples/read.py", line 76, in <module>
main()
File "examples/read.py", line 48, in main
rfid.init()
File "build/bdist.linux-armv7l/egg/rfidhid/core.py", line 58, in init
File "build/bdist.linux-armv7l/egg/rfidhid/usb_hid.py", line 43, in get_report_descriptor
File "build/bdist.linux-armv7l/egg/usb/control.py", line 173, in get_descriptor
File "build/bdist.linux-armv7l/egg/usb/core.py", line 1043, in ctrl_transfer
File "build/bdist.linux-armv7l/egg/usb/backend/libusb1.py", line 883, in ctrl_transfer
File "build/bdist.linux-armv7l/egg/usb/backend/libusb1.py", line 595, in _check
usb.core.USBError: [Errno 32] Pipe error
I've also tried on my own desktop, and it is failing with the same stacktrace ...
Any idea ?
I am using an RFID reader with Raspberry Pi 3 and when I execute that code, I am getting this error
Cannot write USB feature report. Maybe incompatible device?
Traceback (most recent call last):
File "/home/pi/PFE/RFID/read.py", line 11, in <module>
payload_response = rfid.read_tag()
File "/usr/local/lib/python3.9/dist-packages/rfidhid/core.py", line 96, in read_tag
response = self.hid.set_feature_report(1, buff)
File "/usr/local/lib/python3.9/dist-packages/rfidhid/usb_hid.py", line 52, in set_feature_report
return self.dev.ctrl_transfer(
File "/usr/local/lib/python3.9/dist-packages/usb/core.py", line 1080, in ctrl_transfer
self._ctx.managed_claim_interface(self, interface_number)
File "/usr/local/lib/python3.9/dist-packages/usb/core.py", line 113, in wrapper
return f(self, *args, **kwargs)
File "/usr/local/lib/python3.9/dist-packages/usb/core.py", line 178, in managed_claim_interface
self.backend.claim_interface(self.handle, i)
File "/usr/local/lib/python3.9/dist-packages/usb/backend/libusb1.py", line 829, in claim_interface
_check(self.lib.libusb_claim_interface(dev_handle.handle, intf))
File "/usr/local/lib/python3.9/dist-packages/usb/backend/libusb1.py", line 604, in _check
raise USBError(_strerror(ret), ret, _libusb_errno[ret])
usb.core.USBError: [Errno 16] Resource busy
Does anyone know how to solve it please ?
If I change the VID and PID in core.py it doesn't seem to use the new ID's when I run read.py. Thanks
https://store.roboticsbd.com/rfid-nfc/1817-rfid-nfc-card-reader-usb-1356mhz-robotics-bangladesh.html
Can I use it with this lib
No idea why I get busy errors.
[22393.205161] usb 1-1: new low-speed USB device number 19 using xhci_hcd
[22393.344665] usb 1-1: New USB device found, idVendor=0108, idProduct=0100
[22393.344666] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[22393.344667] usb 1-1: Product: USB Smart Card Reader
[22393.344668] usb 1-1: Manufacturer: JX-SCI_001
[22393.344668] usb 1-1: SerialNumber: V1.00
[22393.350046] hid-generic 0003:0108:0100.000C: hiddev96,hidraw1: USB HID v1.10 Device [JX-SCI_001 USB Smart Card Reader] on usb-0000:00:14.0-1/input0
Made this test to use the device.
# lsusb -vd 0108:0100
Bus 001 Device 020: ID 0108:0100
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 1.10
bDeviceClass 0
bDeviceSubClass 0
bDeviceProtocol 0
bMaxPacketSize0 8
idVendor 0x0108
idProduct 0x0100
bcdDevice 0.00
iManufacturer 1 JX-SCI_001
iProduct 2 USB Smart Card Reader
iSerial 3 V1.00
bNumConfigurations 1
Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 34
bNumInterfaces 1
bConfigurationValue 1
iConfiguration 0
bmAttributes 0xe0
Self Powered
Remote Wakeup
MaxPower 200mA
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 1
bInterfaceClass 3 Human Interface Device
bInterfaceSubClass 0
bInterfaceProtocol 0
iInterface 0
HID Device Descriptor:
bLength 9
bDescriptorType 33
bcdHID 1.10
bCountryCode 51 Unknown
bNumDescriptors 1
bDescriptorType 34 Report
wDescriptorLength 29
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 5
Device Status: 0x0000
(Bus Powered)
# cat test
from rfidhid.core import RfidHid
try:
# Try to open RFID device using default vid:pid (ffff:0035)
rfid = RfidHid(0x0108,0x0100)
except Exception as e:
print(e)
exit()
payload_response = rfid.read_tag()
uid = payload_response.get_tag_uid()
rfid.beep()
print(uid)
# python test
Traceback (most recent call last):
File "test", line 10, in <module>
payload_response = rfid.read_tag()
File "/root/code/pyrfidhid/rfidhid/core.py", line 122, in read_tag
response = self.dev.ctrl_transfer(0x21, self.SET_REPORT, 0x0301, 0, buff)
File "/root/.local/lib64/python3.5/site-packages/usb/core.py", line 1034, in ctrl_transfer
self._ctx.managed_claim_interface(self, interface_number)
File "/root/.local/lib64/python3.5/site-packages/usb/core.py", line 102, in wrapper
return f(self, *args, **kwargs)
File "/root/.local/lib64/python3.5/site-packages/usb/core.py", line 167, in managed_claim_interface
self.backend.claim_interface(self.handle, i)
File "/root/.local/lib64/python3.5/site-packages/usb/backend/libusb1.py", line 811, in claim_interface
_check(self.lib.libusb_claim_interface(dev_handle.handle, intf))
File "/root/.local/lib64/python3.5/site-packages/usb/backend/libusb1.py", line 595, in _check
raise USBError(_strerror(ret), ret, _libusb_errno[ret])
usb.core.USBError: [Errno 16] Resource busy
I did notice that the thing gives errors after being plugged in awhile.
# lsusb -vd 0108:0100
Bus 001 Device 020: ID 0108:0100
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 1.10
bDeviceClass 0
bDeviceSubClass 0
bDeviceProtocol 0
bMaxPacketSize0 8
idVendor 0x0108
idProduct 0x0100
bcdDevice 0.00
iManufacturer 1 (error)
iProduct 2 (error)
iSerial 3 V1.00
bNumConfigurations 1
Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 34
bNumInterfaces 1
bConfigurationValue 1
iConfiguration 0
bmAttributes 0xe0
Self Powered
Remote Wakeup
MaxPower 200mA
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 1
bInterfaceClass 3 Human Interface Device
bInterfaceSubClass 0
bInterfaceProtocol 0
iInterface 0
HID Device Descriptor:
bLength 9
bDescriptorType 33
bcdHID 1.10
bCountryCode 51 Unknown
bNumDescriptors 1
bDescriptorType 34 Report
wDescriptorLength 29
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 5
Device Status: 0x0000
(Bus Powered)
tree ~/code/pyrfidhid #
I am getting No backend available
when execute python read.py
Using RFID card of 13.56 MHZ
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:
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.
I had some problems with using this tool.
I have the following system and configuration:
Python 3.7.4
pip 19.2.3
5.3.12-1-MANJARO
$ lsusb -d ffff:0035
Bus 002 Device 008: ID ffff:0035 IC Reader IC Reader
$ cat /etc/udev/rules.d/99-rfidreader.rule
SUBSYSTEM=="usb", ATTR{idVendor}=="ffff", ATTR{idProduct}=="0035", MODE="0666", GROUP="usbusers"
$ groups
... usbusers ...
I tried to use the CLI utility, but I got the following trace:
$ rfid_cli -h
Traceback (most recent call last):
File "/usr/bin/rfid_cli", line 11, in <module>
load_entry_point('pyrfidhid==1.0', 'console_scripts', 'rfid_cli')()
File "/usr/lib/python3.7/site-packages/pyrfidhid-1.0-py3.7.egg/cli/rfid_cli.py", line 410, in main
File "/usr/lib/python3.7/site-packages/pyrfidhid-1.0-py3.7.egg/cli/rfid_cli.py", line 43, in __init__
File "/usr/lib/python3.7/site-packages/pyrfidhid-1.0-py3.7.egg/cli/rfid_cli.py", line 303, in parse_arguments
TypeError: __init__() got an unexpected keyword argument 'version'
And when I tried to use it from source, eg. using your read.py
example, also failed:
$ python read.py
Initializing device...
Traceback (most recent call last):
File "read.py", line 76, in <module>
main()
File "read.py", line 48, in main
rfid.init()
File "/usr/lib/python3.7/site-packages/pyrfidhid-1.0-py3.7.egg/rfidhid/core.py", line 58, in init
File "/usr/lib/python3.7/site-packages/pyrfidhid-1.0-py3.7.egg/rfidhid/usb_hid.py", line 43, in get_report_descriptor
File "/usr/lib/python3.7/site-packages/usb/control.py", line 173, in get_descriptor
data_or_wLength = desc_size)
File "/usr/lib/python3.7/site-packages/usb/core.py", line 1025, in ctrl_transfer
self._ctx.managed_open()
File "/usr/lib/python3.7/site-packages/usb/core.py", line 102, in wrapper
return f(self, *args, **kwargs)
File "/usr/lib/python3.7/site-packages/usb/core.py", line 120, in managed_open
self.handle = self.backend.open_device(self.dev)
File "/usr/lib/python3.7/site-packages/usb/backend/libusb1.py", line 786, in open_device
return _DeviceHandle(dev)
File "/usr/lib/python3.7/site-packages/usb/backend/libusb1.py", line 643, in __init__
_check(_lib.libusb_open(self.devid, byref(self.handle)))
File "/usr/lib/python3.7/site-packages/usb/backend/libusb1.py", line 595, in _check
raise USBError(_strerror(ret), ret, _libusb_errno[ret])
usb.core.USBError: [Errno 13] Access denied (insufficient permissions)
Using sudo
did not help.
$ sudo python read.py
Initializing device...
Traceback (most recent call last):
File "read.py", line 76, in <module>
main()
File "read.py", line 48, in main
rfid.init()
File "/usr/lib/python3.7/site-packages/pyrfidhid-1.0-py3.7.egg/rfidhid/core.py", line 58, in init
File "/usr/lib/python3.7/site-packages/pyrfidhid-1.0-py3.7.egg/rfidhid/usb_hid.py", line 43, in get_report_descriptor
File "/usr/lib/python3.7/site-packages/usb/control.py", line 173, in get_descriptor
data_or_wLength = desc_size)
File "/usr/lib/python3.7/site-packages/usb/core.py", line 1043, in ctrl_transfer
self.__get_timeout(timeout))
File "/usr/lib/python3.7/site-packages/usb/backend/libusb1.py", line 883, in ctrl_transfer
timeout))
File "/usr/lib/python3.7/site-packages/usb/backend/libusb1.py", line 595, in _check
raise USBError(_strerror(ret), ret, _libusb_errno[ret])
usb.core.USBError: [Errno 32] Pipe error
I have strictly followed the Setup steps for Linux.
# libusb-1.0-0-dev was already installed
$ sudo pip install pyusb
$ sudo python setup.py install
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.