Make sure ‘QTextCursor‘ is registered using qRegisterMetaType()

本文介绍了一个基于Python的串口通信数据实时读取与解析的程序实现。该程序能够连续从串口接收数据,并根据配置参数决定输出信息的格式,包括日期、时间、接收的数据等。同时,程序还统计了接收数据的位数并显示。
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
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值