我无法在使用 serial.write() 发送的代码语句的返回中接收传入数据。我上面指定的代码片段适用于单个字节。我正在分享 wireshark 包示例。 仅当传入数据的大小大于 1 且连续时,它才会空闲。(示例 Rx 数据:2d30302d30302c30303a303029283030) 空闲状态: 注意:即使我更改阅读大小 (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))。但我看到它在循环。