From fd9f86a182c40db31dc8a5611efd4fe6733af67a Mon Sep 17 00:00:00 2001 From: Joey Yakimowich-Payne Date: Fri, 21 Nov 2025 15:49:39 -0700 Subject: [PATCH] Add filtering --- controller_uart_bridge.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/controller_uart_bridge.py b/controller_uart_bridge.py index 84152e7..c50486d 100644 --- a/controller_uart_bridge.py +++ b/controller_uart_bridge.py @@ -153,13 +153,24 @@ def is_usb_serial(path: str) -> bool: return True +def is_usb_serial_port(port: list_ports.ListPortInfo) -> bool: + """Heuristic: prefer ports with USB VID/PID; fall back to path hints.""" + if getattr(port, "vid", None) is not None or getattr(port, "pid", None) is not None: + return True + path = port.device or "" + manufacturer = (getattr(port, "manufacturer", "") or "").upper() + if "USB" in manufacturer: + return True + return is_usb_serial(path) + + def discover_ports(include_non_usb: bool = False) -> List[Dict[str, str]]: results: List[Dict[str, str]] = [] for port in list_ports.comports(): path = port.device or "" if not path: continue - if not include_non_usb and not is_usb_serial(path): + if not include_non_usb and not is_usb_serial_port(port): continue results.append( {