Having strange results from an RFID HID card reader - I'm stuck - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Having strange results from an RFID HID card reader - I'm stuck (/thread-36770.html) |
Having strange results from an RFID HID card reader - I'm stuck - orbisnz - Mar-28-2022 Hi all, and thanks for taking a look. I'm in the process of upgrading an old Python 2.7 program I wrote about 5 years ago to Python 3 as well as using a USB connected RFID reader rather than the old SPI interface one I used to use. So I'm using Python 3.10 on Debian Bullseye (Raspberry Pi 3+). The section of code below is used to read 8 bytes from the card reader: import evdev EVENT_READ_NUMBER = 1 #read card code here for event in device.read_loop(): if event.value == EVENT_VALUE_KEYDOWN: #logger.debug(event ) which_key = evdev.ecodes.KEY[event.code] #logger.debug(which_key) press = which_key[-1] logger.debug('key ' + press) readlist.append(press) EVENT_READ_NUMBER += 1 logger.debug(EVENT_READ_NUMBER) if EVENT_READ_NUMBER == 8: logger.debug('card read complete') rfidstring=(rfidraw.join(readlist)) logger.debug('rfidstring is: ' + rfidstring) sn = rfidstring.lower() snum = sn EVENT_READ_NUMBER = 0 readlist = [] sn = "" rfidstring = "" logger.debug('rfidstring is now: ' + rfidstring) break logger.debug('Card Detected')The card reader does not return any end of string character, if it did, I'd use that rather than count 8 bytes. When I go slow (wait at least a couple of seconds between card swipes) then it works perfectly as expected creating a result like sn = cabd5b04 which is what I'm looking for. I'm not getting any python errors (finally the code is running for me at least!) Here is the logger output from a successful swipe: The problem I'm having comes when a user repeat swipes several times in quick succession. In that case the byte order seems to get "mixed up" like part of it is read out of order/sequence. For example: To me it looks like the EVENT_READ_NUMBER is not resetting properly after getting the full 8 bytes from the rfid card. I have tried resetting everything in the for loop, but I’m hitting the end of my knowledge here. Any hints? Should I be inserting some sort of time.sleep in there somewhere? Thanks very much in advance!Pete RE: Having strange results from an RFID HID card reader - I'm stuck - Larz60+ - Mar-28-2022 Have you installed all of the python 3 drivers required (with python 3.1 active)? see chapter 2 http://python-evdev.readthedocs.io/en/latest/ for Debian, reinstall using apt: then reinstall evdev using pip
|