pub struct StdTcpTransport { /* private fields */ }Expand description
A concrete implementation of ModbusTcpTransport using std::net::TcpStream.
This struct manages a standard TCP connection for Modbus TCP communication.
Implementations§
Trait Implementations§
Source§impl Debug for StdTcpTransport
impl Debug for StdTcpTransport
Source§impl Default for StdTcpTransport
impl Default for StdTcpTransport
Source§fn default() -> StdTcpTransport
fn default() -> StdTcpTransport
Source§impl Transport for StdTcpTransport
impl Transport for StdTcpTransport
Source§fn connect(&mut self, config: &ModbusConfig) -> Result<(), Self::Error>
fn connect(&mut self, config: &ModbusConfig) -> Result<(), Self::Error>
Establishes a TCP connection to the specified remote address.
§Arguments
addr- The address of the Modbus TCP server (e.g., “192.168.1.1:502”).config- TheModbusTcpConfigcontaining the host and port of the Modbus TCP server.
§Returns
Ok(()) if the connection is successfully established, or an error otherwise.
Source§fn disconnect(&mut self) -> Result<(), Self::Error>
fn disconnect(&mut self) -> Result<(), Self::Error>
Closes the active TCP connection.
If no connection is active, this operation does nothing and returns Ok(()).
Source§fn recv(&mut self) -> Result<Vec<u8, MAX_ADU_FRAME_LEN>, Self::Error>
fn recv(&mut self) -> Result<Vec<u8, MAX_ADU_FRAME_LEN>, Self::Error>
Receives available Modbus bytes from the TCP connection.
This implementation performs a single, non-blocking read operation. It retrieves
whatever bytes are currently available in the socket buffer up to the maximum ADU size.
The higher-level Modbus Client Services (ClientServices::ingest_frame) is responsible
for buffering and isolating the complete frames.
§Returns
Ok(Vec<u8, MAX_ADU_FRAME_LEN>) containing the received bytes, or an error otherwise.
Source§fn is_connected(&self) -> bool
fn is_connected(&self) -> bool
Checks if the transport is currently connected to a remote host.
This is a best-effort check and indicates if a TcpStream is currently held.
Source§const TRANSPORT_TYPE: TransportType = TransportType::StdTcp
const TRANSPORT_TYPE: TransportType = TransportType::StdTcp
Source§type Error = TransportError
type Error = TransportError
MbusError for upper-layer processing.