stoner_measurement.instruments.transport.gpib_transport.PassThroughGpibTransport

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

Bases: GpibTransport

Passthrough Keithley 6221 GPIB transport.

Subclasses a GPIBTransport so that commands are wrapped in the SYST:COMM:SER:[SEND|ENT?] SCPI commands of a Keithley 6221 current source. This is primarily intentended for communicating with an attached Keithley 2182A nanovoltmeter, but could in principle be used for other instruments supports IEEE488.2 common comands.

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

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

  • 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'
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.

query(data: bytes, num_bytes: int | None = None, slow: int | None = False) → bytes[source]

Perform a write and then read operation in series.

Parameters:

data (bytes) – Raw bytes to transmit.

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.

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

Returns:

The bytes received from the instrument.

Return type:

(bytes)

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

Read one response frame from the instrument via the 6221’s SYST:COMM:SER:ENT?.

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 wrapped *STB? query.

Because this is a serial over GPIB transport, this is not an out-of-band operation.

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
write(data: bytes, slow: int | None = None, host=False) → None[source]

Write data to the 6221 wrapping the data in a SYST:COMM:SER:ESEND command.

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.