【发布时间】:2012-12-29 18:38:36
【问题描述】:
我刚刚安装了 Pyserial 2.6 并且我有 Python 2.7.3 不幸的是它没有正确安装或者我没有正确使用它。我使用该行通过终端安装它
sudo easy_install pyserial
不幸的是,它给了我 2 个警告:
warning: no files found matching 'examples/miniterm.py'
warning: no files found matching 'test/test_io_lib.py'
除此之外,它似乎安装正确。
当我在 Python 中运行它时,我不断收到更远的错误
import serial
serial_input = serial.Serial('/dev/tty/.usbmodem3d241',9600)
while True:
ser.readline()
错误:
Traceback (most recent call last):
File "/Users/ben/Documents/Arduino_to_Python.py", line 5, in <module>
serial_input = serial.Serial('/dev/tty/.usbmodem3d241',9600)
File "build/bdist.macosx-10.7-intel/egg/serial/serialutil.py", line 261, in __init__
self.open()
File "build/bdist.macosx-10.7-intel/egg/serial/serialposix.py", line 278, in open
raise SerialException("could not open port %s: %s" % (self._port, msg))
SerialException: could not open port /dev/tty/.usbmodem3d241: [Errno 20] Not a directory: '/dev/tty/.usbmodem3d241'
无论我尝试什么串行端口,它似乎都无法正常工作。我已经尝试了 Arduino 程序 Tools>Serial Port 中的那些以及http://pyserial.sourceforge.net/shortintro.html#opening-serial-ports的所有提示
任何帮助将不胜感激。谢谢。
【问题讨论】:
-
您确定该路径确实存在吗?在 shell 中查看
/dev/tty。 -
dmesg | grep usbmodem是否提供有关设备路径的任何线索? -
我在 pyserial 网站上试过这个,但没有 avial。对路径应该是什么有任何想法? >>> ser = serial.Serial() >>> ser.baudrate = 19200 >>> ser.port = 0 >>> ser.open() Traceback(最近一次调用最后):文件“
” ,第 1 行,在 ser.open() 文件“build/bdist.macosx-10.7-intel/egg/serial/serialposix.py”,第 278 行,打开引发 SerialException(“无法打开端口 %s: %s" % (self._port, msg)) SerialException: could not open port 0: [Errno 2] No such file or directory: '/dev/cuad0' -
Martijn 我将它处理到 python shell 并得到一个语法错误?对 serial_input 行的正确路径有什么想法吗?
-
查看类似帖子 查看类似arduino.cc/forum/index.php/topic,39052.0.html 的帖子;您正在寻找 USB 事件来告诉您要打开的设备的正确名称。
标签: python serial-port arduino pyserial