From e636b4298ab32591c05b936afdf767a69b2936e1 Mon Sep 17 00:00:00 2001 From: TT Date: Sat, 28 Sep 2019 08:07:26 +0900 Subject: [PATCH] feat: find device automaticaly in python script (proposal #19 from Psynosaur) --- python/nanovna.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/python/nanovna.py b/python/nanovna.py index ba4a63f..8edda94 100755 --- a/python/nanovna.py +++ b/python/nanovna.py @@ -5,6 +5,19 @@ import pylab as pl import scipy.signal as signal import time import struct +import os +from serial.tools import list_ports + +VID = 0x0483 #1155 +PID = 0x5740 #22336 + +# Get nanovna device automatically +def getport() -> str: + device_list = list_ports.comports() + for device in device_list: + if device.vid == VID and device.pid == PID: + return device.device + raise OSError("device not found") REF_LEVEL = (1<<9) @@ -353,7 +366,7 @@ if __name__ == '__main__': help="capture current display to FILE", metavar="FILE") (opt, args) = parser.parse_args() - nv = NanoVNA(opt.device or '/dev/cu.usbmodem401') + nv = NanoVNA(opt.device or getport()) if opt.capture: print("capturing...")