diff --git a/bin/log.py b/bin/log.py index 1f52929..34b5e2f 100644 --- a/bin/log.py +++ b/bin/log.py @@ -5,6 +5,11 @@ import sys # 同一个进程中所有调用这个文件的 .py 文件都使用这个变量 _log_fp=None +STR_RED="\033[0;31m" +STR_BLUE="\033[0;34m" +STR_YELLOW="\033[0;33m" +STR_END="\033[0m" + def _time(): return '['+time.strftime("%Y-%m-%d %H:%M:%S")+']' @@ -30,7 +35,7 @@ def mywrite(data:str): txt=txt.replace('\n\n','\n') _log_fp.write(txt) _log_fp.flush() - sys.stdout.write(data) + sys.stdout.write(f"{STR_YELLOW}{data}{STR_END}") sys.stdout.flush() def log_init(file_name:str): diff --git a/kunlun.py b/kunlun.py index fb85071..96b19e1 100644 --- a/kunlun.py +++ b/kunlun.py @@ -119,13 +119,12 @@ def download_callback(total_packets, success_count, error_count): # 打印串口收到的字符 def print_device_str(data:bytearray): - data:list[bytearray]=data.split(b"\r\n") - for item in data: - try: - d=item.decode('utf-8') - myprint("DEVICE:",d.strip()) - except Exception as e: - myprint("DEVICE:",item) + data=data.replace(b"\r\n",b"\n") + try: + d=data.decode('utf-8') + mywrite(d) + except Exception as e: + mywrite(f"{data}\n")