stoner_measurement.instruments.transport.null_transport.NullTransport

class stoner_measurement.instruments.transport.null_transport.NullTransport(responses: list[bytes] | None = None, timeout: float = 2.0)[source]

Bases: BaseTransport

Loopback transport for simulation and unit testing.

write() appends bytes to write_log. read() returns the next entry from the responses queue provided at construction time. When the queue is exhausted read() returns b"".

Variables:
  • write_log (list[bytes]) – All data written via write() since the transport was created.

  • timeout (float) – Nominal timeout (not actually enforced). Defaults to 2.0.

Examples

>>> from stoner_measurement.instruments.transport import NullTransport
>>> t = NullTransport(responses=[b"+0.123\n"])
>>> t.open()
>>> t.write(b"MEAS:VOLT?\n")
>>> t.read_until(b"\n")
b'+0.123\n'
>>> t.write_log
[b'MEAS:VOLT?\n']
>>> t.close()
clear_log() → None[source]

Clear the write log and any pending responses.

Examples

>>> from stoner_measurement.instruments.transport import NullTransport
>>> t = NullTransport(responses=[b"data\n"])
>>> t.open()
>>> t.write(b"CMD\n")
>>> t.clear_log()
>>> t.write_log
[]
>>> t.close()
close() → None[source]

Mark the transport as closed.

open() → None[source]

Mark the transport as open.

queue_response(response: bytes) → None[source]

Append response to the end of the response queue.

Useful when building up a sequence of expected replies during a test.

Parameters:

response (bytes) – Bytes to add to the response queue.

Examples

>>> from stoner_measurement.instruments.transport import NullTransport
>>> t = NullTransport()
>>> t.open()
>>> t.queue_response(b"OK\n")
>>> t.read_until()
b'OK\n'
>>> t.close()
read(num_bytes: int | None = None) → bytes[source]

Return the next pre-loaded response, or b"" when exhausted.

Parameters:

num_bytes (int | None) – Ignored; present for interface compatibility.

Returns:

Next response from the queue, or b"" if the queue is empty.

Return type:

(bytes)

Raises:

ConnectionError – If the transport has not been opened.

read_status_byte() → int[source]

Return a clear IEEE 488.2 status byte for simulated links.

Returns:

Always 0x00 to indicate that no event status bits are set.

Return type:

(int)

read_until(terminator: bytes = b'\n') → bytes[source]

Return the next pre-loaded response regardless of terminator.

Parameters:

terminator (bytes) – Ignored; present for interface compatibility.

Returns:

Next response from the queue, or b"" if exhausted.

Return type:

(bytes)

Raises:

ConnectionError – If the transport has not been opened.

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

Record data in write_log.

Parameters:

data (bytes) – Bytes to record.

Raises:

ConnectionError – If the transport has not been opened.