解决串口部分字符乱码导致全部打印异常的问题
This commit is contained in:
10
kunlun.py
10
kunlun.py
@@ -120,9 +120,17 @@ def download_callback(total_packets, success_count, error_count):
|
|||||||
# 打印串口收到的字符
|
# 打印串口收到的字符
|
||||||
def print_device_str(data:bytearray):
|
def print_device_str(data:bytearray):
|
||||||
data=data.replace(b"\r\n",b"\n")
|
data=data.replace(b"\r\n",b"\n")
|
||||||
|
index=0
|
||||||
|
while index<len(data):
|
||||||
|
if(bytes([data[index]]).isascii()):
|
||||||
|
index+=1
|
||||||
|
else:
|
||||||
|
break
|
||||||
try:
|
try:
|
||||||
d=data.decode('utf-8')
|
d=data[:index].decode('utf-8')
|
||||||
mywrite(d)
|
mywrite(d)
|
||||||
|
if(index<len(data)):
|
||||||
|
mywrite(f"{data[index:]}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
mywrite(f"{data}\n")
|
mywrite(f"{data}\n")
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user