Session-bound provisioning and low-level configuration API.
Use this module for PREOP-first workflows, direct SDO traffic, and runtime
activation control. Every operation requires the %EtherCAT.Session{} that
owns the target runtime.
PREOP-first workflow
- Supervise
EtherCAT.Runtimeand start a session with a:backendand the domains you will need, but no:slaveslist. - Call
EtherCAT.await_ready/2. Discovery holds devices in PREOP under positional names (:coupler,:slave_1, …); inspectEtherCAT.Diagnostics.slaves/1before choosing a driver. - Use
configure_slave/3to supply a driver, driver config, process-data assignments, andtarget_state: :opfor each device that should activate. Refer only to domain IDs declared at session startup. - Call
activate/1, thenEtherCAT.await_operational/2. Slaves intentionally left withtarget_state: :preopare not promoted to OP. - Inspect status and samples. If activation fails, inspect
EtherCAT.Diagnostics.master_status/1andEtherCAT.Diagnostics.last_failure/1rather than assuming the ring is operational.
To change configuration after activation, first use
deactivate(session, :preop). The default deactivate(session) holds at SAFEOP,
which is not the configuration state. Neither operation ends the session;
EtherCAT.stop/1 does.
Mailbox traffic
SDO uploads return raw binaries. Downloads accept raw binaries; choose the
object width, signedness, and byte order from the device's object dictionary.
For example, given a live session and a mailbox-capable slave named :drive:
{:ok, device_name} = EtherCAT.Provisioning.upload_sdo(session, :drive, 0x1008, 0x00)Mailbox support and allowed AL states are device-specific. An SDO failure is returned explicitly, including protocol and device abort errors. A failed or timed-out write may already have reached the device; do not blindly retry non-idempotent operations. Provisioning and output writes are not a safety stop.
Summary
Functions
Attempt cyclic activation for slaves configured with target_state: :op.
Wait for the session's active DC monitor to report lock; does not enable DC.
Update one slave while the session and the slave are in PREOP.
Stop cyclic runtime and retreat activatable slaves to SAFEOP (default) or PREOP.
Download one non-empty raw binary to a CoE object on a named slave.
Update a domain period in microseconds, using a whole-millisecond value.
Upload one CoE object from a named slave as a raw binary.
Functions
@spec activate(EtherCAT.Session.t()) :: :ok | {:error, term()}
Attempt cyclic activation for slaves configured with target_state: :op.
@spec await_dc_locked(EtherCAT.Session.t(), pos_integer()) :: :ok | {:error, term()}
Wait for the session's active DC monitor to report lock; does not enable DC.
@spec configure_slave( EtherCAT.Session.t(), atom(), keyword() | EtherCAT.Slave.Config.t() ) :: :ok | {:error, term()}
Update one slave while the session and the slave are in PREOP.
Keyword options update the existing configuration; a EtherCAT.Slave.Config
struct supplies a replacement. The name cannot change. Supported fields are
:driver, :config, :process_data, :target_state, :sync, and :health_poll_ms.
Domains must already exist. Layout changes remain subject to PREOP and domain
registration checks; an error is not a request to silently discard mappings.
@spec deactivate(EtherCAT.Session.t(), :safeop | :preop) :: :ok | {:error, term()}
Stop cyclic runtime and retreat activatable slaves to SAFEOP (default) or PREOP.
The session remains live. Check the result and runtime status for incomplete transitions; this API does not replace hardware safety mechanisms.
@spec download_sdo( EtherCAT.Session.t(), atom(), non_neg_integer(), non_neg_integer(), binary() ) :: :ok | {:error, term()}
Download one non-empty raw binary to a CoE object on a named slave.
@spec update_domain_cycle_time(EtherCAT.Session.t(), atom(), pos_integer()) :: :ok | {:error, term()}
Update a domain period in microseconds, using a whole-millisecond value.
The runtime validates the affected slave synchronization configuration too; callers must handle rejection rather than assuming the new period was applied.
@spec upload_sdo(EtherCAT.Session.t(), atom(), non_neg_integer(), non_neg_integer()) :: {:ok, binary()} | {:error, term()}
Upload one CoE object from a named slave as a raw binary.