Skip to content

Commit eccb024

Browse files
authored
Merge pull request #90 from gorbyo/issue-serial-symlink
check is usb port a link
2 parents f2d6d83 + d2deb9a commit eccb024

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

defs/common.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import re
2+
import os
23

34
import serial.tools.list_ports
45

@@ -46,13 +47,23 @@ def strtoint(val : str) -> int:
4647
return int(val)
4748

4849
def get_usb_serial_port_info(port : str = "") -> str:
50+
51+
# If port is a symlink
52+
if os.path.islink(port):
53+
port = os.path.realpath(port)
54+
4955
for p in serial.tools.list_ports.comports():
5056
if str(p.device).upper() == port.upper():
5157
return "["+hex(p.vid)+":"+hex(p.pid)+":"+str(p.serial_number)+":"+str(p.location)+"]"
5258

5359
return ""
5460

5561
def find_usb_serial_port(port : str = "", vendor_id : str = "", product_id : str = "", serial_number : str = "", location : str = "") -> str:
62+
63+
# If port is a symlink
64+
if os.path.islink(port):
65+
port = os.path.realpath(port)
66+
5667
if not port.startswith("["):
5768
return port
5869

0 commit comments

Comments
 (0)