2010-10-28 127 views
4

我想與我的串口在python中進行通信。我安裝了用於Linux pyserial和USPP:python串行端口

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

[help ..... serial port programming]可能重複(http://stackoverflow.com/questions/4051869/help-serial-port-programming) – 2010-10-29 16:47:44

回答

6

如果你正在使用Linux,通常,串行端口被命名爲/dev/tty*;只需將*替換爲s以及端口號碼/dev/ttyS1即可。我使用通過usb-serial進行通信的arduino,它是/dev/ttyUSB0