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(inst=None, **kwds)¶
Base class for all instruments.
- observe(name, callback)¶
Add a callback to observe changes in a facet’s value
The callback should be a callable accepting a
ChangeEvent
as its only argument. ThisChangeEvent
is a namedtuple withname
,old
, andnew
fields.name
is the facet’s name,old
is the old value, andnew
is the new value.
- 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. Ifforce
is True, the old entry will be commented out (with a warning given) and a new entry will be written.
- instrumental.drivers.instrument(inst=None, **kwargs)¶
Create any Instrumental instrument object from an alias, parameters, or an existing instrument.
- reopen_policystr of (‘strict’, ‘reuse’, ‘new’), optional
How to handle the reopening of an existing instrument. ‘strict’ - disallow reopening an instrument with an existing instance which hasn’t been cleaned up yet. ‘reuse’ - if an instrument is being reopened, return the existing instance ‘new’ - always create a new instance of the instrument class. Not recommended unless you know exactly what you’re doing. The instrument objects are not synchronized with one another. By default, follows the ‘reuse’ policy.
>>> 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, blacklist=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.blacklist (list or str, optional) – A str or list of strs indicating driver modules which should not be queried for instruments. Strings should be in the format
'subpackage.module'
, e.g.'cameras.pco'
. This is useful for very slow-loading drivers whose instruments no longer need to be listed (but may still be in use otherwise). This can be set permanently in yourinstrumental.conf
.module (str, optional) – A str to filter what driver modules are checked. A driver module gets checked only if it contains the substring
module
in its full name. The full name includes both the driver group and the module, e.g.'cameras.pco'
.
- 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()