串行端口数据发送在接收端被分离

2024-10-03 04:33:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我从串口发送数据

1H|\^&|||c111^Roche^c111^2.0.0.0710^1^3334
44|||||host|TSREQ^REAL|

到串口,在接收端字符串被拆分为

1H|\^

以及

&|||c111^Roche^c111^2.0.0.0710^1^3334
    44|||||host|TSREQ^REAL|

为什么会这样,我想把它作为一个单一的字符串发送。你知道吗

这是我的密码

 import serial
    import requests

    ser = serial.Serial(port='COM1',baudrate=9600,parity=serial.PARITY_NONE,stopbits=serial.STOPBITS_ONE,bytesize=serial.EIGHTBITS,timeout=0.5)
    concat = str()
    concat01=str()
    header = "b'\x021H|\^&||||||||||P||'\r\n"
    sample = "b'\x023Q|1|^0101645900^10^0^4^^SAMPLE^NORMAL||ALL||||||||O'\r\n"
    eol="b'\x024L|1|I'\r\n"
    patient_info = "b'\x022P|1'\r\n"

    while 1:
        z=ser.readline()
        print(z)
        print("Str Result",str(z))
        if str(z)!="b''":
            if str(z) == str(b'\x06'):
                print("verfied 06")
                concat = header + patient_info + sample + eol
                ser.write(concat.encode())

Tags: sample字符串importhostserialrealserheader