from time import
sleep
import pyvisa
as visa
from pyvisa
import constants
# 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)
session.called = False
def handle_event(resource, event, user_handle):
resource.called
= True
print(f"Handled
event {event.event_type} on
{resource}\n")
# 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")
# Create the measurement
session.write("CALC1:MEAS1:DEF
'S11'")
# Displays measurement 1 in window
1 and assigns the next available trace number to the measurement
session.write("DISP:MEAS1:FEED
1")
session.write("SENS:SWE:MODE
SING")
opcCode = session.query("*OPC?")
# Type of event we want to be notified about
event_type = constants.EventType.service_request
# Mechanism that we want to be notified about
event_mech = constants.EventMechanism.handler
wrapped = session.wrap_handler(handle_event)
user_handle = session.install_handler(event_type,
wrapped, 42)
session.enable_event(event_type,
event_mech, None)
# The following code enables service request
# Turn on the SRQ for operation complete? bit
session.write("*SRE
32")
# Clear any pending status
session.write("*CLS")
# Set sweep time to 2 seconds
session.write("SENS:SWE:TIME
2")
print("Sweep Started")
session.write("SENS:SWE:MODE
SING")
session.write("*OPC") # Tell VNA that
we are interested in operation complete status
while not
session.called:
print("Waiting")
sleep(0.01)
print("Done")
session.disable_event(event_type,
event_mech)
session.uninstall_handler(event_type,
wrapped, user_handle)
|