Skip to main content

StdTcpTransport

Struct StdTcpTransport 

Source
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§

Source§

impl StdTcpTransport

Source

pub fn new() -> Self

Creates a new StdTcpTransport instance.

Initially, there is no active connection.

§Arguments
  • config - The ModbusConfig to use for this transport.
§Returns

A new StdTcpTransport instance with the provided configuration and no active connection.

Trait Implementations§

Source§

impl Debug for StdTcpTransport

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for StdTcpTransport

Source§

fn default() -> StdTcpTransport

Returns the “default value” for a type. Read more
Source§

impl Transport for StdTcpTransport

Source§

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 - The ModbusTcpConfig containing 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>

Closes the active TCP connection.

If no connection is active, this operation does nothing and returns Ok(()).

Source§

fn send(&mut self, adu: &[u8]) -> Result<(), Self::Error>

Sends a Modbus Application Data Unit (ADU) over the TCP connection.

§Arguments
  • adu - The byte slice representing the ADU to send.
§Returns

Ok(()) if the ADU is successfully sent, or an error otherwise.

Source§

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

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

Compile-time transport type metadata. Read more
Source§

type Error = TransportError

The specific error type returned by this transport implementation. It must be convertible into the common MbusError for upper-layer processing.
Source§

const SUPPORTS_BROADCAST_WRITES: bool = false

Compile-time capability flag for Serial-style broadcast write semantics. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.