Drivers

Instrumental drivers allow you to control and read data from various hardware devices.

Some devices (e.g. Thorlabs cameras) have drivers that act as wrappers to their drivers’ C bindings, using ctypes or cffi. Others (e.g. Tektronix scopes and AFGs) utilize VISA and PyVISA, its Python wrapper. PyVISA requires a local installation of the VISA library (e.g. NI-VISA) to interface with connected devices.


Functions

class instrumental.drivers.Instrument

Base class for all instruments.

save_instrument(name, force=False)

Save an entry for this instrument in the config file.

Parameters:
  • name (str) – The name to give the instrument, e.g. ‘myCam’
  • force (bool, optional) – Force overwrite of the old entry for instrument name. By default, Instrumental will raise an exception if you try to write to a name that’s already taken. If force is True, the old entry will be commented out (with a warning given) and a new entry will be written.
class instrumental.drivers.InstrumentMeta

Instrument metaclass.

Implements inheritance of method and property docstrings for subclasses of Instrument. That way e.g. you don’t have to repeat the docstring of an abstract method, though you can provide a docstring in case more specific documentation is useful.

If the child’s docstring contains only a single-line function signature, it is prepended to its parent’s docstring rather than overriding it comopletely. This is useful for the explicitly specifying signatures for methods that are wrapped by a decorator.

instrumental.drivers.instrument(inst=None, **kwargs)

Create any Instrumental instrument object from an alias, parameters, or an existing instrument.

>>> inst1 = instrument('MYAFG')
>>> inst2 = instrument(visa_address='TCPIP::192.168.1.34::INSTR')
>>> inst3 = instrument({'visa_address': 'TCPIP:192.168.1.35::INSTR'})
>>> inst4 = instrument(inst1)
instrumental.drivers.list_instruments(server=None, module=None)

Returns a list of info about available instruments.

May take a few seconds because it must poll hardware devices.

It actually returns a list of specialized dict objects that contain parameters needed to create an instance of the given instrument. You can then get the actual instrument by passing the dict to instrument().

>>> inst_list = get_instruments()
>>> print(inst_list)
[<NIDAQ 'Dev1'>, <TEKTRONIX 'TDS 3032'>, <TEKTRONIX 'AFG3021B'>]
>>> inst = instrument(inst_list[0])
Parameters:server (str, optional) – The remote Instrumental server to query. It can be an alias from your instrumental.conf file, or a str of the form (hostname|ip-address)[:port], e.g. ‘192.168.1.10:12345’. Is None by default, meaning search on the local machine.
instrumental.drivers.list_visa_instruments()

Returns a list of info about available VISA instruments.

May take a few seconds because it must poll the network.

It actually returns a list of specialized dict objects that contain parameters needed to create an instance of the given instrument. You can then get the actual instrument by passing the dict to instrument().

>>> inst_list = get_visa_instruments()
>>> print(inst_list)
[<TEKTRONIX 'TDS 3032'>, <TEKTRONIX 'AFG3021B'>]
>>> inst = instrument(inst_list[0])

Example

>>> from instrumental import instrument
>>> scope = instrument('my_scope_alias')
>>> x, y = scope.get_data()