stoner_measurement.instruments.transport.udp_transport.UdpTransport

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

Bases: BaseTransport

UDP socket transport for network-connected instruments.

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

  • port (int) – UDP port number.

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

Examples

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

Close the UDP socket.

open() → None[source]

Create a UDP socket and record the default remote address.

socket.connect() is called on the UDP socket so that subsequent socket.send() and socket.recv() calls are directed to and filtered from the given host and port without requiring explicit address arguments.

Raises:

ConnectionError – If the socket cannot be created or bound.

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

Receive up to num_bytes from the instrument.

Parameters:

num_bytes (int | None) – Optional maximum number of bytes to read per datagram. 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:

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

Return type:

(str)

Examples

>>> from stoner_measurement.instruments.transport import UdpTransport
>>> UdpTransport(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 as a single UDP datagram.

Parameters:

data (bytes) – Raw bytes to transmit.

Keyword Arguments:

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

Raises: