Tutorial

Note: system setup should be completed first

This example expects a function generator connected to channel 1 of an oscilloscope.

Open an instrument

In [1]: from instrument_opening import open_by_name

In [2]: fg = open_by_name(name='old_fg')   # name within the configuration file (config.yaml)
Opened Instrument: Agilent Technologies,33220A,MY44060286,2.07-2.06-22-2

Simple set and get combination

In [3]: fg.set('offset', 0.5);

In [4]: print('Readback of Function Generator offset = {} [V]'.format(fg.get('offset')))
Readback of Function Generator offset = 0.5 [V]

In [5]: fg.set('v', 1);

In [6]: fg.set('freq', 3.12e3);

In [7]: fg.set('load', 'INF');

In [8]: fg.set('output', 'ON');  # this is an example of a lookup table conversion 'ON' -> 1

Open an oscilloscope in order to demonstrate more complex setters and getters:

In [9]: osc = open_by_name(name='msox_scope')  # name within the configuration file (config.yaml)
Opened Instrument: KEYSIGHT TECHNOLOGIES,MSO-X 3034T,MY58030693,07.20.2017102614

In [10]: osc.set('time_range', 1e-3);

In [11]: osc.set('chan_scale', 0.2, configs={'chan': 1});

In [12]: osc.set('chan_offset', 0.5, configs={'chan': 1});

Oscilloscope triggering

In [13]: osc.set('trigger_sweep', 'NORM');

In [14]: osc.set('trigger_mode', 'EDGE');

In [15]: osc.set('trigger_slope', 'POS');

In [16]: osc.set('trigger_level', 0.5, configs={'chan': 1});

In [17]: osc.set('trigger_source', 1);

Oscilloscope measurements

In [18]: v_average = osc.get('meas', configs={'meas_type': 'VAV', 'chan': 1});

In [19]: v_pkpk = osc.get('meas', configs={'meas_type': 'VPP', 'chan': 1});

In [20]: v_freq = osc.get('meas', configs={'meas_type': 'FREQ', 'chan': 1});

Print oscilloscope measurements

In [21]: print('Oscilloscope measurements: Average voltage: {} \nPeak-to-peak voltage: {}\n'.format(v_average, v_pkpk))
Oscilloscope measurements: Average voltage: 0.49938 
Peak-to-peak voltage: 1.01


In [22]: print('Frequency: {} [kHz]'.format(v_freq/1000))
Frequency: 3.1201999999999996 [kHz]

Help

Help is available both at the single command level. In an iPython terminal help outputs are nicely color coded. Unfortunately, coloroma color-coding is broken in the Sphinx documentation.

Help on a single command:

In [23]: fg.help('offset')
Help for command offset in subsystem: output:
    voltage offset, range depends on amplitude 
    Allowable range is: [-4.99, 4.99]
    Returns: float

Help on all commands (or all commands in a subsystem):

In [24]: fg.help_all(subsystem_list = ['output'])
=====================================

Help for Subsytem: output:


Help for command function in subsystem: output:
    output function, sin; square, etc.
    Allowable range is: ['SIN', 'SQU', 'RAMP', 'PULS', 'NOIS', 'DC', 'USER']
    Returns: str_strip

Help for command freq in subsystem: output:
    output frequency in Hz
    Allowable range is: [0, 20000000.0]
    Returns: float

Help for command v in subsystem: output:
    voltage amplitude
    Allowable range is: [0.01, 10]
    Returns: float

Help for command offset in subsystem: output:
    voltage offset, range depends on amplitude 
    Allowable range is: [-4.99, 4.99]
    Returns: float

Help for command phase in subsystem: output:
    phase with respect to sync and rear-panel connectors
    Allowable range is: [-360, 360]
    Returns: float

Help for command v_low in subsystem: output:
    need to check this one
    Allowable range is: [0, 1]
    Returns: float

Help for command v_high in subsystem: output:
    need to check this one
    Allowable range is: [0, 1]
    Returns: float

Help for command unit in subsystem: output:
    voltage unit
    Allowable range is: ['VPP', 'VRMS', 'DBM']
    Returns: str_strip

Help for command output in subsystem: output:
    turn output on or off
    Allowable range is: [0.0, 1.0]
    Returns: int
    This command utilizes a lookup table on get and set:
     {'OFF': 0.0, 'ON': 1.0}

Help for command duty_cycle in subsystem: output:
    square wave
    Allowable range is: [0, 100]
    Returns: float

Help for command symmetry in subsystem: output:
    ramp
    Allowable range is: [0, 100]
    Returns: float

Help for command load in subsystem: output:
    output load (50 Ohm or High-Z). Ohms or 'MIN', 'MAX'
    Returns: float

Help for command polarity in subsystem: output:
    invert the output or not
    Allowable range is: ['NORM', 'INV']
    Returns: str_strip

Help for command sync in subsystem: output:
    sync to external reference
    Allowable range is: [0.0, 1.0]
    Returns: int
    This command utilizes a lookup table on get and set:
     {'OFF': 0.0, 'ON': 1.0}