Instruments

An instrument, both physically and within Empyric, is essentially an ensemble of knobs that you set and meters that you measure. Commands to perform these actions are mediated by an adapter (see Adapters). The methods for setting knobs are of the format, set_knob or set('knob'), where knob is the name of the knob. Similarly, measuring a meter is done by calling the instrument’s measure_meter or measure('meter') methods, where meter is the name of the meter.

It is also possible to read a knob value from an instrument by calling the get_knob method of the instrument, if it has one. Otherwise, the last known value of the knob can obtained by retrieving the corresponding attribute of the instrument, e.g. instrument.knob to get the last known setpoint of knob on the instrument.

Each instrument has a one or more supported adapters, found by retrieving the supported_adapters attribute of the class; each element of this tuple contains the adapter class and any non-default settings of that adapter required to communicate with this instrument.

The supported instruments listed below are subclasses of the Instrument class:

class empyric.collection.instrument.Instrument(address=None, adapter=None, presets=None, postsets=None, **kwargs)

Basic representation of an instrument, essentially a set of knobs and meters

Each instrument has the following attributes:

  • name: the name of the instrument. Once connected via an adapter, this is converted to name + '@' + address.

  • supported adapters: tuple of 2-element tuples. Each 2-element tuple contains an adapter class that the instrument can be used with and a dictionary of adapter settings.

  • knobs: tuple of the names of all knobs that can be set on the instrument. Every instrument has a connected (Toggle) knob, for convenience, whose set method calls the instruments connect or disconnect methods, if set to ON or OFF respectively.

  • presets: dictionary of knob settings to apply when the instrument is instantiated. The keys are the names of the knobs and the values are the knob values.

  • postsets: dictionary of knob settings (same format as presets) to apply when the instrument is deleted.

  • meters: tuple of the names of all meters that can be measured on this instrument.

Every knob of an instrument has an associated set_[knob] method, which sends commands to the physical instrument that change the value of the knob to the given value. Each set_[knob] method should be wrapped by the setter function defined above.

Every knob may also have an associated get_[knob] method, which queries the value of the knob from the physical instrument, and should be wrapped by the getter function defined above.

Every meter of an instrument has an associated measure_[meter] method, which queries the value of a quantity measured by the physical instrument, and should be wrapped by the measurer function defined above.

For convenience, the setter, getter and `measurer functions augment the corresponding methods primarily by enforcing typing on the method arguments and the returned values, and storing the last known values of knobs and meters in the corresponding attribute of the Instrument instance. For example, if a meter called “”temperature” is retrieved via the corresponding measure_temperature method of the instrument thermometer, the wrapping measurer function will assign that temperature value to thermometer.temperature. If the expected data type is a floating point number, the measurer function additionally converts whatever the bare measure_temperature method returns to a 64-bit floating point value.

supported_adapters = ((<class 'empyric.adapters.Adapter'>, {}),)
meters = ()
ignore_errors = False
knobs = ()
name = 'Instrument'
presets = {}
postsets = {}
write(*args, **kwargs)

Alias for the adapter’s write method

Parameters:
  • args – any arguments for the adapter’s write method, usually including a command string

  • kwargs – any arguments for the adapter’s write method

Returns:

whatever is returned by the adapter’s write method

read(*args, **kwargs)

Alias for the adapter’s read method

Parameters:
  • args – any arguments for the adapter’s read method

  • kwargs – any arguments for the adapter’s read method

Returns:

whatever is returned by the adapter’s read method

query(*args, **kwargs)

Alias for the adapter’s query method, if it has one

Parameters:
  • args – any arguments for the adapter’s query method

  • kwargs – any arguments for the adapter’s query method

Returns:

whatever is returned by the adapter’s query method

set(knob: str, value)

Set the value of a knob on the instrument

Parameters:
  • knob – (string) name of variable to be set

  • value – (float/string) value of new variable setting

Returns:

None

get(knob: str)

Get the value of a knob on the instrument. If the instrument has a get method for the knob, a command will be sent to the instrument to retrieve the actual value of the knob. If it does not have a get method for the knob, the last known value, stored as an instance attribute, will be return (possibly being nan if no value has yet been set)

measure(meter: str)

Measure the value of a variable associated with this instrument

Parameters:

meter – (string) name of the variable to be measured

Returns:

(float/string) measured value of the variable

connect()

(Re)Connect to the instrument. This is useful when communications are lost and a new connection is required.

Returns:

None

disconnect()

Apply any postsets to the instrument and disconnect the adapter

Returns:

None

set_connected(state: Toggle)
get_connected() Toggle

An instance of an instrument from the collection of instruments below can be initialized by importing from empyric.instruments. For example, instantiating a Keithley 2400 sourcemeter is done with the command sequence,

from empyric.instruments import Keithley2400
sourcemeter = Keithley2400(1)  # if GPIB address is 1

Supported Instruments