From d2deb9a9b9e662181b405116575b258c170ddc29 Mon Sep 17 00:00:00 2001 From: Oleh Horbachov Date: Thu, 12 Jun 2025 10:32:27 +0300 Subject: [PATCH] add check - is usb port a link --- defs/common.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/defs/common.py b/defs/common.py index 7c5a82f..655eb8d 100644 --- a/defs/common.py +++ b/defs/common.py @@ -1,4 +1,5 @@ import re +import os import serial.tools.list_ports @@ -46,6 +47,11 @@ def strtoint(val : str) -> int: return int(val) def get_usb_serial_port_info(port : str = "") -> str: + + # If port is a symlink + if os.path.islink(port): + port = os.path.realpath(port) + for p in serial.tools.list_ports.comports(): if str(p.device).upper() == port.upper(): return "["+hex(p.vid)+":"+hex(p.pid)+":"+str(p.serial_number)+":"+str(p.location)+"]" @@ -53,6 +59,11 @@ def get_usb_serial_port_info(port : str = "") -> str: return "" def find_usb_serial_port(port : str = "", vendor_id : str = "", product_id : str = "", serial_number : str = "", location : str = "") -> str: + + # If port is a symlink + if os.path.islink(port): + port = os.path.realpath(port) + if not port.startswith("["): return port