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:
BaseTransportUDP socket transport for network-connected instruments.
- Variables:
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
- open() None[source]¶
Create a UDP socket and record the default remote address.
socket.connect()is called on the UDP socket so that subsequentsocket.send()andsocket.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:
ConnectionError – If the socket is not open.
TimeoutError – If no datagram arrives within
timeoutseconds.
- 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:
ConnectionError – If the socket is not open.
OSError – If a low-level I/O error occurs.