IEEE488.2#

Every SCPI interface is based on the IEEE488.2 protocol. This Python implementation separates the protocol into two layers:

  • IEEE488.2 layer: IEEE488.2 layer that implements the protocol based on the transport layer.

  • Transport layer: Transport layers responsible for lowest level of communication (e.g. Ethernet or dummy).”

IEEE488.2 layer#

class Ieee488_2(transport, debug=DebugLevel.MINIMAL_CHECK)[source]#

Bases: object

Class that implements the IEEE488.2 interface.

__init__(transport, debug=DebugLevel.MINIMAL_CHECK)[source]#

Creates IEEE488.2 interface object.

Parameters:
  • transport (Transport) – Transport class responsible for the lowest level of communication (e.g. ethernet).

  • debug (DebugLevel (default: <DebugLevel.MINIMAL_CHECK: 0>)) – Debug level. See DebugLevel for more information. By default None, which means that for a connection to a dummy cluster, DebugLevel.ERROR_CHECK will be used, and for a real cluster, DebugLevel.MINIMAL_CHECK.

clear()#

Clear all status and event registers (see SCPI).

Parameters:

None

Return type:

None

Returns:

None

Raises:
  • Exception – Invalid input parameter type.

  • Exception – An error is reported in system error and debug <= 1.

async close()[source]#

Close the connection to the instrument. It can not be used afterwards.

Return type:

None

fast_error_check(*raw_data)#

Inspects raw SCPI responses for firmware error sentinels. Triggers a full error queue check if a sentinel is detected.

Parameters:

*raw_data (Any) – The raw response data returned from the SCPI read operation. Accepts multiple arguments if a command returns multiple variables.

Raises:

RuntimeError – An error was found in the system error queue after a sentinel was detected.

Return type:

None

get_operation_complete()#

Get operation complete state.

Parameters:

None

Return type:

bool

Returns:

bool Operation complete state (False = running, True = completed).

Raises:

Exception – An error is reported in system error and debug <= 1.

get_service_request_enable()#

Get service request enable register. The register is cleared after reading it.

Parameters:

None

Return type:

int

Returns:

int Service request enable register.

Raises:

Exception – An error is reported in system error and debug <= 1.

get_standard_event_status()#

Get standard event status register. The register is cleared after reading it.

Parameters:

None

Return type:

int

Returns:

int Standard event status register.

Raises:

Exception – An error is reported in system error and debug <= 1.

get_standard_event_status_enable()#

Get standard event status enable register. The register is cleared after reading it.

Parameters:

None

Return type:

int

Returns:

int Standard event status enable register.

Raises:

Exception – An error is reported in system error and debug <= 1. All errors are read from system error and listed in the exception.

get_status_byte()#

Get status byte register. Register is only cleared when feeding registers are cleared.

Parameters:

None

Return type:

int

Returns:

int Status byte register.

Raises:

Exception – An error is reported in system error and debug <= 1.

reconnect()[source]#

Close and re-open the connection to instrument.

Return type:

None

set_operation_complete()#

Set device in operation complete query active state.

Parameters:

None

Return type:

None

Returns:

None

Raises:

Exception – An error is reported in system error and debug <= 1.

set_service_request_enable(reg)#

Set service request enable register.

Parameters:

reg (int) – Service request enable register.

Return type:

None

Returns:

None

Raises:
  • Exception – Invalid input parameter type.

  • Exception – An error is reported in system error and debug <= 1.

set_standard_event_status_enable(reg)#

Set standard event status enable register.

Parameters:

reg (int) – Standard event status enable register.

Return type:

None

Returns:

None

Raises:
  • Exception – Invalid input parameter type.

  • Exception – An error is reported in system error and debug <= 1.

test()#

Run self-test.

Parameters:

None

Return type:

bool

Returns:

bool Test result (False = failed, True = success).

Raises:

Exception – An error is reported in system error and debug <= 1.

wait()#

Wait until operations completed before continuing.

Parameters:

None

Return type:

None

Returns:

None

Raises:

Exception – An error is reported in system error and debug <= 1.

Transport layer#

class IpTransport(host, port=5025, timeout=60.0, snd_buf_size=524288, loop_from=None, use_running_loop=False)[source]#

Bases: Transport

Class for data transport of IP socket.

__init__(host, port=5025, timeout=60.0, snd_buf_size=524288, loop_from=None, use_running_loop=False)[source]#

Create IP socket transport class.

Parameters:
  • host (str) – Instrument IP address.

  • port (int (default: 5025)) – Instrument port.

  • timeout (float (default: 60.0)) – Instrument call timeout in seconds.

  • snd_buf_size (int (default: 524288)) – Instrument buffer size for transmissions to instrument.

  • loop_from (Transport | None (default: None)) – Transport to use event loop from: bypasses use_running_loop checks.

  • use_running_loop (bool (default: False)) – Whether to use an existing event loop if it is already running; use this only if you are supplying your own event loop and only invoking asynchronous functions, or if the event loop is not running when invoking synchronous command functions. Default to False.

async close()[source]#

Close IP socket.

Return type:

None

async read_binary(size)[source]#

Read binary data from instrument over IP socket.

Parameters:

size (int) – Number of bytes

Return type:

bytes

Returns:

bytes Binary data array of length “size”.

async readline()[source]#

Read data from instrument over IP socket.

Return type:

str

Returns:

str String with data.

reconnect()[source]#

Re-open IP connection to instrument.

Return type:

None

async write(cmd_str)[source]#

Write command to instrument over IP socket.

Parameters:

cmd_str (str) – Command

Return type:

None

async write_binary(*data)[source]#

Write binary data to instrument over IP socket.

Parameters:

*data (bytes) – Binary data

Return type:

None

property host: str#

Get host this socket is connected to.

Returns:

str Current host this socket is connected to.

property timeout: float#

Get current socket timeout.

Returns:

float Current socket timeout in seconds.

class ClusterDummyTransport(dummy_cfg, loop_from=None, use_running_loop=False)[source]#

Bases: DummyTransport

Class to replace Cluster device with dummy device to support software stack testing without hardware. The class implements all mandatory, required and Cluster specific SCPI calls. Call responses are largely artificially constructed to be inline with the call’s functionality (e.g. *IDN? returns valid, but artificial IDN data). To assist development, the Q1ASM assembler has been completely implemented. Please have a look at the call’s implementation to know what to expect from its response.

__init__(dummy_cfg, loop_from=None, use_running_loop=False)[source]#

Create Cluster dummy transport class.

Parameters:
  • dummy_cfg (DummyConfiguration | dict[str | int, ClusterType]) – Dictionary of dummy module types (e.g. Cluster QCM, Cluster QRM). Each key of the dictionary is a slot index with a dummy type specification of type ClusterType.

  • loop_from (Transport | None (default: None)) – Transport to use event loop from: bypasses use_running_loop checks.

  • use_running_loop (bool (default: False)) – Whether to use an existing event loop if it is already running; use this only if you are supplying your own event loop and only invoking asynchronous functions, or if the event loop is not running when invoking synchronous command functions. Default to False.

async close()[source]#

Close and resets Cluster dummy transport class.

Return type:

None

delete_dummy_binned_acquisition_data(slot_idx, sequencer=None, acq_index_name=None)[source]#

Delete all dummy binned acquisition data for the dummy.

Parameters:
  • slot_idx (int) – Slot of the hardware you want to set the data to on a cluster.

  • sequencer (int | None (default: None)) – Sequencer.

  • acq_index_name (str | None (default: None)) – Acquisition index name.

Return type:

None

delete_dummy_scope_acquisition_data(slot_idx)[source]#

Delete dummy scope acquisition data for the dummy.

Parameters:

slot_idx (int) – Slot of the hardware you want to set the data to on a cluster.

Return type:

None

get_module_transport(slot_idx)[source]#

Get transport for individual module.

Parameters:

slot_idx (int) – Slot index for module to obtain transport of

Return type:

ModuleDummyTransport

Returns:

ModuleDummyTransport Transport for the module

Raises:

KeyError – Module is not available.

reset()[source]#

Resets Cluster dummy transport class.

Return type:

None

set_dummy_binned_acquisition_data(slot_idx, sequencer, acq_index_name, data)[source]#

Set dummy binned acquisition data for the dummy.

Parameters:
  • slot_idx (int) – Slot of the hardware you want to set the data to on a cluster.

  • sequencer (int) – Sequencer.

  • acq_index_name (str) – Acquisition index name.

  • data (Iterable[DummyBinnedAcquisitionData | None]) – Dummy data for the binned acquisition. An iterable of all the bin values.

Return type:

None

set_dummy_scope_acquisition_data(slot_idx, data)[source]#

Set dummy scope acquisition data for the dummy.

Parameters:
  • slot_idx (int) – Slot of the hardware you want to set the data to on a cluster.

  • data (DummyScopeAcquisitionData) – Dummy data for the scope acquisition.

Return type:

None

Supporting classes and functions#

class ModuleDummyTransport(dummy_type, loop_from=None, use_running_loop=False)[source]#

Bases: DummyTransport

Class to replace a module with a dummy device to support software stack testing without hardware. The class implements all mandatory, required and module specific SCPI calls. Call responses are largely artificially constructed to be inline with the call’s functionality (e.g. *IDN? returns valid, but artificial IDN data). To assist development, the Q1ASM assembler has been completely implemented. Please have a look at the call’s implementation to know what to expect from its response.

__init__(dummy_type, loop_from=None, use_running_loop=False)[source]#

Create module dummy transport class.

Parameters:
  • dummy_type (ClusterType) – Dummy module type

  • loop_from (Transport | None (default: None)) – Transport to use event loop from: bypasses use_running_loop checks.

  • use_running_loop (bool (default: False)) – Whether to use an existing event loop if it is already running; use this only if you are supplying your own event loop and only invoking asynchronous functions, or if the event loop is not running when invoking synchronous command functions. Default to False.

delete_dummy_binned_acquisition_data(sequencer=None, acq_index_name=None)[source]#

Set dummy binned acquisition data for the dummy.

Parameters:
  • sequencer (int | None (default: None)) – Sequencer.

  • acq_index_name (str | None (default: None)) – Acquisition index name.

Return type:

None

delete_dummy_scope_acquisition_data()[source]#

Delete dummy scope acquisition data for the dummy.

Return type:

None

reset()[source]#

Resets module dummy transport class.

Return type:

None

set_dummy_binned_acquisition_data(sequencer, acq_index_name, data)[source]#

Set dummy binned acquisition data for the dummy.

Parameters:
Return type:

None

set_dummy_scope_acquisition_data(data)[source]#

Set dummy scope acquisition data for the dummy.

Parameters:

data (DummyScopeAcquisitionData) – Dummy data for the scope acquisition.

Return type:

None

property is_eom_type: bool#

Return if module is of type EOM.

Returns:

bool True if module is of type EOM.

property is_linq_type: bool#

Return if module is of type LINQ.

Returns:

bool True if module is of type LINQ.

property is_qcm_type: bool#

Return if module is of type QCM.

Returns:

bool True if module is of type QCM.

property is_qdm_type: bool#

Return if module is of type QDM.

Returns:

bool True if module is of type QDM.

property is_qrc_type: bool#

Return if module is of type QRC.

Returns:

bool True if module is of type QRC.

property is_qrm_type: bool#

Return if module is of type QRM.

Returns:

bool True if module is of type QRM.

property is_qsm_type: bool#

Return if module is of type QSM.

Returns:

bool True if module is of type QSM.

property is_qtm_type: bool#

Return if module is of type QTM.

Returns:

bool True if module is of type QTM.

property is_rf_type: bool#

Return if module is of type QCM-RF or QRM-RF.

Returns:

bool True if module is of type QCM-RF or QRM-RF.

property module_type: InstrumentType#

Return module type.

Returns:

InstrumentType Module type.

class DummyTransport(dummy_type, sw_scpi_version=(1, 2), loop_from=None, use_running_loop=False)[source]#

Bases: ABC, Transport

Class to replace device with dummy device to support software stack testing without hardware. The class implements all mandatory and required SCPI calls. Call responses are largely artificially constructed to be inline with the call’s functionality (e.g. *IDN? returns valid, but artificial IDN data).

__init__(dummy_type, sw_scpi_version=(1, 2), loop_from=None, use_running_loop=False)[source]#

Create dummy transport class.

Parameters:
  • dummy_type (ClusterType) – Dummy instrument type

  • sw_scpi_version (tuple[int, ...] (default: (1, 2))) – SCPI layer version.

  • loop_from (Transport | None (default: None)) – Transport to use event loop from: bypasses use_running_loop checks.

  • use_running_loop (bool (default: False)) – Whether to use an existing event loop if it is already running; use this only if you are supplying your own event loop and only invoking asynchronous functions, or if the event loop is not running when invoking synchronous command functions. Default to False.

async close()[source]#

Close and resets base dummy transport class.

Return type:

None

abstractmethod delete_dummy_binned_acquisition_data(sequencer=None, acq_index_name=None)[source]#

Delete all dummy binned acquisition data for the dummy.

Parameters:
  • sequencer (int | None (default: None)) – Sequencer.

  • acq_index_name (str | None (default: None)) – Acquisition index name.

Raises:

ValueError – If the slot_idx doesn’t make sense for the transport.

Return type:

None

abstractmethod delete_dummy_scope_acquisition_data()[source]#

Delete dummy scope acquisition data for the dummy.

Raises:

ValueError – If the slot_idx doesn’t make sense for the transport.

Return type:

None

get_cmd_hist()[source]#

Get list of every executed command since the initialization or reset of the class.

Return type:

list[str]

Returns:

list : str List of executed command strings including arguments (does not include binary data argument).

async read_binary(size)[source]#

Read binary data from dummy.

Parameters:

size (int) – Number of bytes

Return type:

bytes

Returns:

bytes Binary data array of length “size”.

async readline()[source]#

Read data from dummy.

Return type:

str

Returns:

str String with data.

reconnect()[source]#

Closes the connection.

Return type:

None

reset()[source]#

Resets base dummy transport class.

Return type:

None

abstractmethod set_dummy_binned_acquisition_data(sequencer, acq_index_name, data)[source]#

Set dummy binned acquisition data for the dummy.

Parameters:
Raises:

ValueError – If the slot_idx doesn’t make sense for the transport.

Return type:

None

abstractmethod set_dummy_scope_acquisition_data(data)[source]#

Set dummy scope acquisition data for the dummy.

Parameters:

data (DummyScopeAcquisitionData) – Dummy data for the scope acquisition.

Raises:

ValueError – If the slot_idx doesn’t make sense for the transport.

Return type:

None

async write(cmd_str)[source]#

Write command to dummy. Stores command in command history.

Parameters:

cmd_str (str) – Command

Return type:

None

async write_binary(*data)[source]#

Write binary data to dummy. Stores command in command history.

Parameters:

*data (bytes) – Binary data

Return type:

None

property instrument_class: str#

Get instrument class (e.g. Cluster).

Returns:

str Instrument class

property instrument_type: str#

Get instrument type (e.g. MM, QRM, QCM).

Returns:

str Instrument type

property timeout: float#

Get current dummy timeout.

Returns:

float Current socket timeout in seconds.

class Transport(loop_from=None, use_running_loop=False)[source]#

Bases: object

Abstract base class for data transport to instruments.

__init__(loop_from=None, use_running_loop=False)[source]#

Create transport instance.

Parameters:
  • loop_from (Transport | None (default: None)) – Transport to use event loop from: bypasses use_running_loop checks.

  • use_running_loop (bool (default: False)) – Whether to use an existing event loop if it is already running; use this only if you are supplying your own event loop and only invoking asynchronous functions, or if the event loop is not running when invoking synchronous command functions. Default to False.

abstractmethod async close()[source]#

Abstract method to close instrument.

Return type:

None

abstractmethod async read_binary(size)[source]#

Abstract method to read binary data from instrument.

Parameters:

size (int) – Number of bytes

Return type:

bytes

Returns:

bytes Binary data array of length “size”.

abstractmethod async readline()[source]#

Abstract method to read data from instrument.

Return type:

str

Returns:

str String with data.

abstractmethod reconnect()[source]#

Close and re-open connection to instrument.

Return type:

None

abstractmethod async write(cmd_str)[source]#

Abstract method to write command to instrument.

Parameters:

cmd_str (str) – Command

Return type:

None

abstractmethod async write_binary(*data)[source]#

Abstract method to write binary data to instrument.

Parameters:

*data (bytes) – Binary data

Return type:

None

property loop: BaseEventLoop#

Event loop for this transport.

abstract property timeout: float#

Timeout for this transport.

class DummyBinnedAcquisitionData(data, thres, avg_cnt)[source]#

Bases: object

Class to hold data for the dummy hardware for the binned acquisition. This class contains all values for one bin.

__init__(data, thres, avg_cnt)#
avg_cnt: int#
data: tuple[float, float]#
thres: int#
class DummyScopeAcquisitionData(data, out_of_range, avg_cnt)[source]#

Bases: object

Class to hold data for the dummy hardware for the scope acquisition. This class contains all values for the scope acquisition on one module.

__init__(data, out_of_range, avg_cnt)#
avg_cnt: tuple[int, int]#
data: Iterable[tuple[float, float]]#
out_of_range: tuple[bool, bool]#