File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -43,19 +43,18 @@ def myLoop(app, reader):
4343 last_time = 0
4444 scanner_error = False
4545 while True :
46- time .sleep (0.1 )
47-
4846 if scanner_error :
47+ time .sleep (0.1 )
4948 if reader .reconnect ():
5049 logging .info ("Card reader reconnected" )
5150 scanner_error = False
5251 continue
5352
5453 try :
5554 in_waiting = reader .getSerInWaiting ()
56- except OSError :
55+ except OSError as e :
5756 if not scanner_error :
58- logging .error ("Card reader disconnected, disabling until reconnection" )
57+ logging .error ("Card reader disconnected, disabling until reconnection: %s" , e )
5958 scanner_error = True
6059 continue
6160
Original file line number Diff line number Diff line change @@ -26,8 +26,8 @@ def __init__(self, usb_id="/dev/ttyUSB0"):
2626 logging .info ("Card reader init finished" )
2727
2828 def _init_pn532 (self ):
29- uart = serial .Serial (self ._usb_id , baudrate = 115200 , timeout = 1 )
30- self ._pn532 = PN532_UART (uart , debug = False )
29+ uart = serial .Serial (self ._usb_id , baudrate = 115200 , timeout = 0. 1 )
30+ self ._pn532 = PN532_UART (uart , debug = True )
3131 self ._pn532 .SAM_configuration ()
3232
3333 def reconnect (self ):
@@ -47,6 +47,8 @@ def getSerInWaiting(self):
4747 raise OSError (f"PN532 error: { e } " )
4848 if uid :
4949 self ._pending_tag = "" .join (f"{ b :02X} " for b in uid )
50+ time .sleep (0.01 ) # let any remaining in-flight bytes arrive
51+ self ._pn532 ._uart .reset_input_buffer () # and flush them
5052 return expected_characters
5153 self ._pending_tag = None
5254 return 0
You can’t perform that action at this time.
0 commit comments