我的串口有一个奇怪的问题。ubuntu实现并重新启动后,似乎某事已更改。
przem@przem:~/Pulpit/bat/scripts$ python
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import serial
>>> ser = serial.Serial("/dev/ttyUSB0", 57600)
>>> ser.read()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/serial/serialposix.py", line 475, in read
raise SerialException('device reports readiness to read but returned no data (device disconnected or multiple access on port?)')
serial.serialutil.SerialException: device reports readiness to read but returned no data (device disconnected or multiple access on port?)
>>>
我知道我应该从设备中获得“”(空符号)结果,但取而代之的是异常:
“设备报告已准备好读取但未返回任何数据(设备已断开连接或端口上的多路访问?)”
这个问题是我的问题的简介:https : //stackoverflow.com/questions/32844942/serialport-doenst-work-correctly-after-ubuntu-update?noredirect=1#comment53527004_32844942
请帮我。
我遇到同样的问题。它似乎不限于串行端口硬件。您可以使用socat创建两个伪终端:
$ socat -d -d pty,raw,echo=0 pty,raw,echo=0
2015/09/30 09:46:18 socat[6296] N PTY is /dev/pts/17
2015/09/30 09:46:18 socat[6296] N PTY is /dev/pts/18
2015/09/30 09:46:18 socat[6296] N starting data transfer loop with FDs [3,3] and [5,5]
您可以连接两个设备,例如使用cu
cu -l /dev/pts/17 -s 115200
和
cu -l /dev/pts/18 -s 115200
并双向发送数据,没问题。
但是与Python 2.7的连接失败并显示您提到的错误消息
$ python
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import serial
>>> ser = serial.Serial("/dev/pts/17", 230400, timeout=0.2)
>>> ser.read()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 460, in read
raise SerialException('device reports readiness to read but returned no data (device disconnected?)')
serial.serialutil.SerialException: device reports readiness to read but returned no data (device disconnected?)
该代码在昨天为Ubuntu 14.04安装更新之前有效。
有任何想法吗?
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句