stoner_measurement.instruments.transport.ethernet_transport.EthernetTransport

class stoner_measurement.instruments.transport.ethernet_transport.EthernetTransport(host: str, port: int, timeout: float = 2.0)[source]

Bases: BaseTransport

TCP/IP socket transport for network-connected instruments.

Variables:
  • host (str) – Hostname or IP address of the instrument.

  • port (int) – TCP port number (most instruments use 5025 for SCPI).

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

Examples

>>> from stoner_measurement.instruments.transport import EthernetTransport
>>> t = EthernetTransport(host="192.168.1.100", port=5025)
>>> t.host
'192.168.1.100'
>>> t.port
5025
close() → None[source]

Close the TCP socket.

flush() → None[source]

Drain any unread data from the socket receive buffer.

Temporarily sets the socket to non-blocking mode and discards any data already in the receive buffer.

open() → None[source]

Connect to the instrument over TCP.

Raises:

ConnectionError – If the TCP connection cannot be established.

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

Receive one response frame from the instrument.

Parameters:

num_bytes (int | None) – Optional maximum frame size for this read. When None, the protocol-defined frame-size limit is used.

Returns:

Bytes received from the instrument.

Return type:

(bytes)

Raises:
property transport_address: str

Return the remote endpoint as "<host>:<port>".

Returns:

Ethernet address string, e.g. "192.168.1.100:5025".

Return type:

(str)

Examples

>>> from stoner_measurement.instruments.transport import EthernetTransport
>>> EthernetTransport(host="192.168.1.100", port=5025).transport_address
'192.168.1.100:5025'
write(data: bytes, slow: int | None = None) → int[source]

Send data to the instrument.

Parameters:

data (bytes) – Raw bytes to transmit.

Keyword Arguments:

slow (int | None) – Optional delay in milliseconds to wait after writing.

Raises:

ConnectionError – If the socket is not open.