无法通过催眠端口打开串行端口

发布于 2025-02-13 02:44:35 字数 1181 浏览 0 评论 0原文


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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文