stoner_measurement.instruments.transport.gpib_transport.GpibTransport

class stoner_measurement.instruments.transport.gpib_transport.GpibTransport(address: int, board: int = 0, timeout: float = 2.0, use_mav: bool = True, poll_time: float = 0.01, command_complete_mask: int | None = None, secondary_address: int | None = None)[source]

Bases: BaseTransport

GPIB transport using PyVISA.

Wraps a PyVISA GPIBInstrument resource to provide the standard BaseTransport interface. The VISA resource string is constructed as GPIB<board>::<address>[::<secondary_address>]::INSTR.

Variables:
  • address (int) – GPIB primary address of the instrument (0–30).

  • board (int) – GPIB board (interface) index. Defaults to 0.

  • secondary_address (int | None) – Secondary address (0–30), or None when not used. Zero is a real secondary address and is distinct from None.

  • timeout (float) – Read timeout in seconds. Defaults to 2.0.

Examples

>>> from stoner_measurement.instruments.transport import GpibTransport
>>> t = GpibTransport(address=22)
>>> t.address
22
>>> t.board
0
>>> t.resource_string
'GPIB0::22::INSTR'
close() → None[source]

Close this transport’s GPIB resource.

PyVISA shares one ResourceManager between instances. Closing that manager here would also close resources owned by other active transports, so its process-level lifetime is left to PyVISA.

flush() → None[source]

Send IEEE 488.2 Device Clear to the instrument and reset the interface.

Calls the PyVISA clear() method, which sends the Selected Device Clear (SDC) message over the GPIB bus. This resets the instrument’s parser and discards any bytes queued in its output buffer, preventing stale responses from old commands being misread after a reconnect.

If the resource is not open or Device Clear fails, the exception is ignored and logged at debug level.

classmethod from_resource_string(resource_string: str, timeout: float = 2.0, use_mav: bool = True, poll_time: float = 0.01, command_complete_mask: int | None = None) → GpibTransport[source]

Construct a GpibTransport from a VISA resource string.

Parses GPIB[board]::primary[::secondary][::INSTR]. An omitted board defaults to zero; an omitted secondary address means none.

Parameters:

resource_string (str) – VISA resource string, e.g. "GPIB0::22::INSTR".

Keyword Parameters:

timeout (float) – Read timeout in seconds. Defaults to 2.0.

Returns:

A new GpibTransport instance.

Return type:

(GpibTransport)

Raises:
  • ValueError – If resource_string does not match the expected GPIB format.

  • ImportError – If pyvisa is not installed.

Examples

>>> from stoner_measurement.instruments.transport import GpibTransport
>>> t = GpibTransport.from_resource_string("GPIB0::14::INSTR")
>>> t.address
14
>>> t.board
0
>>> t.resource_string
'GPIB0::14::INSTR'
open() → None[source]

Open the GPIB resource via PyVISA.

Raises:

ConnectionError – If the resource cannot be opened.

read(num_bytes: int | None = None) → bytes[source]

Read one response frame from the GPIB instrument.

Keyword Arguments:

num_bytes (int | None, None) – Optional maximum frame size for this call. When None, the transport uses the protocol-defined frame-size limit.

Returns:

Bytes received.

Return type:

(bytes)

Raises:
read_status_byte() → int | None[source]

Return the IEEE 488.2 status byte via a GPIB serial poll.

Performs an out-of-band serial poll (PyVISA read_stb()) without transmitting any command to the instrument. This is the preferred mechanism for checking the GPIB status byte because it does not consume a response from the instrument’s output buffer.

Returns:

The 8-bit status byte, or None if the transport is not currently open.

Return type:

(int | None)

Examples

>>> from stoner_measurement.instruments.transport import GpibTransport
>>> t = GpibTransport(address=22)
>>> t.read_status_byte() is None  # not open
True
property resource_string: str

VISA resource string for this GPIB address.

Returns:

Canonical VISA string including the secondary address, if set.

Return type:

(str)

Examples

>>> from stoner_measurement.instruments.transport import GpibTransport
>>> GpibTransport(address=14, board=1).resource_string
'GPIB1::14::INSTR'
send_group_execute_trigger() → None[source]

Send an IEEE-488 GET (Group Execute Trigger) for this instrument.

suppress_status_error_check() → Iterator[None][source]

Temporarily disable rejection of writes with the error bit set.

property transport_address: str

Return the VISA resource string for this GPIB instrument.

Returns:

VISA resource string, e.g. "GPIB0::22::INSTR".

Return type:

(str)

Examples

>>> from stoner_measurement.instruments.transport import GpibTransport
>>> GpibTransport(address=22).transport_address
'GPIB0::22::INSTR'
wait_for_srq(timeout: float) → bool | None[source]

Wait for the GPIB service-request line without command polling.

write(data: bytes, slow: int | None = None) → None[source]

Write data to the GPIB instrument.

Parameters:

data (bytes) – Raw bytes to transmit. The bytes are decoded as ASCII before being passed to PyVISA’s write_raw.

Keyword Arguments:

slow (int|none, None) – Whether to except the response to be slow and thus to pause for slow milliseconds.

Raises:

ConnectionError – If the transport is not open.