kopia lustrzana https://github.com/NanoVNA-Saver/nanovna-saver
Show VNA type in port selector
rodzic
aca61a6e04
commit
b86ddb95aa
|
@ -49,6 +49,18 @@ RETRIES = 3
|
|||
TIMEOUT = 0.2
|
||||
WAIT = 0.05
|
||||
|
||||
NAME2DEVICE = {
|
||||
"S-A-A-2" : NanoVNA_V2,
|
||||
"AVNA": AVNA,
|
||||
"H4": NanoVNA_H4,
|
||||
"H": NanoVNA_H,
|
||||
"F_V2": NanoVNA_F_V2,
|
||||
"F": NanoVNA_F,
|
||||
"NanoVNA": NanoVNA,
|
||||
"tinySA": TinySA,
|
||||
"Unknown": NanoVNA,
|
||||
}
|
||||
|
||||
# The USB Driver for NanoVNA V2 seems to deliver an
|
||||
# incompatible hardware info like:
|
||||
# 'PORTS\\VID_04B4&PID_0008\\DEMO'
|
||||
|
@ -75,50 +87,42 @@ def get_interfaces() -> List[Interface]:
|
|||
t.name, d.vid, d.pid, d.device)
|
||||
iface = Interface('serial', t.name)
|
||||
iface.port = d.device
|
||||
iface.open()
|
||||
iface.comment = get_comment(iface)
|
||||
iface.close()
|
||||
interfaces.append(iface)
|
||||
|
||||
logger.debug("Interfaces: %s", interfaces)
|
||||
return interfaces
|
||||
|
||||
|
||||
def get_VNA(iface: Interface) -> 'VNA':
|
||||
# serial_port.timeout = TIMEOUT
|
||||
return NAME2DEVICE[iface.comment](iface)
|
||||
|
||||
def get_comment(iface: Interface) -> str:
|
||||
logger.info("Finding correct VNA type...")
|
||||
with iface.lock:
|
||||
vna_version = detect_version(iface)
|
||||
|
||||
if vna_version == 'v2':
|
||||
logger.info("Type: NanoVNA-V2")
|
||||
return NanoVNA_V2(iface)
|
||||
return "S-A-A-2"
|
||||
|
||||
logger.info("Finding firmware variant...")
|
||||
info = get_info(iface)
|
||||
if info.find("AVNA + Teensy") >= 0:
|
||||
logger.info("Type: AVNA")
|
||||
return AVNA(iface)
|
||||
if info.find("NanoVNA-H 4") >= 0:
|
||||
logger.info("Type: NanoVNA-H4")
|
||||
vna = NanoVNA_H4(iface)
|
||||
return vna
|
||||
if info.find("NanoVNA-H") >= 0:
|
||||
logger.info("Type: NanoVNA-H")
|
||||
vna = NanoVNA_H(iface)
|
||||
return vna
|
||||
if info.find("NanoVNA-F_V2") >= 0:
|
||||
logger.info("Type: NanoVNA-F_V2")
|
||||
return NanoVNA_F_V2(iface)
|
||||
if info.find("NanoVNA-F") >= 0:
|
||||
logger.info("Type: NanoVNA-F")
|
||||
return NanoVNA_F(iface)
|
||||
if info.find("NanoVNA") >= 0:
|
||||
logger.info("Type: Generic NanoVNA")
|
||||
return NanoVNA(iface)
|
||||
if info.find("tinySA") >= 0:
|
||||
logger.info("Type: tinySA Spectrum Analyser")
|
||||
return TinySA(iface)
|
||||
for search, name in (
|
||||
("AVNA + Teensy", "AVNA"),
|
||||
("NanoVNA-H 4", "H4"),
|
||||
("NanoVNA-H", "H"),
|
||||
("NanoVNA-F_V2", "F_V2"),
|
||||
("NanoVNA-F", "F"),
|
||||
("NanoVNA", "NanoVNA"),
|
||||
("tinySA", "tinySA"),
|
||||
):
|
||||
if info.find(search) >= 0:
|
||||
return name
|
||||
logger.warning("Did not recognize NanoVNA type from firmware.")
|
||||
return NanoVNA(iface)
|
||||
|
||||
return "Unknown"
|
||||
|
||||
def detect_version(serial_port: serial.Serial) -> str:
|
||||
data = ""
|
||||
|
|
Ładowanie…
Reference in New Issue