The answer part references GPT, GPT_Pro better solve the problem
Python read the serial assistant hex message how to display correctly?
For Python to correctly display HEX messages sent by the serial assistant, you must first ensure that the messages sent are correct, that is, the correct messages sent in HEX format.
Then, in python code, convert the HEX message sent by the serial assistant into hexadecimal format using the b2a_hex() function provided in python's built-in binascii library. This code is as follows:
import binascii
n = serinWaiting0)
data=binascii.b2a_hex(serread(n))
print(data.upper())
time.sleep(1)
Finally convert the hexadecimal format into string format for display, the code is as follows:
import binascii
n = serinWaiting0)
data=binascii.b2a_hex(serread(n))
data_str=data.decode('utf-8') #将16进制转换成字符串格式
print(data_str.upper()) #大写显示
time.sleep(1)
This is how to get Python to correctly display HEX messages sent by the serial assistant.
If the answer is helpful, please accept it.