import pyvisa as visa
#
Change this variable to the address of your instrument
VISA_ADDRESS
= 'TCPIP0::localhost::inst0::INSTR'
#
Create a connection (session) to the instrument
resourceManager
= visa.ResourceManager()
session = resourceManager.open_resource(VISA_ADDRESS)
#
Command to preset the instrument and deletes the default trace,
measurement, and window
session.write("SYST:FPR")
#
Create and turn on window 1
session.write("DISP:WIND1:STAT
ON")
#
======================== Getting data ========================
#
Select the measurement
session.write("CALC1:MEAS1:DEF
'S21'")
#
Take a sweep
session.write("SENS1:SWE:MODE
SING")
session.query("*OPC?")
#
Data format suited for large amounts of measurement data (dB)
session.write("FORM:DATA
REAL,32")
#
Tells the instrument to use the native endian type when sending
binary data
session.write("FORM:BORD
SWAP")
#
Ask for the data from the sweep, pick one of the locations to
read
myMeas
= session.query_binary_values('CALC1:MEAS1:DATA:FDATA?',
datatype='f') # Formatted
Meas
# myMeas =
session.query_binary_values("CALC:MEAS1:DATA:SDATA?",
datatype='f') # Corrected, Complex Meas
# session.write("CALC:MEAS:MATH:MEM")
#
Stores a trace into memory, required if querying with FMEM or
SMEM
#
myMeas = session.query_binary_values("CALC:MEAS1:DATA:FMEM?",
datatype='f') # Formatted Memory
#
myMeas = session.query_binary_values("CALC:MEAS1:DATA:SMEM?",
datatype='f') # Corrected, Complex
Memory
# myMeas
= session.query_binary_values("SENS1:CORR:CSET:ETER:DATA?
'Directivity(1,1)'", datatype='f') #
Error-Term Directivity
print(myMeas)
#
Data format suited for accurate transfer of frequency data (Frequency)
session.write("FORM:DATA
REAL,64")
myFreq
= session.query_binary_values('CALC1:MEAS1:X?',
datatype='d')
#
======================== Putting data ========================
#
Preset the instrument and deletes existing traces, measurements,
and windows
#
Creates a S11 measurement named "CH1_S11_1"
session.write("SYST:PRES")
#
Must set data format and swap again after system preset
#
Data format suited for large amounts of measurement data (dB)
session.write("FORM:DATA
REAL,32")
#
Tells the instrument to use the native endian type when sending
binary data
session.write("FORM:BORD
SWAP")
session.write_binary_values("CALC1:MEAS1:DATA:FDATA
",myMeas) # Formatted Meas
# session.write_binary_values("CALC:MEAS1:DATA:FMEM
",myMeas) # Formatted Memory
# session.write_binary_values("CALC:MEAS1:DATA:SDATA
",myMeas) # Corrected, Complex Meas
# session.write_binary_values("CALC:MEAS1:DATA:SMEM
",myMeas) # Corrected, Complex
Memory
# session.write_binary_values("SENS1:CORR:CSET:ETER:DATA
'Directivity(1,1)',", myMeas) # Error-Term
Directivity'
|