pub struct ExplicitSession { /* private fields */ }Expand description
An active explicit-messaging EtherNet/IP session for a single target address.
Construct with ExplicitSession::connect, use it for tag reads and writes, and call
ExplicitSession::close to unregister the session when finished. Dropping
ExplicitSession only drops the underlying transport; it does not perform the async
unregister handshake. Some transient protocol failures are retried by the backend before an
operation returns; retryable errors that still escape mark the client disconnected so the next
operation reconnects automatically.
The session keeps the original target address and route path separate from the active backend client. Retryable transport failures drop only the client; the next operation recreates it from the saved connection identity.
Implementations§
Source§impl ExplicitSession
impl ExplicitSession
Sourcepub async fn connect(addr: &str) -> Result<Self>
pub async fn connect(addr: &str) -> Result<Self>
Connect to an EtherNet/IP endpoint and register a session.
addr must be parseable as a std::net::SocketAddr (for example "192.168.1.10:44818" or
"[::1]:44818"). Hostnames such as "plc.local:44818" are not resolved here.
Note that this implicitly registers a session with the target device on success.
Sourcepub async fn connect_with_route_path_slots(
addr: &str,
slots: &[u8],
) -> Result<Self>
pub async fn connect_with_route_path_slots( addr: &str, slots: &[u8], ) -> Result<Self>
Connect to an EtherNet/IP endpoint through a backplane route path.
The supplied slots are added to rust-ethernet-ip’s route path in order using
RoutePath::add_slot. This follows the upstream route-path surface exactly: all slot hops
are encoded before any future network hops.
Sourcepub async fn read_tag_struct<T>(&mut self, tag_name: &str) -> Result<T>
pub async fn read_tag_struct<T>(&mut self, tag_name: &str) -> Result<T>
Read a structured tag and decode it into a caller-owned type.
This is a convenience wrapper around ExplicitSession::read_tag for tags backed by
user-defined types. Callers provide a TryFrom implementation from
StructuredValue.
Read several tags in a single batch request, preserving input order in the returned list.
Tag reads are sent to the PLC as a CIP Multiple Service Packet via the upstream batch API, which is significantly more efficient than issuing N separate reads. The upstream driver transparently chunks the request when the tag list exceeds packet limits.
The outer Result reports transport-level failures (the whole batch could not be
dispatched or its response could not be parsed). On success, the returned list contains
one entry per requested tag in input order, with a per-tag Result so partial failures
are first-class — a missing or type-mismatched tag does not prevent the other tags from
being returned. Per-tag errors are wrapped as Error::BatchReadItem, whose typed
BatchReadError source preserves the upstream variant (tag-not-found, type mismatch,
CIP error, etc.) for caller branching.
Sourcepub async fn write_tag(&mut self, tag_name: &str, value: Value) -> Result<()>
pub async fn write_tag(&mut self, tag_name: &str, value: Value) -> Result<()>
Write a user-facing Value to a PLC tag.
Sourcepub async fn write_tag_struct<T>(
&mut self,
tag_name: &str,
value: T,
) -> Result<()>where
T: Into<StructuredValue>,
pub async fn write_tag_struct<T>(
&mut self,
tag_name: &str,
value: T,
) -> Result<()>where
T: Into<StructuredValue>,
Encode a caller-owned type into a StructuredValue and write it to a tag.
This is a convenience wrapper around ExplicitSession::write_tag for structured PLC
payloads. Callers provide an Into conversion to StructuredValue.
Sourcepub async fn close(self) -> Result<()>
pub async fn close(self) -> Result<()>
Unregister the explicit EtherNet/IP session.
Call this before dropping ExplicitSession when you want graceful protocol-level
cleanup.
If unregister fails, self is still consumed and the caller cannot retry; that is
acceptable here because the underlying connection is likely already broken anyway.