2010-10-29 66 views
3

我想和我的串口在python中進行通訊。我安裝了pyserial和uspp for linux。然而,當我運行下面的代碼:幫助.....串口編程

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' 

我該怎麼辦?

+3

當您請求打開/ dev/pts/1時,如何得到關於/ dev/tyUSB1的錯誤? – KevinDTimm 2010-10-29 15:28:48

+0

[python串行端口]的可能重複(http://stackoverflow.com/questions/4040151/python-serial-port) – Oded 2011-10-29 11:58:34

回答

7

/dev/tyUSB1看起來像一個錯字。設備節點通常稱爲/dev/ttyXXX

2

如果要打開第二個USB串行端口,則需要/dev/ttyUSB1而不是/dev/tyUSB1