Skip to main content

ExplicitSession

Struct ExplicitSession 

Source
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

Source

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.

Source

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.

Source

pub async fn read_tag(&mut self, tag_name: &str) -> Result<Value>

Read a Value for a tag.

Source

pub async fn read_tag_struct<T>(&mut self, tag_name: &str) -> Result<T>
where T: TryFrom<StructuredValue>, T::Error: Error + Send + Sync + 'static,

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.

Source

pub async fn read_tags<S>( &mut self, tag_names: &[S], ) -> Result<Vec<(String, Result<Value>)>>
where S: AsRef<str>,

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.

Source

pub async fn write_tag(&mut self, tag_name: &str, value: Value) -> Result<()>

Write a user-facing Value to a PLC tag.

Source

pub async fn write_tag_struct<T>( &mut self, tag_name: &str, value: T, ) -> Result<()>

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.

Source

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.

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more