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:
BaseTransportLoopback transport for simulation and unit testing.
write()appends bytes towrite_log.read()returns the next entry from the responses queue provided at construction time. When the queue is exhaustedread()returnsb"".- Variables:
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()
- 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
0x00to 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.