蟒蛇串口

发布于 2024-09-29 06:37:03 字数 720 浏览 0 评论 0原文

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

I want to communicate with my serial port in python. I installed pyserial and 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()             #

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'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

望笑 2024-10-06 06:37:03

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文