Linux 蟒蛇串口
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4040151/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
python serial port
提问by user489712
I want to communicate with my serial port in python. I installed pyserial and uspp for linux:
我想在 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() #
It gives the following error:
它给出了以下错误:
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'
回答by Gille Bates
if you are working with linux, generally, serial ports are named /dev/tty*
; just replace the *
with s
and the number of the port like /dev/ttyS1
. I work with a arduino that communicates via usb-serial, and it's /dev/ttyUSB0
.
如果您使用的是 linux,通常会命名串行端口/dev/tty*
;只需将*
withs
和端口号替换为/dev/ttyS1
。我使用通过 USB 串行通信的 arduino,它是/dev/ttyUSB0
.