From 51c70d2f88ca7235620e818744d498888968109e Mon Sep 17 00:00:00 2001 From: Matthew Frost Date: Wed, 1 Nov 2023 17:45:12 +0100 Subject: [PATCH] decding eror --- python/example-tinance2.py | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/python/example-tinance2.py b/python/example-tinance2.py index 612f898..3393e17 100644 --- a/python/example-tinance2.py +++ b/python/example-tinance2.py @@ -125,25 +125,28 @@ def serial_router(): data = ser.readline() try: data = data.decode('utf-8') - if '=' in data: - prefix, value = data.split('=') - prefix = prefix.strip() - value = value.strip() + try: + if '=' in data: + prefix, value = data.split('=') + prefix = prefix.strip() + value = value.strip() - actions = { - "LOG_MSG": handle_log_msg, - "FULL_CARD_ID": check_valid_card, - "DOOR_DISABLED_STATUS": handle_log_msg, - "DOOR_LOCK_STATUS": handle_log_msg - } + actions = { + "LOG_MSG": handle_log_msg, + "FULL_CARD_ID": check_valid_card, + "DOOR_DISABLED_STATUS": handle_log_msg, + "DOOR_LOCK_STATUS": handle_log_msg + } - if prefix in actions: - actions[prefix](prefix, value) - else: - print(f"Unknown prefix: {prefix}") - except UnicodeDecodeError: - hex_data = binascii.hexlify(data).decode('utf-8') - print(f"Received non-UTF-8 data: {hex_data}") + if prefix in actions: + actions[prefix](prefix, value) + else: + print(f"Unknown prefix: {prefix}") + except UnicodeDecodeError: + hex_data = binascii.hexlify(data).decode('utf-8') + print(f"Received non-UTF-8 data: {hex_data}") + except: + print("Error decoding serial data") def start_thread(thread_function): thread = threading.Thread(target=thread_function)