def read_com():
global ser,set_ser,text_read
bit_count1 = int()
while True:
day1 = datetime.datetime.today()
n = day1.year
y = day1.month
r = day1.day
h = day1.hour
m = day1.minute
s = day1.second
ms = day1.microsecond
# print(day1)
# print(n, y, r)
# print(h, m, s, ms)
day2 = str(n) + "-" + str(y) + "-" + str(r)
st = str(h) + ":" + str(m) + ":" + str(s) + "(" + str(ms) + ")"
# print(day2)
# print(st)
com_input = str()
com_input = ser.readall().decode('utf-8')
#print(com_input)
# com_input = str(com_input.replace(" ",""))
# com_input = com_input.strip("\n")
# com_input = com_input.replace("LF","")
if com_input: # 如果读取结果非空,则输出
# print(com_input)
# if chk_6 == 2:
# text = " " + "Send" + " " + str(com_input)
# else:
if chk_3 == 2 and chk_4 == 2 and chk_5 == 2:
text = str(day2) + " " + str(st) + " " + "Read" +" " +str(com_input)
elif chk_3 == 2 and chk_4 == 2 and chk_5 == 0:
text = str(st) + " " + "Read" +" " +str(com_input)
elif chk_3 == 2 and chk_4 == 0 and chk_5 == 2: # chk3 内容,chk4 时间,chk5日期
text = str(day2) + " " + "Read" +" " + str(com_input)
elif chk_3 == 0 and chk_4 == 2 and chk_5 == 2:
text = str(day2) + " " + str(st)
elif chk_3 == 0 and chk_4 == 0 and chk_5 == 2: # chk3 内容,chk4 时间,chk5日期
text = str(day2)
elif chk_3 == 0 and chk_4 == 2 and chk_5 == 0: # chk3 内容,chk4 时间,chk5日期
text = str(st)
elif chk_3 == 2 and chk_4 == 0 and chk_5 == 0: # chk3 内容,chk4 时间,chk5日期
text = " " + "Read" +" " +str(com_input)
text_read = text
myWin.textEdit.append(text)
bit_count = len(com_input)
bit_count1 = bit_count1 + bit_count
bit_count2 = str(bit_count1)
myWin.lineEdit_13.setText(bit_count2)
print(text)
continue
Make sure ‘QTextCursor‘ is registered using qRegisterMetaType()
最新推荐文章于 2024-10-19 11:02:56 发布
本文介绍了一个基于Python的串口通信数据实时读取与解析的程序实现。该程序能够连续从串口接收数据,并根据配置参数决定输出信息的格式,包括日期、时间、接收的数据等。同时,程序还统计了接收数据的位数并显示。

4222

被折叠的 条评论
为什么被折叠?



