From 06cf6420740a86a003b47a84499a1bf2c86544f7 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Wed, 15 Mar 2023 20:31:16 +0000 Subject: [PATCH] Make specific to RDM6300 card reader --- main.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/main.py b/main.py index 6d7ef4b..704d0d0 100644 --- a/main.py +++ b/main.py @@ -51,7 +51,7 @@ def init(): GPIO.output(RFID_EN_PIN, GPIO.LOW) logging.info('GPIO initialized') - ser = serial.Serial(port='/dev/ttyAMA0', baudrate=secrets.BAUD_RATE, timeout=0.1) + ser = serial.Serial(port='/dev/ttyAMA0', baudrate=secrets.BAUD_RATE, timeout=0.05) logging.info('Serial initialized') for sig in (SIGABRT, SIGILL, SIGINT, SIGSEGV, SIGTERM): @@ -71,7 +71,8 @@ def reader_thread(card_data_queue): except Empty: pass - card = ser.readline() + ser.reset_input_buffer() + card = ser.read(100) if not card: continue @@ -83,16 +84,15 @@ def reader_thread(card_data_queue): except UnicodeDecodeError: continue - logging.debug('Card read string: %s', card) + card = card[1:11] - if len(card) != 10: - logging.debug('Card length not 10, skipping') - continue + logging.debug('Card read string: %s', card) # debounce card scans now = time.time() if card in recent_scans: if now - recent_scans[card] < 5.0: + logging.debug('Debouncing scan') continue recent_scans[card] = now