【发布时间】:2025-12-08 07:50:02
【问题描述】:
喂,
我正在通过串行端口写入一些数据,但我在读取该设备的响应时遇到问题。
例子:
ser.write('Hello World')
print(ser.readline()) #Instead of reading the response from the
#other device, it reads 'Hello world'
我已经为这个问题做了一个解决方法,调用了两次 readline(),而不关心第一个。以这种方式(工作)它读取从其他设备发送的数据
ser.write('Hello World')
ser.readline()
print(ser.readline())
对我来说,发送的数据似乎保留在缓冲区中?当调用 readline() 时它会先变红?!
谁能解释一下我做错了什么?
谢谢!
【问题讨论】:
-
LOL“仍在缓冲区中”。正是我遇到这个问题时的想法。
标签: python serial-port pyserial