python串口

时间:2010-10-28 05:48:39

标签: python linux pyserial

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

1 个答案:

答案 0 :(得分:6)

如果你正在使用linux,通常,串口被命名为/dev/tty*;只需将*替换为s,将/dev/ttyS1替换为端口号。我使用通过usb-serial进行通信的arduino,它是/dev/ttyUSB0