mirror of
https://github.com/ttrftech/NanoVNA.git
synced 2025-12-06 03:31:59 +01:00
feat: find device automaticaly in python script (proposal #19 from Psynosaur)
This commit is contained in:
parent
0b885f2640
commit
e636b4298a
|
|
@ -5,6 +5,19 @@ import pylab as pl
|
||||||
import scipy.signal as signal
|
import scipy.signal as signal
|
||||||
import time
|
import time
|
||||||
import struct
|
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)
|
REF_LEVEL = (1<<9)
|
||||||
|
|
||||||
|
|
@ -353,7 +366,7 @@ if __name__ == '__main__':
|
||||||
help="capture current display to FILE", metavar="FILE")
|
help="capture current display to FILE", metavar="FILE")
|
||||||
(opt, args) = parser.parse_args()
|
(opt, args) = parser.parse_args()
|
||||||
|
|
||||||
nv = NanoVNA(opt.device or '/dev/cu.usbmodem401')
|
nv = NanoVNA(opt.device or getport())
|
||||||
|
|
||||||
if opt.capture:
|
if opt.capture:
|
||||||
print("capturing...")
|
print("capturing...")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue