msl.equipment.connection_gpib module

Base class for equipment that is connected through GPIB.

msl.equipment.connection_gpib.find_listeners(include_sad: bool = True) list[str][source]

Find GPIB listeners.

Parameters:

include_sad – Whether to scan all secondary GPIB addresses.

Returns:

The GPIB addresses that were found.

class msl.equipment.connection_gpib.ConnectionGPIB(record: EquipmentRecord)[source]

Bases: ConnectionMessageBased

Base class for equipment that is connected through GPIB.

The properties for a GPIB connection supports the following key-value pairs in the Connections Database:

'encoding': str, the encoding to use [default: 'utf-8']
'encoding_errors': str, encoding error handling scheme, e.g. 'strict', 'ignore' [default: 'strict']
'eos_mode': int, the end-of-string mode [default: 0]
'max_read_size': int, the maximum number of bytes that can be read [default: 1 MB]
'read_termination': str or None, read until this termination sequence is found [default: None]
'rstrip': bool, whether to remove trailing whitespace from "read" messages [default: False]
'send_eoi': bool, enables or disables the assertion of the EOI signal [default: True]
'termination': shortcut for setting both 'read_termination' and 'write_termination' to this value
'timeout': float or None, the timeout (in seconds) for read and write operations [default: None]
'write_termination': str or None, termination sequence appended to write messages [default: '\r\n']

The backend value must be equal to MSL to use this class for the communication system. This is achieved by setting the value in the Backend field for a connection record in the Connections Database to be MSL.

Do not instantiate this class directly. Use the connect() method to connect to the equipment.

Parameters:

record – A record from an Equipment-Register Database.

ask(option: int, *, handle: int | None = None) int[source]

Get a configuration setting (board or device).

This method is the ibask function, it should not be confused with the query() method.

Parameters:
  • option – A configuration setting to get the value of.

  • handle – Board or device descriptor. Default is the handle of the instantiated class.

Returns:

The value of the configuration setting.

property board: int

Returns the board index.

clear(*, handle: int | None = None) int[source]

Send the clear command (device).

This method is the ibclr function.

Parameters:

handle – Board or device descriptor. Default is the handle of the instantiated class.

Returns:

The status value (ibsta).

command(data: bytes, *, handle: int | None = None) int[source]

Write command bytes (board).

This method is the ibcmd function.

Parameters:
  • data – The commands to write to the bus.

  • handle – Board or device descriptor. Default is the handle of the instantiated class.

Returns:

The status value (ibsta).

config(option: int, value: int, *, handle: int | None = None) int[source]

Change configuration settings (board or device).

This method is the ibconfig function.

Parameters:
  • option – A configuration setting to change the value of.

  • value – The new configuration setting value.

  • handle – Board or device descriptor. Default is the handle of the instantiated class.

Returns:

The status value (ibsta).

control_atn(state: int, *, handle: int | None = None) int[source]

Set the state of the ATN line (board).

This method mimics the PyVISA-py implementation.

Parameters:
  • state

    The state of the ATN line or the active controller.

    Allowed values are:

    • 0: ATN_DEASSERT

    • 1: ATN_ASSERT

    • 2: ATN_DEASSERT_HANDSHAKE

    • 3: ATN_ASSERT_IMMEDIATE

  • handle – Board or device descriptor. Default is the handle of the instantiated class.

Returns:

The status value (ibsta).

control_ren(state: int, *, handle: int | None = None) int[source]

Controls the state of the GPIB Remote Enable (REN) interface line.

Optionally the remote/local state of the device is also controlled.

This method mimics the PyVISA-py implementation.

Parameters:
  • state

    Specifies the state of the REN line and optionally the device remote/local state.

    Allowed values are:

    • 0: REN_DEASSERT

    • 1: REN_ASSERT

    • 2: REN_DEASSERT_GTL

    • 3: REN_ASSERT_ADDRESS

    • 4: REN_ASSERT_LLO

    • 5: REN_ASSERT_ADDRESS_LLO

    • 6: REN_ADDRESS_GTL

  • handle – Board or device descriptor. Default is the handle of the instantiated class.

Returns:

The status value (ibsta).

count() int[source]

Get the number of bytes sent or received.

This method is the ibcntl function.

disconnect() None[source]

Close the GPIB connection.

property handle: int

Returns the handle of the instantiated board or device.

interface_clear(*, handle: int | None = None) int[source]

Perform interface clear (board).

Resets the GPIB bus by asserting the interface clear (IFC) bus line for a duration of at least 100 microseconds.

This method is the ibsic function.

Parameters:

handle – Board or device descriptor. Default is the handle of the instantiated class.

Returns:

The status value (ibsta).

property library_path: str

Returns the path to the GPIB library.

lines(*, handle: int | None = None) int[source]

Returns the status of the control and handshaking bus lines (board).

This method is the iblines function.

Parameters:

handle – Board or device descriptor. Default is the handle of the instantiated class.

listener(pad: int, sad: int = 0, *, handle: int | None = None) bool[source]

Check if a listener is present (board or device).

This method is the ibln function.

Parameters:
  • pad – Primary address of the GPIB device.

  • sad – Secondary address of the GPIB device.

  • handle – Board or device descriptor. Default is the handle of the instantiated class.

Returns:

Whether a listener is present.

local(*, handle: int | None = None) int[source]

Go to local mode (board or device).

This method is the ibloc function.

Parameters:

handle – Board or device descriptor. Default is the handle of the instantiated class.

Returns:

The status value (ibsta).

online(value: bool, *, handle: int | None = None) int[source]

Close or reinitialize descriptor (board or device).

This method is the ibonl function.

If you want to close the connection for the GPIB board or device that was instantiated, use disconnect().

Parameters:
  • value – If False, closes the connection. If True, then all settings associated with the descriptor (GPIB address, end-of-string mode, timeout, etc.) are reset to their default values. The default values are the settings the descriptor had when it was first obtained.

  • handle – Board or device descriptor. Default is the handle of the instantiated class.

Returns:

The status value (ibsta).

property name: str | None

Returns the name of the board or device or None if a name was not specified in the address.

static parse_address(address: str) dict | None[source]

Get the board, interface name, primary address and secondary address.

Parameters:

address – The address of a ConnectionRecord

Returns:

The information about the GPIB connection or None if address is not valid for a GPIB interface.

pass_control(*, handle: int | None = None, name: str | None = None, board: int | None = None, pad: int = 0, sad: int = 65535) int[source]

Set a GPIB board or device to become the controller-in-charge (CIC).

This method is the ibpct function.

If no arguments are specified, the instantiated class becomes the CIC.

Parameters:
  • handle – Board or device descriptor. If specified, name, board, pad and sad are ignored.

  • name – The name of a GPIB board or device. If specified, board, pad and sad are ignored.

  • board – Index of the GPIB interface board.

  • pad – Primary address of the GPIB device.

  • sad – Secondary address of the GPIB device.

Returns:

The handle of the board or device that became CIC.

property primary_address: int | None

Returns the primary address of the GPIB device or None if a primary address was not specified in the address.

property read_termination: bytes | None

The termination character sequence that is used for the read() method.

By default, reading stops when the EOI line is asserted.

remote_enable(value: bool, *, handle: int | None = None) int[source]

Set remote enable (board).

This method is the ibsre function.

Parameters:
  • value – If True, the board asserts the REN line. Otherwise, the REN line is unasserted. The board must be the system controller.

  • handle – Board or device descriptor. Default is the handle of the instantiated class.

Returns:

The status value (ibsta).

property secondary_address: int | None

Returns the secondary address of the GPIB device.

serial_poll(*, handle: int | None = None) int[source]

Read status byte / serial poll (device).

This method is the ibrsp function.

Parameters:

handle – Board or device descriptor. Default is the handle of the instantiated class.

Returns:

The status byte.

spoll_bytes(*, handle: int | None = None) int[source]

Get the length of the serial poll bytes queue (device).

This method is the ibspb function.

Parameters:

handle – Board or device descriptor. Default is the handle of the instantiated class.

status() int[source]

Returns the status value (ibsta).

trigger(*, handle: int | None = None) int[source]

Trigger device.

This method is the ibtrg function.

Parameters:

handle – Board or device descriptor. Default is the handle of the instantiated class.

Returns:

The status value (ibsta).

version() str[source]

Returns the version of the GPIB library (linux).

wait(mask: int, *, handle: int | None = None) int[source]

Wait for an event (board or device).

This method is the ibwait function.

Parameters:
  • mask – Wait until one of the conditions specified in mask is true.

  • handle – Board or device descriptor. Default is the handle of the instantiated class.

Returns:

The status value (ibsta).

wait_for_srq(*, handle: int | None = None) int[source]

Wait for the SRQ line to be asserted (board or device).

Parameters:

handle – Board or device descriptor. Default is the handle of the instantiated class.

Returns:

The status value (ibsta).

write_async(message: bytes, *, handle: int | None = None) int[source]

Write a message asynchronously (board or device).

This method is the ibwrta function.

Parameters:
  • message – The data to send.

  • handle – Board or device descriptor. Default is the handle of the instantiated class.

Returns:

The status value (ibsta).