vna.preset() vna.pause() vna.clear_status() # Setup channel 1 ch1 = vna.channel(1) ch1.sweep_type = SweepType.power ch1.start_power_dBm = -20.0 ch1.stop_power_dBm = 0 ch1.points = 201 ch1.if_bw_Hz = 1, 'kilo' ch1.cal_group = 'example' ch1.manual_sweep = True # Setup Trc1: S21 s21_trace = vna.trace('Trc1') s21_trace.parameter = 'S21' # Setup Trc2: a1(P1) vna.create_trace(channel=1, name='Trc2', parameter="a1(P1)") a1_trace = vna.trace('Trc2') a1_trace.diagram = 1 # Sweep, Retrieve data power_dBm, s21_dB = s21_trace.measure_formatted_data() a1_dBm = a1_trace.y_formatted # Plot plt.plot(power_dBm, s21_dB, 'r-', label="Ideal") plt.plot(a1_dBm, s21_dB, 'b-', label="Measured") plt.legend()
# alternatively, using pyvisa: # vna.open('gpib', 20) # preset and clear errors vna.clear_status() vna.preset() vna.pause() # create an interesting setup # to save ch1 = vna.channel(1) ch1.start_frequency_Hz = 1.0e9 ch1.stop_frequency_Hz = 2.0e9 ch1.points = 401 trc1 = vna.trace('Trc1') trc1.parameter = 'S11' index = vna.create_diagram() name = vna.create_trace() trc2 = vna.trace(name) trc2.parameter = 'S21' trc2.diagram = index # save vna.save_active_set_locally(set_file) vna.pause() # preset (again) vna.preset()
vna.settings.display = False # sweep, measure time vna.manual_sweep = True vna.sweep_count = args.sweep_count total_time_s = default_time_s(vna.sweep) time_per_sweep_s = total_time_s / args.sweep_count # save timing info timing_info_file = data_path / 'timing_info.csv' with timing_info_file.open('w') as f: header = [ 'sweep_count', 'total_time_s', 'time_per_sweep_s'] data = [args.sweep_count, total_time_s, time_per_sweep_s ] csvwriter = csv.writer(f) csvwriter.writerow(header) csvwriter.writerow(data) # save trace history for name in vna.traces: filename = str(data_path / f'{name}.csv') vna.trace(name).save_complex_history_locally(filename) # verbose? if not args.quiet: print(f'total time: {si_format(total_time_s, precision=3)}s') print(f'per sweep: {si_format(time_per_sweep_s, precision=3)}s') # success sys.exit(0)