# -*- coding: utf-8 -*- """Module allowing to command a waveform generator""" import os import ssh import time config = { #Name of the attenuator used by the GPIB driver "name":"GBF", #User name to connect to the host where the GPIB driver is installed "user":"spidcom", #Host where the GPIB driver is installed "host":"blovac", #Noise band in MHz #Value for an Agilent 33250A (see page 158 of the documentation - Chapter 4) "noise_band_mhz":(0, 50), #Power range in dBm #Value for an Agilent 33250A (see page 329 of the documentation - Chapter 7) "power_range_dbm":(-40, 24) } def update_config(new_config): """Update the configuration""" global config config = new_config def power_range_dbm(): return config["power_range_dbm"] def noise_band_mhz(): return config["noise_band_mhz"] def configure_output_impedance(impedance): """Configure the output impedance""" execute("OUTPut:LOAD " + str(impedance)) def configure_sinus(freq_hz, power_dbm, dc_offset_v = 0, am = None, sweep = None): """Configure the output as a sinus, optionnally with AM and sweep""" (power_min_dbm, power_max_dbm) = power_range_dbm() assert power_min_dbm <= power_dbm <= power_max_dbm, power_dbm if freq_hz is None: switch("off") else: execute("APPLy:SINusoid " + str(freq_hz) + "HZ, " + str(power_dbm) + "dBm, " + str(dc_offset_v) + "V") if am is not None: (form, freq_khz, depth_percent) = am execute("AM:SOURce INTernal") execute("AM:INTernal:FUNCtion " + form) execute("AM:INTernal:FREQuency " + str(freq_khz) + "kHz") execute("AM:DEPTh " + str(depth_percent)) execute("AM:STATe ON") if sweep is not None: (freq_min_mhz, freq_max_mhz, time_s) = sweep execute("FREQuency:STARt " + str(freq_min_mhz) + "MHz") execute("FREQuency:STOP " + str(freq_max_mhz) + "MHz") execute("SWEep:TIME " + str(time_s)) execute("SWEep:STATe ON") def configure_white_noise(power_dbm): """Configure the output as white noise""" (power_min_dbm, power_max_dbm) = power_range_dbm() assert power_min_dbm <= power_dbm <= power_max_dbm, power_dbm execute("APPLy:NOISe DEFault, " + str(power_dbm) + "dBm") def configure_output(on_off): """Switch on/off the output""" execute("OUTPut " + on_off.upper()) def switch(on_off): """Switch on/off the GBF""" assert on_off == "on" or on_off == "off" print "Switching", on_off, "the GBF..." configure_output_impedance(50) configure_sinus(1, -40) configure_output(on_off) def execute(command): """Execute the command in ssh on the host where the GPIB driver is intalled""" complete_command = "gpib_control " + config["name"] + \ " \"" + command + "\"" ssh.call(config["user"], config["host"], complete_command)