代码拉取完成,页面将自动刷新
from tkinter import *
import serial
import serial.tools.list_ports
import datetime
import _thread
class MainWINDOW():
def __init__(self,init_window_name):
self.init_window_name = init_window_name
self.init_window_name.title("双串口调试工具")
self.init_window_name.geometry('800x600')
self.s = Scrollbar(self.init_window_name)
self.text = Text(self.init_window_name, width=800, height=600)
self.s.pack(side=RIGHT,fill=Y)
self.text.pack(side=LEFT,fill=Y)
self.s.config(command=self.text.yview)
self.text.config(yscrollcommand=self.s.set)
self.openSerial()
def openSerial(self):
portlist = serial.tools.list_ports.comports()
for port in portlist:
print(port)
serial1name = input("serial1name: ")
serial2name = input("serial2name: ")
try:
self.serial1 = serial.Serial(serial1name, 115200)
finally:
print(serial1name, "Open Succeeded")
try:
self.serial2 = serial.Serial(serial2name, 115200)
finally:
print(serial2name, "Open Succeeded")
_thread.start_new_thread(self.readserial1, ())
_thread.start_new_thread(self.readserial2, ())
def readserial1(self):
while True:
if self.serial1.in_waiting:
self.text.insert(END, datetime.datetime.now().strftime('%H:%M:%S.%f')+" RX: "+self.serial1.readline().decode())
self.text.see(END)
# print(datetime.datetime.now().strftime('%H:%M:%S.%f'), "RX: ", serial1.readline())
# if self.serial2.in_waiting:
# self.text.insert(END, datetime.datetime.now().strftime('%H:%M:%S.%f')+" TX: "+self.serial2.readline().decode())
# self.text.see(END)
def readserial2(self):
while True:
if self.serial2.in_waiting:
self.text.insert(END, datetime.datetime.now().strftime(
'%H:%M:%S.%f') + " TX: " + self.serial2.readline().decode())
self.text.see(END)
def guiStart():
my_app = Tk()
main_window = MainWINDOW(my_app)
my_app.mainloop()
guiStart()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。