求助......串口编程
我想用 python 与我的串口进行通信。我为linux安装了pyserial和uspp。尽管如此,当我运行以下代码时:
import serial
ser = serial.Serial('/dev/pts/1', 19200, timeout=1)
print ser.portstr #check which port was really used
ser.write("hello") #write a string
ser.close() #
它给出了以下错误:
Traceback (most recent call last):
File "poi.py", line 5, in ser.open()
File "/usr/local/lib/python2.6/dist-packages/pyserial-2.5-py2.6.egg/serial/serialposix.py",
line 276,
in open raise SerialException("could not open port %s: %s" % (self._port, msg)) serial.serialutil.SerialException:
could not open port /dev/tyUSB1: [Errno 2] No such file or directory: '/dev/tyUSB1'
我应该做什么?
I want to communicate with my serial port in python. I installed pyserial, and uspp for linux. Still, when I run the following code:
import serial
ser = serial.Serial('/dev/pts/1', 19200, timeout=1)
print ser.portstr #check which port was really used
ser.write("hello") #write a string
ser.close() #
it gives the following error:
Traceback (most recent call last):
File "poi.py", line 5, in ser.open()
File "/usr/local/lib/python2.6/dist-packages/pyserial-2.5-py2.6.egg/serial/serialposix.py",
line 276,
in open raise SerialException("could not open port %s: %s" % (self._port, msg)) serial.serialutil.SerialException:
could not open port /dev/tyUSB1: [Errno 2] No such file or directory: '/dev/tyUSB1'
What should I do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
/dev/tyUSB1
看起来像是一个拼写错误。设备节点通常称为/dev/ttyXXX
/dev/tyUSB1
looks like a typo. Device nodes are normally called/dev/ttyXXX
如果您想打开第二个 USB 串行端口,则需要
/dev/ttyUSB1
而不是/dev/tyUSB1
。If you want to open your second USB serial port, you want
/dev/ttyUSB1
instead of/dev/tyUSB1
.