如何在macOS中为pySerial确定Arduino的端口号 [英] How to determine port number of Arduino for pySerial in macOS

查看:124
本文介绍了如何在macOS中为pySerial确定Arduino的端口号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我要在Python中使用它,我想知道如何确定连接到我的macbook的Arduino nano的端口号.

I would like to know how to determine the port number of the Arduino nano that is connected to my macbook if I will use it in Python.

工具> Arduino IDE中的端口

Tools>Port in Arduino IDE

/dev/cu.usbserial-A900afrI

我的.py文件中有此代码

I have this code in my .py file

import serial

a = serial.Serial('A900afrI', baudrate=9600, timeout=1)

我想知道应该用哪个端口替换"A9000afrI",因为出现这样的错误:

I want to know what port should I replace 'A9000afrI' with because I get an error which is this:

Traceback (most recent call last):
  File "/Users/cievlh/Desktop/Python/python_env/lib/python3.7/site-packages/serial/serialposix.py", line 265, in open
    self.fd = os.open(self.portstr, os.O_RDWR | os.O_NOCTTY | os.O_NONBLOCK)
FileNotFoundError: [Errno 2] No such file or directory: 'A900afrI'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "pyserial.py", line 3, in <module>
    a = serial.Serial('A900afrI', baudrate=9600, timeout=1)
  File "/Users/cievlh/Desktop/Python/python_env/lib/python3.7/site-packages/serial/serialutil.py", line 240, in __init__
    self.open()
  File "/Users/cievlh/Desktop/Python/python_env/lib/python3.7/site-packages/serial/serialposix.py", line 268, in open
    raise SerialException(msg.errno, "could not open port {}: {}".format(self._port, msg))
serial.serialutil.SerialException: [Errno 2] could not open port A900afrI: [Errno 2] No such file or directory: 'A900afrI'
(python_env)

推荐答案

知道了,只是根据gre_gor包括了整个字符串.

Got it, just included the whole string according to gre_gor.

import serial

a = serial.Serial('/dev/cu.usbserial-A900afrI', baudrate=9600, timeout=1)

这篇关于如何在macOS中为pySerial确定Arduino的端口号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