Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions defs/common.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import re
import os

import serial.tools.list_ports

Expand Down Expand Up @@ -46,13 +47,23 @@ 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)+"]"

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

Expand Down