lightlab.laboratory.instruments.bases module

This module provides an interface for instruments, hosts and benches in the lab.

Summary

Exceptions:

NotFoundError Error thrown when instrument is not found

Classes:

Bench Represents an experiment bench for the purpose of facilitating its location in lab.
Device Represents a device in lab.
Host Computer host, from which GPIB/VISA commands are issued.
Instrument Represents an instrument in lab.
LocalHost
MockInstrument

Reference

class Host(name='Unnamed Host', hostname=None, **kwargs)[source]

Bases: lightlab.laboratory.Node

Computer host, from which GPIB/VISA commands are issued.

mac_address = None
os = 'linux-ubuntu'
hostname = None
name
instruments
isLive()[source]

Pings the system and returns if it is alive.

gpib_port_to_address(port, board=0)[source]
Parameters:
  • port (int) – The port on the GPIB bus of this host
  • board (int) – For hosts with multiple GPIB busses
Returns:

the address that can be used in an initializer

Return type:

(str)

list_resources_info(use_cached=True)[source]

Executes a query to the NI Visa Resource manager and returns a list of instruments connected to it.

Parameters:use_cached (bool) – query only if not cached, default True
Returns:list of pyvisa.highlevel.ResourceInfo named tuples.
Return type:list
list_gpib_resources_info(use_cached=True)[source]

Like list_resources_info(), but only returns gpib resources.

Parameters:use_cached (bool) – query only if not cached, default True.
Returns:list of pyvisa.highlevel.ResourceInfo named tuples.
Return type:(list)
get_all_gpib_id(use_cached=True)[source]

Queries the host for all connected GPIB instruments, and queries their identities with instrID().

Warning: This might cause your instrument to lock into remote mode.

Parameters:use_cached (bool) – query only if not cached, default True
Returns:dictionary with gpib addresses as keys and identity strings as values.
Return type:dict
findGpibAddressById(id_string_search, use_cached=True)[source]

Finds a gpib address using get_all_gpib_id(), given an identity string.

Parameters:
  • id_string_search (str) – identity string
  • use_cached (bool) – query only if not cached, default True
Returns:

address if found.

Return type:

str

Raises:

NotFoundError – If the instrument is not found.

addInstrument(*instruments)[source]

Adds an instrument to lab.instruments if it is not already present.

Parameters:*instruments (Instrument) – instruments
removeInstrument(*instruments)[source]

Disconnects the instrument from the host

Parameters:*instruments (Instrument) – instruments

Todo

Remove all connections

checkInstrumentsLive()[source]

Checks whether all instruments are “live”.

Instrument status is checked with the Instrument.isLive() method

Returns:True if all instruments are live, False otherwise
Return type:(bool)
display()[source]

Displays the host’s instrument table in a nice format.

class LocalHost(name=None)[source]

Bases: lightlab.laboratory.instruments.bases.Host

isLive()[source]

Pings the system and returns if it is alive.

class Bench(name, *args, **kwargs)[source]

Bases: lightlab.laboratory.Node

Represents an experiment bench for the purpose of facilitating its location in lab.

name = None
instruments
devices
addInstrument(*instruments)[source]

Adds an instrument to lab.instruments if it is not already present and connects to the host.

Parameters:*instruments (Instrument) – instruments
removeInstrument(*instruments)[source]

Detaches the instrument from the bench.

Parameters:*instruments (Instrument) – instruments

Todo

Remove all connections

addDevice(*devices)[source]

Adds a device to lab.devices if it is not already present and places it in the bench.

Parameters:*devices (Device) – devices
removeDevice(*devices)[source]

Detaches the device from the bench.

Parameters:*devices (Device) – devices

Todo

Remove all connections

display()[source]

Displays the bench’s table in a nice format.

class Instrument(name='Unnamed Instrument', id_string=None, address=None, **kwargs)[source]

Bases: lightlab.laboratory.Node

Represents an instrument in lab.

This class stores information about instruments, for the purpose of facilitating verifying whether it is connected to the correct devices.

Driver feedthrough
Methods, properties, and even regular attributes that are in essential_attributes of the class will get/set/call through to the driver object.
Do not instantiate directly
Calling a VISAInstrumentDriver class will return an Instrument object

Short example:

osa = Apex_AP2440A_OSA(name='foo', address='NULL')
osa.spectrum()
Long example
Instrument configuration
Detailed testing
test_driver_init()
essentialMethods = ['startup']

list of methods to be fed through the driver

essentialProperties = []

list of properties to be fed through the driver

optionalAttributes = []

list of optional attributes to be fed through the driver

ports = None

list(str) Port names of instruments. To be used with labstate connections.

address = None

Complete Visa address of the instrument (e.g. visa://hostname/GPIB0::1::INSTR)

implementedOptionals
hardware_warmup()[source]

Called before the beginning of an experiment.

Typical warmup procedures include RESET gpib commands.

hardware_cooldown()[source]

Called after the end of an experiment.

Typical cooldown procedures include laser turn-off, or orderly wind-down of current etc.

warmedUp()[source]

A context manager that warms up and cools down in a “with” block

Usage:

with instr.warmedUp() as instr:  # warms up instrument
    instr.doStuff()
    raise Exception("Interrupting experiment")
# cools down instrument, even in the event of exception
driver_class

Class of the actual equipment driver (from lightlab.equipment.lab_instruments)

This way the object knows how to instantiate a driver instance from the labstate.

driver_object

Instance of the equipment driver.

driver

Alias of driver_object().

bench

Property that only accepts <class ‘lightlab.laboratory.instruments.bases.Bench’> values

host

Property that only accepts <class ‘lightlab.laboratory.instruments.bases.Host’> values

name

(property) Instrument name (can only set during initialization)

id_string

The id_string should match the value returned by self.driver.instrID(), and is checked by the command self.isLive() in order to authenticate that the intrument in that address is the intended one.

display()[source]

Displays the instrument’s info table in a nice format.

isLive()[source]

Attempts VISA connection to instrument, and checks whether instrID() matches id_string.

Produces a warning if it is live but the id_string is wrong.

Returns:True if “live”, False otherwise.
Return type:(bool)
connectHost(new_host)[source]

Sets/changes instrument’s host.

Equivalent to self.host = new_host

placeBench(new_bench)[source]

Sets/changes instrument’s bench.

Equivalent to self.bench = new_bench

class MockInstrument(name='Unnamed Instrument', id_string=None, address=None, **kwargs)[source]

Bases: lightlab.laboratory.instruments.bases.Instrument

exception NotFoundError[source]

Bases: RuntimeError

Error thrown when instrument is not found

class Device(name, **kwargs)[source]

Bases: lightlab.laboratory.Node

Represents a device in lab. Only useful for documenting the experiment.

Todo

Add equality function

name = None

device name

ports = None

list(str) port names

bench

Property that only accepts <class ‘lightlab.laboratory.instruments.bases.Bench’> values

display()[source]

Displays the device’s info table in a nice format.