tools/mpremote: Only auto connect to serial device with USB VID/PID.
On MacOS and Windows there are a few default serial devices that are returned by `serial.tools.list_ports.comports()`. For example on MacOS: ``` {'description': 'n/a', 'device': '/dev/cu.Bluetooth-Incoming-Port', 'hwid': 'n/a', 'interface': None, 'location': None, 'manufacturer': None, 'name': 'cu.Bluetooth-Incoming-Port', 'pid': None, 'product': None, 'serial_number': None, 'vid': None} {'description': 'n/a', 'device': '/dev/cu.wlan-debug', 'hwid': 'n/a', 'interface': None, 'location': None, 'manufacturer': None, 'name': 'cu.wlan-debug', 'pid': None, 'product': None, 'serial_number': None, 'vid': None} ``` Users of mpremote most likely do not want to connect to these ports. It would be desirable if mpremote did not select this ports when using the auto connect behavior. These serial ports do not have USB VID or PID values and serial ports for Micropython boards with FTDI/serial-to-USB adapter or native USB CDC/ACM support do. Check for the presence of a USB VID / PID int value when selecting a serial port to auto connect to. All serial ports will still be listed by the `list` command and can still be selected by name when connecting. Signed-off-by: Michael Mogenson <michael.mogenson@gmail.com>
This commit is contained in:
parent
3c1a2a942a
commit
921f397acb
@ -19,10 +19,10 @@ The simplest way to use this tool is just by invoking it without any arguments:
|
|||||||
|
|
||||||
mpremote
|
mpremote
|
||||||
|
|
||||||
This command automatically detects and connects to the first available serial
|
This command automatically detects and connects to the first available USB
|
||||||
device and provides an interactive REPL. Serial ports are opened in exclusive
|
serial device and provides an interactive REPL. Serial ports are opened in
|
||||||
mode, so running a second (or third, etc) instance of ``mpremote`` will connect
|
exclusive mode, so running a second (or third, etc) instance of ``mpremote``
|
||||||
to subsequent serial devices, if any are available.
|
will connect to subsequent serial devices, if any are available.
|
||||||
|
|
||||||
|
|
||||||
Commands
|
Commands
|
||||||
@ -52,7 +52,7 @@ The full list of supported commands are:
|
|||||||
``<device>`` may be one of:
|
``<device>`` may be one of:
|
||||||
|
|
||||||
- ``list``: list available devices
|
- ``list``: list available devices
|
||||||
- ``auto``: connect to the first available device
|
- ``auto``: connect to the first available USB serial port
|
||||||
- ``id:<serial>``: connect to the device with USB serial number
|
- ``id:<serial>``: connect to the device with USB serial number
|
||||||
``<serial>`` (the second entry in the output from the ``connect list``
|
``<serial>`` (the second entry in the output from the ``connect list``
|
||||||
command)
|
command)
|
||||||
@ -186,8 +186,8 @@ Auto connection and soft-reset
|
|||||||
|
|
||||||
Connection and disconnection will be done automatically at the start and end of
|
Connection and disconnection will be done automatically at the start and end of
|
||||||
the execution of the tool, if such commands are not explicitly given. Automatic
|
the execution of the tool, if such commands are not explicitly given. Automatic
|
||||||
connection will search for the first available serial device. If no action is
|
connection will search for the first available USB serial device. If no action
|
||||||
specified then the REPL will be entered.
|
is specified then the REPL will be entered.
|
||||||
|
|
||||||
Once connected to a device, ``mpremote`` will automatically soft-reset the
|
Once connected to a device, ``mpremote`` will automatically soft-reset the
|
||||||
device if needed. This clears the Python heap and restarts the interpreter,
|
device if needed. This clears the Python heap and restarts the interpreter,
|
||||||
|
@ -7,7 +7,7 @@ The simplest way to use this tool is:
|
|||||||
|
|
||||||
mpremote
|
mpremote
|
||||||
|
|
||||||
This will automatically connect to the device and provide an interactive REPL.
|
This will automatically connect to a USB serial port and provide an interactive REPL.
|
||||||
|
|
||||||
The full list of supported commands are:
|
The full list of supported commands are:
|
||||||
|
|
||||||
|
@ -32,14 +32,15 @@ def do_connect(state, args=None):
|
|||||||
# Don't do implicit REPL command.
|
# Don't do implicit REPL command.
|
||||||
state.did_action()
|
state.did_action()
|
||||||
elif dev == "auto":
|
elif dev == "auto":
|
||||||
# Auto-detect and auto-connect to the first available device.
|
# Auto-detect and auto-connect to the first available USB serial port.
|
||||||
for p in sorted(serial.tools.list_ports.comports()):
|
for p in sorted(serial.tools.list_ports.comports()):
|
||||||
try:
|
if p.vid is not None and p.pid is not None:
|
||||||
state.pyb = pyboard.PyboardExtended(p.device, baudrate=115200)
|
try:
|
||||||
return
|
state.pyb = pyboard.PyboardExtended(p.device, baudrate=115200)
|
||||||
except pyboard.PyboardError as er:
|
return
|
||||||
if not er.args[0].startswith("failed to access"):
|
except pyboard.PyboardError as er:
|
||||||
raise er
|
if not er.args[0].startswith("failed to access"):
|
||||||
|
raise er
|
||||||
raise pyboard.PyboardError("no device found")
|
raise pyboard.PyboardError("no device found")
|
||||||
elif dev.startswith("id:"):
|
elif dev.startswith("id:"):
|
||||||
# Search for a device with the given serial number.
|
# Search for a device with the given serial number.
|
||||||
|
Loading…
Reference in New Issue
Block a user