SPI Rack

QCoDeS driver

class spi_rack.spi_rack.dummy_spi_api(address, baud_rate, timeout=1.0)[source]

Bases: object

A dummy API that can be used to test the SPI rack driver.

TEMPERATURE = 25.0
BATTERY_LVLS = [6.0, -6.0]
FIRMWARE_VERSION = 'v1.0'
__init__(address, baud_rate, timeout=1.0)[source]

Instantiates the dummy API object.

Parameters
  • address – Mock value for the address on which the spi_rack is connected. This value is assigned to a member variable, but is not actually used.

  • address – Mock value for the baud_rate for the serial connection. This value is assigned to a member variable, but is not actually used.

  • timeout – Mock value for the timeout for the serial connection. This value is assigned to a member variable, but is not actually used.

get_temperature()float[source]

Return a mock temperature.

Returns

returns dummy_spi_api.TEMPERATURE

Return type

float

get_battery()List[float][source]

Return a mock battery level list. In the actual API these are two values read from the battery ADCs. For the mock API simply constant values are returned. The expected values to be returned can also be gotten through dummy_spi_api.BATTERY_LVLS.

Returns

returns dummy_spi_api.BATTERY_LVLS

Return type

List[float]

get_firmware_version()str[source]

Returns a firmware version string. In the actual API this is returned by the microcontroller.

Returns

returns dummy_spi_api.FIRMWARE_VERSION

Return type

str

close()[source]

Not relevant for dummy api but added to remove errors

unlock()[source]

Unlocks the communication to the microcontroller. Since for the dummy implementation there is no communication to the microcontroller, this simply sets a self.locked to False.

class spi_rack.spi_rack.spi_rack(name: str, address: str, baud_rate: int = 9600, timeout: float = 1, is_dummy: bool = False)[source]

Bases: qcodes.instrument.base.Instrument

SPI rack driver class based on QCoDeS <https://qcodes.github.io/Qcodes/>. This class relies on the spirack API <https://github.com/mtiggelman/SPI-rack/>.

Example usage:

from spi_rack.spi_rack import spi_rack
from spi_rack.s4g_module import s4g_module

spi = spi_rack("my_spi_rack", "COM4")     # connects to an SPI rack on COM port 4
spi.add_spi_module(3, "D5a", "alice")     # adds an D5a module with address 3 named "alice"
spi.add_spi_module(2, "S4g", "bob")       # adds an S4g module with address 2 named "bob"
spi.add_spi_module(6, s4g_module)         # adds an S4g module with address 6 with the default name module6

spi.bob.dac0.current(10e-3)               # sets the current of output 1 of the S4g module named "bob" to 10 mA
spi.alice.dac6.voltage(-2)                # sets the voltage of output 7 of the D5a module named "alice" to -2 V
__init__(name: str, address: str, baud_rate: int = 9600, timeout: float = 1, is_dummy: bool = False)[source]

Instantiates the driver object.

Parameters
  • name (str) – Instrument name.

  • address (str) – COM port used by SPI rack controller unit (e.g. “COM4”)

  • baud_rate (int) – Baud rate

  • timeout (float) – Data receive timeout in seconds

  • is_dummy (bool) – If true, the SPI rack driver is operating in “dummy” mode for testing purposes.

add_spi_module(address: int, module_type: Union[spi_rack.spi_module_base.spi_module_base, str], name: Optional[str] = None, **kwargs)[source]

Add a module to the driver.

Parameters
  • address (int) – Address that the module is set to (set internally on the module itself with a jumper).

  • module_type (Union[str, spi_module_base]) – Either a str that is defined in _MODULES_MAP, or a reference to a class derived from SPI_Module_Base.

  • name (str) – Optional name of the module. If no name is given or is None, a default name of “module{address}” is used.

Raises

ValueError – module_type is not a string or a subclass of SPI_Module_Base

get_idn()[source]

Generates the IDN dict.

Returns

The QCoDeS style IDN dictionary. Currently only the firmware version is actually read from hardware.

Return type

dict

close()[source]

Closes connection to hardware and closes the Instrument.

set_dacs_zero()[source]

Calls the set_dacs_zero() function on all the modules, which in turn should cause all output values to be set to 0.

connect_message(idn_param: str = 'IDN', begin_time: Optional[float] = None)None[source]

Print a standard message on initial connection to an instrument. Overridden from superclass to accommodate IEEE488.2 for IDN.

Parameters
  • idn_param (str) – Name of parameter that returns ID dict. Default IDN.

  • begin_time (Optional[float]) – time.time() when init started. Default is self._t0, set at start of Instrument.__init__.

class spi_rack.spi_module_base.spi_module_base(parent, name: str, address: int, **kwargs)[source]

Bases: qcodes.instrument.channel.InstrumentChannel

Defines an abstract base class for SPI modules. All module drivers should inherit from this class.

This class defines no actual functionality but rather serves to provide a common interface shared among all modules.

Parameters
  • parent – Reference to the spi_rack parent object. This is handled by the add_spi_module function.

  • name (str) – Name given to the InstrumentChannel.

  • address (int) – Module number set on the hardware (set internally on the module itself with a jumper).

__init__(parent, name: str, address: int, **kwargs)[source]

Initialize self. See help(type(self)) for accurate signature.

abstract set_dacs_zero()[source]

” Base method for set_dacs_zero. Should be overridden by subclass.

class spi_rack.spi_module_base.dummy_spi_module(parent, name: str, address: int)[source]

Bases: spi_rack.spi_module_base.spi_module_base

A dummy implementation of module driver, used for mock implementations.

__init__(parent, name: str, address: int)[source]

Initialize self. See help(type(self)) for accurate signature.

set_dacs_zero()[source]

” Base method for set_dacs_zero. Should be overridden by subclass.

QCoDeS parameters

spi_rack.IDN

Please see QCoDeS for a description.

Properties
  • value: Anything

spi_rack.temperature

Returns the temperature in the C1b module. Reads the temperature from the internal C1b temperature sensor. Accuracy is +- 0.5 degrees in 0-70 degree range.

Properties
  • unit: C

  • value: on

spi_rack.battery_voltages

Calculates the battery voltages from the ADC channel values. Returns: [VbatPlus, VbatMin]

Properties
  • unit: V

  • value: on

S4g module

class spi_rack.s4g_module.dummy_s4g_api(spi_rack, module, max_current=0.05, reset_currents=True)[source]

Bases: object

