decding eror
This commit is contained in:
parent
afcb5e5828
commit
51c70d2f88
1 changed files with 20 additions and 17 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue