4

我想在 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 <module>
    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'
4

1 回答 1

6

如果您使用的是 linux,则通常将串行端口命名为/dev/tty*;只需将端口号*替换为. 我使用通过 USB 串行通信的 arduino,它是.s/dev/ttyS1/dev/ttyUSB0

于 2011-08-20T00:21:57.053 回答