Mock implementation of spirack API (https://github.com/mtiggelman/SPI-rack/blob/master/spirack/S4g_module.py), for use with the dummy drivers.

SPAN_MAPPING = {'range_max_bi': 2, 'range_max_uni': 0, 'range_min_bi': 4}
DAC_RESOLUTION = 262144
NUMBER_OF_DACS = 4
__init__(spi_rack, module, max_current=0.05, reset_currents=True)[source]

Instantiates the mock communication layer with identical parameters to the spirack.S4g_module.S4g_module constructor.

Parameters
  • spi_rack (dummy_spi_api) – Mock SPI_rack class object via which the communication runs

  • module (int) – module number set on the hardware

  • max_current (float) – maximum range of the S4g, configured in hardware

  • reset_currents (bool) – if True, then reset all currents to zero and change the span to range_max_bi

change_span_update(DAC: int, span: int)[source]

Mocks the change_span_update function of the API.

Parameters
  • DAC (int) – Current output of which to change the span

  • span (int) – values for the span as mentioned in the datasheet, use from SPAN_MAPPING

change_span(DAC, span)[source]

Mocks the change_span function of the API

Parameters
  • DAC (int) – Current output of which to change the span

  • span (int) – values for the span as mentioned in the datasheet, use from SPAN_MAPPING

set_current(DAC: int, current: float)[source]

Mocks the set_voltage function of the API

Parameters
  • DAC (int) – Current output of which to update the current

  • voltage (float) – new DAC current

get_settings(DAC: int)[source]

Mocks the get_settings function of the API

Parameters

DAC (int) – Current output of which the settings will be read

Returns

  • float – current

  • int – span

get_stepsize(DAC)[source]

Mocks the get_stepsize function of the API

Parameters

DAC (int) – Current output of which the stepsize is calculated

Returns

Smallest current step possible with DAC

Return type

float

class spi_rack.s4g_module.s4g_module(parent, name: str, address: int, reset_currents: bool = True, dac_names: Optional[List[str]] = None, is_dummy: bool = False)[source]

Bases: spi_rack.spi_module_base.spi_module_base

QCoDeS <https://qcodes.github.io/Qcodes/>- style instrument channel driver for the S4g SPI module.

NUMBER_OF_DACS = 4
__init__(parent, name: str, address: int, reset_currents: bool = True, dac_names: Optional[List[str]] = None, is_dummy: bool = False)[source]

Instantiates the driver object. This is the object that should be instantiated by the add_spi_module function.

Parameters
  • parent – Reference to the spi_rack parent object. This is handled by the add_spi_module function.

  • name (str) – Name given to the InstrumentChannel.

  • address (int) – Module number set on the hardware.

  • reset_currents (bool) – If True, then reset all currents to zero and change the span to range_max_bi.

  • dac_names (List[str]) – List of all the names to use for the dac channels. If no list is given or is None, the default name “dac{i}” is used for the i-th dac channel.

Raises

ValueError – Length of the dac names list does not match the number of dacs.

set_dacs_zero()[source]

Sets all currents of all outputs to 0.

class spi_rack.s4g_module.s4g_dac_channel(parent: spi_rack.s4g_module.s4g_module, name: str, dac: int)[source]

Bases: qcodes.instrument.channel.InstrumentChannel

QCoDeS <https://qcodes.github.io/Qcodes/>- style instrument channel driver for the dac channels of the S4g module. This class is used by the S4g_module to define the individual dac channels and should not be used directly.

__init__(parent: spi_rack.s4g_module.s4g_module, name: str, dac: int)[source]

Constructor for the dac channel instrument channel.

Parameters
  • parent (s4g_module) – Reference to the parent s4g_module

  • name (str) – Name for the instrument channel

  • dac (int) – Number of the dac that this channel corresponds to

set_current_instant(dac, val)[source]

” Wrapper function around the set_current API call. Instantaneously sets the current.

Parameters
  • dac (int) – the dac of which to set the current

  • val (float) – The new value of the current

S4g QCoDeS parameters

spi_rack_module2_dac0.current

Sets the output current of the dac channel. Depending on the value of ramping_enabled, the output value is either achieved through slowly ramping, or instantaneously set.

Properties
  • unit: A

  • value: Numbers -0.04<=v<=0.04

spi_rack_module2_dac0.span

Sets the max range of the DACs. Possible values: ‘range_max_uni’: 0 - 40 mA, ‘range_max_bi’: -40 - 40 mA, ‘range_min_bi’: -20 - 20 mA.

Properties
  • value: Enum: {‘range_max_bi’, ‘range_min_bi’, ‘range_max_uni’}

spi_rack_module2_dac0.ramp_rate

Limits the rate at which currents can be changed. The size of of steps is still limited by ramp_max_step.

Properties
  • unit: A/s

  • value: on

spi_rack_module2_dac0.ramp_max_step

Sets the maximum step size for current ramping. The rate at which it ramps is set by ramp_rate.

Properties
  • unit: A

  • value: on

spi_rack_module2_dac0.ramping_enabled

Turns ramping on or off. Toggling ramping_enabled changed the behavior of the setter for the current parameter. If enabled, ramping is done at a rate set by ramp_rate and in steps specified by ramp_max_step.

Properties
  • value: Boolean

spi_rack_module2_dac0.is_ramping

Returns whether the dac is currently in the process of ramping.

Properties
  • value: on

spi_rack_module2_dac0.stepsize

Returns the smallest current step allowed by the dac for the current settings.

Properties
  • unit: A

  • value: on

spi_rack_module2_dac0.dac_channel

Returns the dac number of this channel.

Properties
  • value: on

D5a module

class spi_rack.d5a_module.dummy_d5a_api(spi_rack, module: int, reset_voltages: bool = True, num_dacs: int = 16)[source]

Bases: object

Mock implementation of spirack API (https://github.com/mtiggelman/SPI-rack/blob/master/spirack/D5a_module.py), for use with the dummy drivers.

SPAN_MAPPING = {'range_2V_bi': 4, 'range_4V_bi': 2, 'range_4V_uni': 0, 'range_8V_bi': 3, 'range_8V_uni': 1}
DAC_RESOLUTION = 262144
__init__(spi_rack, module: int, reset_voltages: bool = True, num_dacs: int = 16)[source]

Instantiates the mock communication layer with identical parameters to the spirack.D5a_module.D5a_module constructor.

Parameters
  • spi_rack (dummy_spi_api) – Mock SPI_rack class object via which the communication runs

  • module (int) – module number set on the hardware

  • reset_voltages (bool) – if True, then reset all voltages to zero and change the span to range_4V_bi. If a voltage jump would occur, then ramp to zero in steps of 10 mV

  • num_dacs (int) – number of DAC channels available

change_span_update(DAC: int, span: int)[source]

Mocks the change_span_update function of the API.

Parameters
  • DAC (int) – Current output of which to change the span

  • span (int) – values for the span as mentioned in the datasheet, use from SPAN_MAPPING

change_span(DAC: int, span: int)[source]

Mocks the change_span function of the API.

Parameters
  • DAC (int) – Current output of which to change the span

  • span (int) – values for the span as mentioned in the datasheet, use from SPAN_MAPPING

set_voltage(DAC: int, voltage: float)[source]

Mocks the set_voltage function of the API

Parameters
  • DAC (int) – DAC inside the module of which to update the voltage

  • voltage (float) – new DAC voltage

get_settings(DAC: int)[source]

Mocks the get_settings function of the API

Parameters

DAC (int) – Current output of which the settings will be read

Returns

  • float – voltage

  • int – span

get_stepsize(DAC: int)[source]

Mocks the get_stepsize function of the API.

Parameters

DAC (int) – DAC inside the module of which the stepsize is calculated

Returns

Smallest voltage step possible with DAC

Return type

float

class spi_rack.d5a_module.d5a_module(parent, name: str, address: int, reset_voltages: bool = True, dac_names: Optional[List[str]] = None, is_dummy: bool = False)[source]

Bases: spi_rack.spi_module_base.spi_module_base

QCoDeS <https://qcodes.github.io/Qcodes/>- style instrument channel driver for the D5a SPI module.

NUMBER_OF_DACS = 16
__init__(parent, name: str, address: int, reset_voltages: bool = True, dac_names: Optional[List[str]] = None, is_dummy: bool = False)[source]

Instantiates the driver object.

Parameters
  • parent – Reference to the spi_rack parent object. This is handled by the add_spi_module function.

  • name (str) – Name given to the InstrumentChannel.

  • address (int) – Module number set on the hardware.

  • reset_voltages (bool) – If True, then reset all voltages to zero and change the span to range_max_bi.

  • dac_names (List[str]) – List of all the names to use for the dac channels. If no list is given or is None, the default name “dac{i}” is used for the i-th dac channel.

  • is_dummy (bool) – If true, do not connect to physical hardware, but use

Raises

ValueError – Length of the dac names list does not match the number of dacs.

set_dacs_zero()[source]

Sets all voltages of all outputs to 0.

class spi_rack.d5a_module.d5a_dac_channel(parent: spi_rack.d5a_module.d5a_module, name: str, dac: int)[source]

Bases: qcodes.instrument.channel.InstrumentChannel

QCoDeS <https://qcodes.github.io/Qcodes/>- style instrument channel driver for the dac channels of the D5a module. This class is used by the d5a_module to define the individual dac channels and should not be used directly.

__init__(parent: spi_rack.d5a_module.d5a_module, name: str, dac: int)[source]

Constructor for the dac channel instrument channel.

Parameters
  • parent (d5a_module) – Reference to the parent s4g_module

  • name (str) – Name for the instrument channel

  • dac (int) – Number of the dac that this channel corresponds to

set_voltage_instant(dac: int, val: float)[source]

” Wrapper function around the set_voltage API call. Instantaneously sets the voltage.

Parameters
  • dac (int) – the dac of which to set the voltage

  • val (float) – The new value of the voltage

D5a QCoDeS parameters

spi_rack_module1_dac0.voltage

Sets the output voltage of the dac channel. Depending on the value of ramping_enabled, the output value is either achieved through slowly ramping, or instantaneously set.

Properties
  • unit: V

  • value: Numbers -8.0<=v<=8.0

spi_rack_module1_dac0.span

Sets the max range of the DACs. Possible values: ‘range_4V_uni’: 0 - 4 V, ‘range_8V_uni’: 0 - 8 V (only if non-standard 12 V power supply is present), ‘range_4V_bi’: -4 - 4 V, ‘range_8V_bi’: -8 - 8 V (only if non-standard 12 V power supply is present), ‘range_2V_bi’: -2 - 2 V.

Properties
  • value: Enum: {‘range_8V_bi’, ‘range_4V_bi’, ‘range_4V_uni’, ‘range_2V_bi’, ‘range_8V_uni’}

spi_rack_module1_dac0.ramp_rate

Limits the rate at which currents can be changed. The size of of steps is still limited by ramp_max_step.

Properties
  • unit: V/s

  • value: on

spi_rack_module1_dac0.ramp_max_step

Sets the maximum step size for voltage ramping. The rate at which it ramps is set by ramp_rate.

Properties
  • unit: V

  • value: on

spi_rack_module1_dac0.ramping_enabled

Turns ramping on or off. Toggling ramping_enabled changed the behavior of the setter for the current parameter. If enabled, ramping is done at a rate set by ramp_rate and in steps specified by ramp_max_step.

Properties
  • value: Boolean

spi_rack_module1_dac0.is_ramping

Returns whether the dac is currently in the process of ramping.

Properties
  • value: on

spi_rack_module1_dac0.stepsize

Returns the smallest current step allowed by the dac for the current settings.

Properties
  • unit: V

  • value: on

spi_rack_module1_dac0.dac_channel

Returns the dac number of this channel.

Properties
  • value: on