From 9e20ba5609cd69851b4626d4b467ee28e9aee380 Mon Sep 17 00:00:00 2001 From: Fischer Moseley <42497969+fischermoseley@users.noreply.github.com> Date: Wed, 16 Aug 2023 09:03:16 -0700 Subject: [PATCH] update ports command to handle macOS --- src/manta/__init__.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/manta/__init__.py b/src/manta/__init__.py index a018f52..2454252 100644 --- a/src/manta/__init__.py +++ b/src/manta/__init__.py @@ -324,11 +324,16 @@ Supported commands: # list available serial ports elif argv[1] == "ports": import serial.tools.list_ports - for port in serial.tools.list_ports.comports(): print(port) - print(' -> vid: 0x{:04X}'.format(port.vid)) - print(' -> pid: 0x{:04X}'.format(port.pid)) + + # sometimes macOS will enumerate non-serial devices as serial ports, + # in which case the PID/VID/serial/location/etc are all None + pid = "0x{port.vid:04X}" if port.pid is not None else "None" + vid = "0x{port.vid:04X}" if port.vid is not None else "None" + + print(f" -> pid: {pid}") + print(f" -> vid: {vid}") print(f" -> ser: {port.serial_number}") print(f" -> loc: {port.location}") print(f" -> mftr: {port.manufacturer}")