python 串行库不断读取传入数据 serial.read() func 的问题

问题描述 投票:0回答:0

我无法在使用 serial.write() 发送的代码语句的返回中接收传入数据。我上面指定的代码片段适用于单个字节。我正在分享 wireshark 包示例。 enter image description here 仅当传入数据的大小大于 1 且连续时,它才会空闲。(示例 Rx 数据:2d30302d30302c30303a303029283030) enter image description here 空闲状态:enter image description here 注意:即使我更改阅读大小 (Rs485.read(1/2/...15)),也没有变化。

def readPort():
    ser.flushInput()
    readBuffer  = ''
    readBytes = ''
    while ('' == readBuffer):
        readBuffer = ser.read(1)            # poll for 1st received byte
        time.sleep(0.025)               # polling sample time (25ms)
    while (readBuffer.isspace() != True):
        readBytes +=  str(readBuffer.decode())      # build received message
        readBuffer = ser.read(1)            # read 1 byte at a time

    return readBytes

respBuf = readPort()
**print(respBuf) ///Nothing....**

我希望在我通过 USB 读取的部分读取数据的每个字节 (ser.read(1.2..3.15))。但我看到它在循环。

python pyserial usbserial
© www.soinside.com 2019 - 2024. All rights reserved.