Hello all - long time listener - first time caller…
I have a project running on a Pi that is driving me insane. Everything is working EXCEPT the case where a user swipes their card multiple times in short succession
First the section of code that’s doing the read:
#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')
logger.debug('Card UID string '+snum)
print (snum)
In the normal running of things my logfile shows the following:
2022-03-20 15:36:09,378 - DEBUG - key C
2022-03-20 15:36:09,379 - DEBUG - 2
2022-03-20 15:36:09,396 - DEBUG - key A
2022-03-20 15:36:09,397 - DEBUG - 3
2022-03-20 15:36:09,414 - DEBUG - key B
2022-03-20 15:36:09,415 - DEBUG - 4
2022-03-20 15:36:09,432 - DEBUG - key D
2022-03-20 15:36:09,433 - DEBUG - 5
2022-03-20 15:36:09,450 - DEBUG - key 5
2022-03-20 15:36:09,451 - DEBUG - 6
2022-03-20 15:36:09,468 - DEBUG - key B
2022-03-20 15:36:09,469 - DEBUG - 7
2022-03-20 15:36:09,486 - DEBUG - key 0
2022-03-20 15:36:09,487 - DEBUG - 8
2022-03-20 15:36:09,504 - DEBUG - key 4
2022-03-20 15:36:09,504 - DEBUG - 9
2022-03-20 15:36:09,505 - DEBUG - card read complete
2022-03-20 15:36:09,506 - DEBUG - rfidstring is: CABD5B04
2022-03-20 15:36:09,507 - DEBUG - rfidstring is now:
2022-03-20 15:36:09,508 - DEBUG - Card Detected
2022-03-20 15:36:09,509 - DEBUG - Card UID string cabd5b04
2022-03-20 15:36:09,513 - DEBUG - ('David', 'Birch', 'TRUE', '1073A', 13, 'cabd5b04')
However, if the user swipes several times within a second or two, then I get this:
2022-03-20 15:36:12,991 - DEBUG - key B
2022-03-20 15:36:12,991 - DEBUG - 2
2022-03-20 15:36:12,992 - DEBUG - key D
2022-03-20 15:36:12,993 - DEBUG - 3
2022-03-20 15:36:12,994 - DEBUG - key 5
2022-03-20 15:36:12,994 - DEBUG - 4
2022-03-20 15:36:12,995 - DEBUG - key B
2022-03-20 15:36:12,996 - DEBUG - 5
2022-03-20 15:36:12,997 - DEBUG - key 0
2022-03-20 15:36:12,997 - DEBUG - 6
2022-03-20 15:36:12,998 - DEBUG - key 4
2022-03-20 15:36:12,999 - DEBUG - 7
2022-03-20 15:36:17,978 - DEBUG - key C
2022-03-20 15:36:17,979 - DEBUG - 8
2022-03-20 15:36:17,996 - DEBUG - key A
2022-03-20 15:36:17,997 - DEBUG - 9
2022-03-20 15:36:18,000 - DEBUG - card read complete
2022-03-20 15:36:18,001 - DEBUG - rfidstring is: BD5B04CA
2022-03-20 15:36:18,002 - DEBUG - rfidstring is now:
2022-03-20 15:36:18,002 - DEBUG - Card Detected
2022-03-20 15:36:18,003 - DEBUG - Card UID string bd5b04ca
2022-03-20 15:36:18,007 - DEBUG - Unknown Card
2022-03-20 15:36:21,272 - DEBUG - key B
2022-03-20 15:36:21,273 - DEBUG - 2
2022-03-20 15:36:21,274 - DEBUG - key D
2022-03-20 15:36:21,274 - DEBUG - 3
2022-03-20 15:36:21,275 - DEBUG - key 5
2022-03-20 15:36:21,276 - DEBUG - 4
2022-03-20 15:36:21,276 - DEBUG - key B
2022-03-20 15:36:21,277 - DEBUG - 5
2022-03-20 15:36:21,278 - DEBUG - key 0
2022-03-20 15:36:21,278 - DEBUG - 6
2022-03-20 15:36:21,279 - DEBUG - key 4
2022-03-20 15:36:21,280 - DEBUG - 7
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? Thanks very much in advance!