我从一段时间以来一直使用BeagleBones Black Rev C,我使用了很多UART接口(RS-232和RS-485),前段时间我开始使用pyserial模块3.4,我注意到了超时行为的一些差异。
所以在模块2.7中,当我打开一个端口(ser = serial.Serial(port,baudrate,...,timeout))时,我通常设置timeout = 1,如果端口没有一秒钟没有收到任何东西,函数ser.read()关闭。
在模块3.4中,如果超时= 1,即使端口正在接收数据,函数ser.read(x)也会在接收所有数据之前关闭。 有一个例子,我要求输入我想要的超时,以及我选择的每个超时所收到的字节,另一方面我发送总共240048字节,125000波特率。
timeout.py ...
baudrate_0 = 115200
parity_0 = 'N'
stopbits_0 = 1
timeout = input( ' Timeout? \n')
timeout_0 = timeout
uart = serial.Serial(port="/dev/ttyO1",baudrate=baudrate_0, parity=parity_0, stopbits=stopbits_0, timeout = timeout_0)
....
data = uart.read(240048)
print 'bytes read:', len(data)
输出:
root@beaglebone:# python timeout.py
Timeout?
1
bytes read: 11232
root@beaglebone:# python timeout.py
Timeout?
2
bytes read: 22656
root@beaglebone:# python timeout.py
Timeout?
10
bytes read: 113904
root@beaglebone:# python timeout.py
Timeout?
25
bytes read: 240048
所以问题是:我可以将超时行为更改为与之前相同的行为(模块2.7)