additional SCPI example for trace data reading
This commit is contained in:
parent
3176037c5d
commit
4a374e022d
@ -80,3 +80,20 @@ class libreVNA:
|
||||
self.sock.sendall(query.encode())
|
||||
self.sock.send(b"\n")
|
||||
return self.__read_response()
|
||||
|
||||
@staticmethod
|
||||
def parse_trace_data(data):
|
||||
ret = []
|
||||
# Remove brackets (order of data implicitly known)
|
||||
data = data.replace(']','').replace('[','')
|
||||
values = data.split(',')
|
||||
if int(len(values) / 3) * 3 != len(values):
|
||||
# number of values must be a multiple of three (frequency, real, imaginary)
|
||||
raise Exception("Invalid input data: expected tuples of three values each")
|
||||
for i in range(0, len(values), 3):
|
||||
freq = float(values[i])
|
||||
real = float(values[i+1])
|
||||
imag = float(values[i+2])
|
||||
ret.append((freq, complex(real, imag)))
|
||||
return ret
|
||||
|
||||
|
@ -0,0 +1,49 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import time
|
||||
from libreVNA import libreVNA
|
||||
|
||||
# Create the control instance
|
||||
vna = libreVNA('localhost', 19542)
|
||||
|
||||
# Quick connection check (should print "LibreVNA-GUI")
|
||||
print(vna.query("*IDN?"))
|
||||
|
||||
# Make sure we are connecting to a device (just to be sure, with default settings the LibreVNA-GUI auto-connects)
|
||||
vna.cmd(":DEV:CONN")
|
||||
dev = vna.query(":DEV:CONN?")
|
||||
if dev == "Not connected":
|
||||
print("Not connected to any device, aborting")
|
||||
exit(-1)
|
||||
else:
|
||||
print("Connected to "+dev)
|
||||
|
||||
# Simple trace data extraction
|
||||
|
||||
# switch to VNA mode, setup the sweep parameters
|
||||
print("Setting up the sweep...")
|
||||
vna.cmd(":DEV:MODE VNA")
|
||||
vna.cmd(":VNA:SWEEP FREQUENCY")
|
||||
vna.cmd(":VNA:STIM:LVL -10")
|
||||
vna.cmd(":VNA:ACQ:IFBW 100")
|
||||
vna.cmd(":VNA:ACQ:AVG 1")
|
||||
vna.cmd(":VNA:ACQ:POINTS 501")
|
||||
vna.cmd(":VNA:FREQuency:START 2000000000")
|
||||
vna.cmd(":VNA:FREQuency:STOP 3500000000")
|
||||
|
||||
# wait for the sweep to finish
|
||||
print("Waiting for the sweep to finish...")
|
||||
while vna.query(":VNA:ACQ:FIN?") == "FALSE":
|
||||
time.sleep(0.1)
|
||||
|
||||
# grab the data of trace S11
|
||||
print("Reading trace data...")
|
||||
data = vna.query(":VNA:TRACE:DATA? S11")
|
||||
|
||||
# Returned data is just a string containing all the measurement points.
|
||||
# Parsing the data returns a list containing frequency/complex tuples
|
||||
S11 = vna.parse_trace_data(data)
|
||||
|
||||
for x in S11:
|
||||
print(x)
|
||||
|
Loading…
Reference in New Issue
Block a user