串口消息通过颜色区分
This commit is contained in:
@@ -5,6 +5,11 @@ import sys
|
|||||||
# 同一个进程中所有调用这个文件的 .py 文件都使用这个变量
|
# 同一个进程中所有调用这个文件的 .py 文件都使用这个变量
|
||||||
_log_fp=None
|
_log_fp=None
|
||||||
|
|
||||||
|
STR_RED="\033[0;31m"
|
||||||
|
STR_BLUE="\033[0;34m"
|
||||||
|
STR_YELLOW="\033[0;33m"
|
||||||
|
STR_END="\033[0m"
|
||||||
|
|
||||||
def _time():
|
def _time():
|
||||||
return '['+time.strftime("%Y-%m-%d %H:%M:%S")+']'
|
return '['+time.strftime("%Y-%m-%d %H:%M:%S")+']'
|
||||||
|
|
||||||
@@ -30,7 +35,7 @@ def mywrite(data:str):
|
|||||||
txt=txt.replace('\n\n','\n')
|
txt=txt.replace('\n\n','\n')
|
||||||
_log_fp.write(txt)
|
_log_fp.write(txt)
|
||||||
_log_fp.flush()
|
_log_fp.flush()
|
||||||
sys.stdout.write(data)
|
sys.stdout.write(f"{STR_YELLOW}{data}{STR_END}")
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
||||||
def log_init(file_name:str):
|
def log_init(file_name:str):
|
||||||
|
@@ -119,13 +119,12 @@ def download_callback(total_packets, success_count, error_count):
|
|||||||
|
|
||||||
# 打印串口收到的字符
|
# 打印串口收到的字符
|
||||||
def print_device_str(data:bytearray):
|
def print_device_str(data:bytearray):
|
||||||
data:list[bytearray]=data.split(b"\r\n")
|
data=data.replace(b"\r\n",b"\n")
|
||||||
for item in data:
|
|
||||||
try:
|
try:
|
||||||
d=item.decode('utf-8')
|
d=data.decode('utf-8')
|
||||||
myprint("DEVICE:",d.strip())
|
mywrite(d)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
myprint("DEVICE:",item)
|
mywrite(f"{data}\n")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user