无法通过催眠端口打开串行端口
I'm trying to read strings from a USB/Serial barcode scanner from a python script in Linux environment.
The device is named /dev/ttyUSB0 by the O.S.
I can read the "special file" from the shell. This command echoes every barcode I scan:
cat < /dev/ttyUSB0
当我尝试使用Pyserial在Python中打开串行设备时,就会发生问题。当我尝试时,我会发现一个错误。我想某些东西使串行端口初始化失败:
nando@nando-VirtualBox:~$ python3
Python 3.5.2 (default, Jan 26 2021, 13:30:48)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import serial
>>> serial.Serial('/dev/ttyUSB0')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3/dist-packages/serial/serialutil.py", line 180, in __init__
self.open()
File "/usr/lib/python3/dist-packages/serial/serialposix.py", line 313, in open
self._update_rts_state()
File "/usr/lib/python3/dist-packages/serial/serialposix.py", line 598, in _update_rts_state
fcntl.ioctl(self.fd, TIOCMBIS, TIOCM_RTS_str)
BrokenPipeError: [Errno 32] Broken pipe
我使用Python 2.7和Python 3.5遇到相同的错误。
有什么想法吗?
I'm trying to read strings from a USB/Serial barcode scanner from a python script in Linux environment.
The device is named /dev/ttyUSB0 by the O.S.
I can read the "special file" from the shell. This command echoes every barcode I scan:
cat < /dev/ttyUSB0
The problem occurs when I try to open the serial device in python using pyserial. When I try it, I get an error. I suppose something fails initializing the serial port:
nando@nando-VirtualBox:~$ python3
Python 3.5.2 (default, Jan 26 2021, 13:30:48)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import serial
>>> serial.Serial('/dev/ttyUSB0')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3/dist-packages/serial/serialutil.py", line 180, in __init__
self.open()
File "/usr/lib/python3/dist-packages/serial/serialposix.py", line 313, in open
self._update_rts_state()
File "/usr/lib/python3/dist-packages/serial/serialposix.py", line 598, in _update_rts_state
fcntl.ioctl(self.fd, TIOCMBIS, TIOCM_RTS_str)
BrokenPipeError: [Errno 32] Broken pipe
I get the same error using python 2.7 and python 3.5.
Any idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论