import pyvisa def scope_conn(SCOPE_ADDR): rm = pyvisa.ResourceManager('@py') print(rm.list_resources()) print("Attempting to connect to scope\n") try: # Try connect to scope scope = rm.open_resource(SCOPE_ADDR) except: print(f"Error in connecting to: {SCOPE_ADDR}\n") return 0 else: print("Connected to scope") return scope def scope_init(scope): # Initialise scope print("Recalling set-up") scope.write("*RCL 1") def scope_avg_phase(scope, avg, chan): # scope is the visa object of the oscilloscope # avg is the number of averages to take # chan is the channel to measure (2-4) CHANNELS = ["MEAS:PHAS? CHAN1,CHAN2","MEAS:PHAS? CHAN1,CHAN3","MEAS:PHAS? CHAN1,CHAN4"] # array of channel IDs phases = [] # array of phase measurements # measure phase 'avg' number of times for i in range(int(avg)): p = scope.query(CHANNELS[chan-2]) p = p.replace("\n","") phases.append(p) return phases