feat(HDMI-Tool): 光机串口下拉显示设备描述, CH344 多路口可辨

This commit is contained in:
2026-09-11 00:46:03 +08:00
parent 22d0969569
commit 1a9927d9bb
5 changed files with 60 additions and 16 deletions
+23 -3
View File
@@ -168,11 +168,31 @@ class DLPC485:
threading.Thread(target=self._run, daemon=True).start()
@staticmethod
def list_ports():
"""枚举本机串口名(未装 pyserial 返回空表)"""
def list_ports_info():
"""枚举串口, 返回 [(设备名, 显示标签), ...]。
标签 = "COMx 设备描述"(描述里的 "(COMx)" 尾巴去掉, COM 号已在最前),
CH344 这类多路适配器的每一路描述不同(如 serial-A/B/C/D), 依此区分;
多口描述完全相同(同型号多口)时追加物理位置/序列号消歧。
"""
if not HAS_SERIAL:
return []
return [p.device for p in serial.tools.list_ports.comports()]
items = []
for p in serial.tools.list_ports.comports():
desc = re.sub(r'\s*\((COM\d+)\)\s*$', '', (p.description or '').strip(),
flags=re.I)
if desc.upper() == p.device.upper():
desc = ''
label = f'{p.device} {desc}'.rstrip()
tail = p.location or p.serial_number or ''
items.append((p.device, label, tail))
counts = collections.Counter(label for _d, label, _t in items)
out = []
for dev, label, tail in items:
if counts[label] > 1 and tail: # 同标签多口: 附物理位置消歧
label = f'{label} [{tail}]'
out.append((dev, label))
return out
def open(self, port, baud=DEFAULT_BAUD):
if not HAS_SERIAL: