我有一台Windows计算机,正在使用Pyserial通过多线程程序读写多个COM端口。
它在我的设置中有效。当我在另一台计算机上运行时,在UART流上未写入任何响应后,我会看到。
我使用mtrace功能在Linux中进行跟踪,它说返回None,这意味着什么也没读。
serialposix.py(483): ready, _, _ = select.select([self.fd, self.pipe_abort_read_r], [], [], timeout.time_left())
--- modulename: serialutil, funcname: time_left
serialutil.py(139): if self.is_non_blocking:
serialutil.py(141): elif self.is_infinite:
serialutil.py(142): return None
我通过缩短测试了回波rx和tx,发现引脚正确。
我只是在写和读之前添加了刷新输入和刷新输出。我检查了线程,也没有竞争状况。
想知道UART中的某些缓冲区没有正确刷新吗?
尽管写阻止了对安全方面的调用,但我为多线程添加了0.5秒的延迟。
我的序列号:
def serial_io():
device = serial.Serial(COM1, baudrate=115200, bytesize=8, parity='N', stopbits=1,
timeout=None, xonxoff=False, rtscts=False, dsrdtr=False)
#reseting the ouput buffer here
reset_output_buffer()
packet = bytearray()
packet.append(0x5A)
packet.append(0xA5)
packet.append(0x01)
packet.append(0x20)
packet.append(0x3D)
packet.append(0xFF)
packet.append(0x01)
packet.append(0x00)
packet.append(0xA1)
packet.append(0xFE)
device.write(packet)
time.sleep(0.5)
#resetting the input buffer here
reset_input_buffer()
run = True
while run:
data=device.readline()
print(data)
if (data == TEST_END):
print("TEST DONE")
run = False
device.close()