lightlab.equipment.abstract_drivers.configurable module

Summary

Exceptions:

AccessException

Classes:

Configurable Instruments can be configurable to keep track of settings within the instrument
TekConfig Wraps a dictionary attribute.

Reference

exception AccessException[source]

Bases: Exception

class TekConfig(initDict=None)[source]

Bases: object

Wraps a dictionary attribute. Uses dpath for operations.

Commands are defined as tuples (cStr, val). For example (‘:PATH:TO:CMD’, 4).
Use these by doing scope.write(‘ ‘.join(TekConfig.get(‘PATH:TO:CMD’))) The val is always a string.

Todo

:transferring subgroup from one instance to another. :returning a dictionary representing a subgroup (actually this might currently be happening in error) :transferring subgroup values to a different subgroup in the same instance (for example, CH1 to CH2)

separator = ':'
print(subgroup='')[source]
copy(subgroup='')[source]
get(cStr, asCmd=True)[source]

Returns the value only, not a dictionary

Parameters:asCmd (bool) – if true, returns a tuple representing a command. Otherwise returns just the value
set(cStr, val)[source]

Takes the value only, not a dictionary

getList(subgroup='', asCmd=True)[source]

Deep crawler that goes in and generates a command for every leaf.

Parameters:
  • subgroup (str) – subgroup must be a subdirectory. If ‘’, it is root directory. It can also be a command string, in which case, the returned list has length 1
  • asCmd (bool) – if false, returns a list of strings that can be sent to scopes
Returns:

list of valid commands (cstr, val) on the subgroup subdirectory

Return type:

list

setList(cmdList)[source]

The inverse of getList

transfer(source, subgroup='')[source]

Pulls config from the source TekConfig object. This is useful for subgrouping.

For example, you might want to load from default only the trigger configuration.

Parameters:
  • source (TekConfig or dict) – the object from which config values are pulled into self
  • subgroup (str) – subgroup must be a subdirectory. If ‘’, it is root directory. It can also be a command string, in which case, only that parameter is affected
classmethod fromFile(fname, subgroup='')[source]
classmethod fromSETresponse(setResponse, subgroup='')[source]

setResponse (str): what is returned by the scope in response to query(‘SET?’)

It will require some parsing for subgroup shorthand

save(fname, subgroup='', overwrite=False)[source]

Saves dictionary parameters in json format. Merges if there’s something already there, unless overwrite is True.

Parameters:
  • fname (str) – file name
  • subgroup (str) – groups of commands to write. If ‘’, it is everything.
  • overwrite (bool) – will make a new file exactly corresponding to this instance, otherwise merges with existing
class Configurable(headerIsOptional=True, verboseIsOptional=False, precedingColon=True, interveningSpace=True, **kwargs)[source]

Bases: lightlab.equipment.abstract_drivers.AbstractDriver

Instruments can be configurable to keep track of settings within the instrument

This class is setup so that the hardware state is reflected exactly in the ‘live’ config unless somebody changes something in lab. Watch out for that and use forceHardware if that is a risk

This clas uses query/write methods that are not directly inherited, so the subclass or its parents must implement those functions

config = None

Dictionary of TekConfig objects.

initHardware()[source]

Runs upon first hardware access. Tells the instrument how to format its commands

setConfigParam(cStr, val=None, forceHardware=False)[source]

Sets an individual configuration parameter. If the value has been read before, and there is no change, then it will not write to the hardware.

Parameters:
  • cStr (str) – name of the command
  • val (any) – value to send. Detects type, so if it’s an int, it will be stored as int
  • forceHardware (bool) – will always send to hardware, in case it is critical or if it tends to be changed by pesky lab users
Returns:

Did it requre a write to hardware?

Return type:

(bool)

getConfigParam(cStr, forceHardware=False)[source]

Gets a single parameter. If the value has been read before, and there is no change, then it will not query the hardware.

This is much faster than getting from hardware; however, it assumes that nobody in lab touched anything.

Parameters:
  • cStr (str) – name of the command
  • forceHardware (bool) – will always query from hardware, in case it is critical or if it tends to be changed by pesky lab users
Returns:

command value. Detects type, so that '2.5' will return as float

Return type:

(any)

If the command is not recognized, attempts to get it from hardware

tempConfig(cStr, tempVal, forceHardware=False)[source]

Changes a parameter within the context of a “with” block. Args are same as in getConfigParam().

getDefaultFilename()[source]

Combines the lightlab.util.io.paths.defaultFileDir with the *IDN? string of this instrument.

Returns:the default filename
Return type:(str)
saveConfig(dest='+user', subgroup='', overwrite=False)[source]

If you would like to setup a temporary state (i.e. taking some measurements and going back), use a file and subgroup=

Parameters:subgroup (str) – a group of commands or a single command. If ‘’, it means everything.
Side effects:
if dest is object or dict, modifies it if dest is token, modifies the config library of self if dest is filename, writes that file
loadConfig(source='+user', subgroup='')[source]

Loads some configuration parameters from a source which is either:

  • a file name string, or
  • a special token [‘+default’ or ‘+init’], or
  • some TekConfig object or dict you have out there
Parameters:
  • source (str/TekConfig) – load source
  • subgroup (str) – a group of commands or a single command. If ‘’, it means everything.
generateDefaults(filename=None, overwrite=False)[source]

Attempts to read every configuration parameter. Handles several cases where certain parameters do not make sense and must be skipped

Generates a new default file which is saved in configurable.defaultFileDir

This takes a while.

Parameters:
  • filename (str) – simple name. You can’t control the directory.
  • overwrite (bool) – If False, stops if the file already exists.