123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- import logging
- import platform
- from collections import namedtuple
- from time import sleep
- from typing import List
- import serial
- from serial.tools import list_ports
- from .Serial import drain_serial, Interface
- logger = logging.getLogger(__name__)
- USBDevice = namedtuple("Device", "vid pid name")
- USBDEVICETYPES = (
- USBDevice(0x0483, 0x5740, "NanoVNA"),
- USBDevice(0x16c0, 0x0483, "AVNA"),
- USBDevice(0x04b4, 0x0008, "S-A-A-2"),
- )
- RETRIES = 3
- TIMEOUT = 0.2
- WAIT = 0.05
- def _fix_v2_hwinfo(dev):
- if dev.hwid == r'PORTS\VID_04B4&PID_0008\DEMO':
- dev.vid, dev.pid = 0x04b4, 0x0008
- return dev
- def get_interfaces() -> List[Interface]:
- interfaces = []
-
- for d in list_ports.comports():
- if platform.system() == 'Windows' and d.vid is None:
- d = _fix_v2_hwinfo(d)
- for t in USBDEVICETYPES:
- if d.vid != t.vid or d.pid != t.pid:
- continue
- logger.debug("Found %s USB:(%04x:%04x) on port %s",
- t.name, d.vid, d.pid, d.device)
- iface = Interface('serial', t.name)
- iface.port = d.device
- interfaces.append(iface)
- return interfaces
|