Skip to main content

Configuration

Access MasterConfig<'_> through master.config(); it manages all communication configuration in one place.

Properties​

CategoryMethodTypeR/WDescription
Cycle configurationloop_cycle() / set_loop_cycle()u32R/WPDO exchange cycle (nanoseconds). The read returns the actual cycle value in effect
dc_cycle()u32Read-onlyDC cycle (nanoseconds). 0 = not configured; the DC time base follows loop_cycle
high_resolution_timer() / set_high_resolution_timer()boolR/WRead: whether the system clock precision is already 1ms (or finer); write: enables/disables it for this process, effective immediately. The installer does not enable it by default
Network transportframe_high_priority() / set_frame_high_priority()boolR/WHigh frame priority (off by default)
use_udp() / set_use_udp()boolR/WUDP frame mode (gateway/EAP devices only)
is_udp_available()boolRead-onlyWhether UDP is available
vlan_id() / set_vlan_id()u16R/WVLAN ID (0-4095, 0=disabled)
vlan_priority() / set_vlan_priority()u8R/WVLAN priority PCP (0-7)
PDO configurationoverlapping_groups() / set_overlapping_groups()boolR/WPDO overlapping mode (not enabled by default, TI ESC only)
packed_mode() / set_packed_mode()boolR/WPacked PDO mapping mode (false = byte-aligned, true = bit-packed mapping)
filter_threshold() / set_filter_threshold()u32R/WConsecutive PDO frame loss threshold (default 3). The callback fires only when consecutive frame loss reaches this value
Mutex protectionmutex_protection() / set_mutex_protection()boolR/WMutex protection (enabled by default)
Adaptive timeoutadaptive_timeout_enabled() / set_adaptive_timeout_enabled()boolR/WAdaptive timeout (enabled by default)
State transition timeoutstimeout_init_to_preop() / set_timeout_init_to_preop()u32R/WINIT→PREOP timeout (ms)
timeout_preop_to_safeop() / set_timeout_preop_to_safeop()u32R/WPREOP→SAFEOP timeout (ms)
timeout_safeop_to_op() / set_timeout_safeop_to_op()u32R/WSAFEOP→OP timeout (ms)
Watchdogprocess_data_watchdog_ms() / set_process_data_watchdog_ms()u32R/WProcess data watchdog (ms)
pdi_watchdog_ms() / set_pdi_watchdog_ms()u32R/WPDI watchdog (ms)
Scan configurationscan_revision_match()u8Read-onlyScan revision match mode (0=exact, 1=compatible, 2=ignore); the fixed reference value is always 2
set_scan_revision_match(mode)Result<()>Write-onlySets the match mode; Ok(())=applied, Err=invalid parameter (mode>2) or write failure. The current version does not support setting it: writing a valid value also returns Err and the configuration does not take effect
Frame repeatframe_repeat_count() / set_frame_repeat_count()u8R/WFrame repeat count (1-3, default 1=disabled)
DC configurationdrift_compensation() / set_drift_compensation()boolR/WDC drift compensation
Mailbox configurationmailbox_timeout()u32Read-onlyFixed reference value 5000 ms (not the actual value read back from a slave)
set_mailbox_timeout(ms)Result<()>Write-onlyNot supported in the current version: always Err, the configuration does not take effect
mailbox_retries()u32Read-onlyFixed reference value 3
set_mailbox_retries(count)Result<()>Write-onlyNot supported in the current version: always Err, the configuration does not take effect

Cycle configuration​

loop_cycle() / set_loop_cycle()​

pub fn loop_cycle(&self) -> u32
pub fn set_loop_cycle(&self, ns: u32)

PDO exchange cycle time, in nanoseconds (ns).

What loop_cycle() reads back is the cycle value currently in effect (not an enum such as a "timing mode"), and it has the same source as master.loop_cycle(). set_loop_cycle() writes only the LoopCycle value and does not touch the DC cycle.

The master RT thread (the high-precision timer in real-time driver mode) sends and receives PDO frames at this cycle. The value determines how often process data is refreshed between the master and the slaves -- the smaller the value, the faster the refresh, but the higher the demand on system real-time behaviour. Real-time driver mode supports a minimum of 31 µs (= 31,000 ns, whole microseconds); that is the lower limit of the specification.

Relationship to the DC cycle:

  • When no separate DC cycle is configured (dc_cycle() returns 0), the DC time base follows loop_cycle, so changing set_loop_cycle() also changes the DC cycle.
  • Once a DC cycle has been configured separately, the two are independent: set_loop_cycle() does not change the DC cycle.
  • To confirm the current DC cycle, read config.dc_cycle().
Recommended values

On Windows, use no less than 125,000ns (125 µs). Real-time driver mode fully supports the 31 µs (= 31,000 ns) lower limit of the specification; smaller values are meaningless on Windows, because the application layer cannot write at a higher rate. On Linux, shorter cycles are supported depending on the system's real-time configuration.

Example:

let config = master.config();
config.set_loop_cycle(1_000_000); // 1ms
config.set_loop_cycle(500_000); // 500 µs
config.set_loop_cycle(250_000); // 250 µs
config.set_loop_cycle(125_000); // 125 µs (recommended minimum on Windows)
DC drift compensation

DC drift compensation is automatic and needs no extra configuration.

DC sync window monitoring is managed automatically by the SDK (fixed 100ms interval) and is enabled when there are DC slaves on the network.

Mailbox communication and the PDO cycle

Mailbox communication is carried along with the PDO cycle and does not use an extra frame.

Mailbox response latency: about 2-3 PDO cycles. For example, with loop_cycle=1ms an SDO read takes about 2-3ms.

dc_cycle()​

pub fn dc_cycle(&self) -> u32

DC cycle time, in nanoseconds (ns), read-only.

  • Returns 0 = no separate DC cycle is configured; the DC time base follows loop_cycle (when a slave-level SYNC0 exists, the slave's configuration applies).
  • Returns a value other than 0 = that value is the DC cycle, independent of loop_cycle().

To configure a separate DC cycle on the master side, use master.set_dc_cycle_time(ns); pass 0 to return to unconfigured (following loop_cycle).

To make the DC synchronization cycle differ from the PDO cycle (for example PDO at 1ms and DC at 2ms), set the DC cycle separately; calling only set_loop_cycle() does not change a DC cycle that was configured separately.

Example:

let config = master.config();
let pdo_ns = config.loop_cycle();
let dc_ns = config.dc_cycle();

if dc_ns == 0 {
println!("PDO 周期 {pdo_ns}ns,DC 跟随 PDO 周期"); // PDO cycle {pdo_ns}ns, DC follows the PDO cycle
} else {
println!("PDO 周期 {pdo_ns}ns,DC 周期 {dc_ns}ns"); // PDO cycle {pdo_ns}ns, DC cycle {dc_ns}ns
}

high_resolution_timer() / set_high_resolution_timer()​

pub fn high_resolution_timer(&self) -> bool
pub fn set_high_resolution_timer(&self, enabled: bool)
High-resolution timer

Read: whether the system clock precision is already 1ms (or finer); it is not a hard-coded false. Write: enables/disables it for this process, effective immediately. The installer does not enable it by default; set it in the cycle configuration. When enabled, waits are more accurate but the mouse may become sluggish; PDO on isolated cores does not depend on this setting. On non-Windows platforms this is a no-op.

The read returns whether the system clock is currently already at 1ms; it is not a hard-coded false, and the installer does not enable it.

Example:

config.set_high_resolution_timer(true);

Network transport​

frame_high_priority() / set_frame_high_priority()​

pub fn frame_high_priority(&self) -> bool
pub fn set_frame_high_priority(&self, enabled: bool)

Raises the transmit priority of EtherCAT frames through the OS layer to reduce queuing latency.

Default: false (off by default)

How each platform implements it
  • Windows — process/thread priority boost
  • Linux — the SO_PRIORITY=6 socket option (network stack queuing priority, requires root privileges)

use_udp() / set_use_udp()​

pub fn use_udp(&self) -> bool
pub fn set_use_udp(&self, enabled: bool)

UDP frame mode (ETG.1500 5.3.7). When enabled, EtherCAT datagrams are carried inside UDP/IP packets (UDP port 34980).

Gateway/EAP devices only; standard slaves are not supported

The ESC (EtherCAT Slave Controller) chip of a standard EtherCAT slave works at the data link layer and recognizes only raw Ethernet frames with EtherType=0x88A4. Frames carried over UDP/IP are invisible to these slaves.

Applies only to:

  • EtherCAT gateways or bridge devices that support the UDP protocol
  • Communication with EtherCAT Automation Protocol (EAP) devices

Does not apply to: direct connection to standard EtherCAT slaves (EK1100, EL7041, servo drives, etc.)

is_udp_available()​

pub fn is_udp_available(&self) -> bool

Whether a UDP socket was created successfully during system initialization. Only when this method returns true can you switch to UDP mode with set_use_udp().

In some restricted environments (for example missing network permissions or a blocking firewall), the UDP socket may fail to be created; is_udp_available() then returns false, and calling set_use_udp(true) has no effect.

Example:

if master.config().is_udp_available() {
master.config().set_use_udp(true); // switch to UDP mode
}

vlan_id() / set_vlan_id()​

pub fn vlan_id(&self) -> u16
pub fn set_vlan_id(&self, id: u16)

VLAN ID (IEEE 802.1Q, ETG1000_4 Table 9, an optional feature in ETG.1500). Range 0-4095; 0 disables the VLAN tag.

Once a non-zero value is set, every EtherCAT frame carries a 4-byte 802.1Q VLAN tag, and the frame header grows from the standard 14 bytes to 18 bytes.

VLAN configuration must be set before entering SafeOp (after Build succeeds and before set_state(Op)).

Takes effect only in real-time driver mode

The VLAN tag feature takes effect only when the real-time driver is installed. The real-time driver sends raw frames directly, so the VLAN tag is preserved intact on the cable.

vlan_priority() / set_vlan_priority()​

pub fn vlan_priority(&self) -> u8
pub fn set_vlan_priority(&self, pcp: u8)

VLAN priority (PCP -- Priority Code Point, IEEE 802.1Q, an optional feature in ETG.1500). Range 0-7, where 7 is the highest priority. It is encoded in the top 3 bits of the TCI field of the VLAN tag.

It is meaningful only after vlan_id() is set to a non-zero value and real-time driver mode is used. On switches that support QoS, frames with a higher PCP value are forwarded first.

Typical VLAN use cases:

  • Converged IT/OT networks -- use VLANs to separate industrial control traffic from office network traffic
  • TSN (Time-Sensitive Networking) -- IEEE 802.1Q priority tags for QoS scheduling
  • Coexisting network segments -- one physical network carrying several EtherCAT segments

Example:

// Set the VLAN after build() succeeds (real-time driver mode required)
let config = master.config();

// Configure the VLAN before entering SafeOp
config.set_vlan_id(100);
config.set_vlan_priority(6); // high priority

PDO configuration​

overlapping_groups() / set_overlapping_groups()​

pub fn overlapping_groups(&self) -> bool
pub fn set_overlapping_groups(&self, enabled: bool)

PDO overlapping mode switch. When enabled, each slave's outputs and inputs share the same logical address range (the larger of the two sizes); the LRW command writes outputs on transmit, and on return the ESC replaces the same location with input data, which reduces the frame size.

Default: false (not enabled by default)

note

Can be set only in the INIT or PRE_OP state, because the memory layout is fixed on entering SAFE_OP.

No impact on the application layer

Overlapping happens only at the frame's logical address level. slave.read_input_*() / slave.write_output_*() and the SlavePdo inputs / outputs always point to separate memory regions; slave.ibytes() / slave.obytes() are unchanged, and all APIs behave the same.

TI ESC

Slaves that use a TI (Texas Instruments) EtherCAT Slave Controller must enable overlapping mode; otherwise LRW commands cannot work correctly. Do not enable it for standard Beckhoff or third-party slaves: some do not support FMMU logical address overlapping and refuse the SAFE_OP transition.

packed_mode() / set_packed_mode()​

pub fn packed_mode(&self) -> bool
pub fn set_packed_mode(&self, enabled: bool)

Packed PDO mapping mode switch. When enabled, PDO variables are packed tightly at bit granularity and byte alignment is not forced.

Default: false (disabled by default, byte-aligned mode)

note

Can be set only in the INIT or PRE_OP state, because the memory layout is fixed on entering SAFE_OP.

Where it applies

For bit-level IO modules (such as Beckhoff EL1008/EL2008 digital IO terminals), whose PDO data is a single bit each. Enabling packed_mode packs several bit IOs into contiguous memory and saves IOmap space.

Example:

config.set_packed_mode(true);  // enable bit packing

filter_threshold() / set_filter_threshold()​

pub fn filter_threshold(&self) -> u32
pub fn set_filter_threshold(&self, value: u32)

Consecutive PDO frame loss threshold; the default is 3.

The master checks on every PDO cycle whether the frame returned normally. A single lost frame is treated as occasional interference and only counted; the on_pdo_frame_loss callback fires only when the number of consecutive lost frames reaches this threshold, which avoids excessive alarms from occasional frame loss.

Example:

config.set_filter_threshold(5);  // fire the callback only after 5 consecutive lost frames
Grouping

PDO configuration works together with slave grouping. Because each group has its own divider and frame loss tracking, frame loss in a high-frequency group and in a low-frequency group do not affect each other.

PDO cycle recording​

record_pdo_cycle_start()​

pub fn record_pdo_cycle_start(&self)

Records the start of one PDO cycle. Each call increments cycle_count() in the master diagnostics by one, and the cycle frequency statistics are updated from it.

The master's own PDO cycle thread already records every cycle, so a regular application does not need to call this. Use it only when you drive the cycle or keep the statistics yourself: each call records one more cycle, so do not count twice alongside the built-in cycle thread. It returns nothing and changes neither bus traffic nor slave states.

Scan configuration​

scan_revision_match() / set_scan_revision_match()​

pub fn scan_revision_match(&self) -> u8
pub fn set_scan_revision_match(&self, mode: u8) -> Result<()>

Version matching policy when scanning slaves. It controls how strictly the revision numbers of slaves found during build() must match those of the slaves in the DENI configuration. The value is a u8 (the Rust SDK provides no dedicated enum type):

Default: 2 (ignore the revision number)

Value meanings:

  • 0 — exact match on VendorID + ProductID + RevisionID
  • 1 — compatible match: scanned RevisionID >= configured RevisionID
  • 2 — ignore RevisionID, match only VendorID + ProductID (default)

Return value (write side): Ok(()) = the setting took effect; Err(..) = invalid parameter (mode > 2) or write failure. The current version does not support setting this mode (there is no channel by which it takes effect): writing a valid value (0-2) also returns Err (the configuration does not take effect), and Ok(()) never occurs -- the method reports the error truthfully and does not store the value silently. On the read side, scan_revision_match() is a fixed reference value that always returns 2.

Example:

config.set_scan_revision_match(1)?;  // request compatible matching (mode=1); mode > 2 is a parameter error, and in the current version a valid value also returns Err (not applied)

Frame repeat​

frame_repeat_count() / set_frame_repeat_count()​

pub fn frame_repeat_count(&self) -> u8
pub fn set_frame_repeat_count(&self, count: u8)

Frame repeat mechanism (ETG.1500 5.4.3). It sets globally how many times the same PDO frame is sent per cycle, and applies automatically to eligible groups.

Default: 1 (disabled), range 1-3

This method is a master-level global setting; filtering by group happens automatically at run time -- frame repeat is performed only for groups in which every slave declares FrameRepeatSupport=1 in its ESI. Group eligibility is computed automatically during IO mapping:

  • Every slave in the group supports it -> frame repeat is enabled for the group
  • Any slave in the group does not support it -> the group skips frame repeat
Why a global setting plus per-group filtering?

ETG.1500 defines frame repeat as a master-level capability with one global repeat count. Because EtherCAT PDO frames are sent as LRW broadcasts, individual slaves cannot be treated differently within the same frame, so "all or nothing" per group is the only compliant approach. There is no need to set a different repeat count for each group.

DENI configuration migration

This parameter and the FrameRepeatSupport flag of each slave are both included in the DENI configuration file. When an exported DENI is loaded on another master, each group's frame repeat eligibility is computed correctly without the ESI files.

Example:

// Global setting: for every eligible group, send the same PDO frame 2 times per cycle
config.set_frame_repeat_count(2);

Mutex protection​

mutex_protection() / set_mutex_protection()​

pub fn mutex_protection(&self) -> bool
pub fn set_mutex_protection(&self, enabled: bool)

Mutex protection switch. It controls whether PDO reads and writes take a lock automatically to ensure thread safety.

  • Enabled (default) -- the framework locks automatically to guarantee thread safety
  • Disabled -- the automatic mutex is off; you manage thread safety yourself, which reduces lock contention overhead

Default: true

Note

With mutex protection disabled, you must ensure the thread safety of PDO data yourself. This suits scenarios with extremely tight latency requirements where you can manage concurrency yourself.

Adaptive timeout​

adaptive_timeout_enabled() / set_adaptive_timeout_enabled()​

pub fn adaptive_timeout_enabled(&self) -> bool
pub fn set_adaptive_timeout_enabled(&self, enabled: bool)

Adaptive timeout. When enabled, it samples the RTT automatically and computes an optimal PDO timeout value dynamically.

Default: true

State transition timeouts​

timeout_init_to_preop() / set_timeout_init_to_preop()​

pub fn timeout_init_to_preop(&self) -> u32
pub fn set_timeout_init_to_preop(&self, ms: u32)

INIT→PREOP timeout (ms). 0 = use the default of 3000ms.

timeout_preop_to_safeop() / set_timeout_preop_to_safeop()​

pub fn timeout_preop_to_safeop(&self) -> u32
pub fn set_timeout_preop_to_safeop(&self, ms: u32)

PREOP→SAFEOP timeout (ms). 0 = use the default of 10000ms. This phase includes SM/FMMU configuration and PDO mapping and usually takes the longest.

timeout_safeop_to_op() / set_timeout_safeop_to_op()​

pub fn timeout_safeop_to_op(&self) -> u32
pub fn set_timeout_safeop_to_op(&self, ms: u32)

SAFEOP→OP timeout (ms). 0 = use the default of 10000ms.

When to change the timeouts
  • Many slaves — a large network (>50 slaves) may need a larger PreOp→SafeOp timeout
  • Special slaves — some servo drives or safety devices initialize slowly
  • Commissioning — increase the timeout so the transition can be observed

MDP automatic orchestration​

The module list of a Modular Device Profile (MDP, ETG.5001) slave has to be written as startup parameters before the slave enters SafeOp. The normal state transition sequence orchestrates it automatically before PreOp→SafeOp, so calling it manually is usually unnecessary; this method exists to run it again explicitly.

apply_mdp_auto_config()​

pub fn apply_mdp_auto_config(&self) -> Result<i32>

Reads 0xF050 (the list of modules actually detected) from each MDP slave, matches the module definitions in the ESI by module identifier, and builds the 0xF030 (configured module list) write sequence, the PDO assignment (0x1C12 / 0x1C13) and the module initialization SDOs. It injects them into that master's startup parameter queue for the PreOp→SafeOp transition, from where the batched startup parameters of that phase write them to the slaves.

Return value:

  • Ok(n) — the number of startup parameter entries this orchestration committed successfully. Entries already in the queue with the same key and the same value are counted too.
  • Err(..) — orchestration failed; the error message carries a return code.

Idempotency and overwriting: entries with the same key that are already in the queue are not appended again; the same key with a different value is overwritten in place, so no duplicate entries are produced. A slave whose startup parameter queue has been explicitly cleared or replaced keeps its existing plan and is not overwritten by automatic orchestration.

When to call it

Call it after the slave has entered PreOp and the mailbox is available. The normal power-up sequence is handled by the master automatically; after changing a module or adjusting the module configuration, use this method to rebuild the startup parameters immediately. For the module-level read/write API, see MDP.

Batched startup parameters​

Startup parameters are the SDO sequence written to the slave object dictionary before entering each EtherCAT state (PDO assignment, PDO mapping, vendor initialization and so on), registered by phase: state transition stage plus before/after the transition. The methods in this group act on every slave of this master; to register parameters for a single slave, see slave startup configuration.

MethodReturnsDescription
apply_startup_parameters_all(transition, timing)Result<i32>Sends the startup parameters of every slave in one batch for the given phase; Ok(n) = number of parameter entries written successfully
clear_all_startup_parameters()Result<()>Clears the startup parameter queue of every slave

apply_startup_parameters_all()​

pub fn apply_startup_parameters_all(&self, transition: u8, timing: u8) -> Result<i32>

Parameters:

ParameterValuesMeaning
transition0-5: TRANS_IP / TRANS_PS / TRANS_SO / TRANS_OS / TRANS_SP / TRANS_PIState transition stage: Init→PreOp / PreOp→SafeOp / SafeOp→Op / Op→SafeOp / SafeOp→PreOp / any→Init
timing0 = TIMING_BEFORE, 1 = TIMING_AFTERWhether to write before or after the transition

The Rust side does not validate the value range; pass only the constants above.

Scope: only entries registered for this phase are written; different slaves are written in parallel, and within one slave the writes are serialized in priority order. A per-slave failure only degrades that slave (it is flagged and can be queried with slave_needs_startup_reconfig; the recovery flow replays it) and does not interrupt the other slaves.

Return value:

  • Ok(n) — the number of parameter entries that landed successfully in this phase. Entries already written with a matching read-back that were skipped this time are counted too.
  • Ok(0) — no entries need to be written in this phase; or nothing in this batch was written successfully but the failures were degraded per slave; or the master is shutting down and skipped this batch.
  • Err(..) — the whole bus did not respond in this phase (bus-level fault) or batch scheduling failed; the state transition should not continue. The error message carries a return code.

Idempotency and overwriting: every "slave + phase" pair keeps a landed record. When the same phase is called again, entries already written with a matching read-back are not sent again (they are still counted in the returned number); a slave reconfiguration or a change to the queue contents invalidates the record for that phase, and the next call writes again. The writes themselves are idempotent SDO writes: writing the same parameter again only writes the same value once more.

Batch entry point and slave index

If the call returns a "slave index invalid" error, the running library does not accept the batch semantics of index 0; in that case call slave.startup().apply(transition, timing) per slave to perform the same phase write. The parameter queue itself is unaffected.

clear_all_startup_parameters()​

pub fn clear_all_startup_parameters(&self) -> Result<()>

Clears the startup parameter queue of every slave of this master. After clearing, each slave's queue is marked as an "explicitly empty plan":

  • MDP automatic orchestration no longer appends parameters to an explicit plan; when the ESI defaults are applied next time, only required entries missing from the queue are added, and existing entries are not overwritten. To use custom parameters, register them manually again.
  • Clearing repeatedly is safe (clearing an empty queue again also returns Ok(())).
  • Only the parameter queue is changed; no slave register is written: the PDO mapping and object dictionary values already active in the slave remain until the next reconfiguration or a power cycle.

Return value: Ok(()) = cleared; Err(..) = the master is not ready or the call failed.

Slave reconfiguration and the PREOP callback​

When a slave reconnects after a power cycle, recovers from a hot-plug, or has its state machine rebuilt, the master brings it from INIT back to PreOp and replays that slave's startup parameters. The methods in this group work alongside that recovery path.

MethodReturnsDescription
slave_needs_startup_reconfig(slave_index)boolWhether this slave needs its startup parameters replayed
clear_slave_startup_reconfig(slave_index)()Clears the reconfiguration flag of this slave
register_preop_reconfig_callback(callback)()Registers the PREOP reconfiguration callback (an associated function, called as EtherCATMaster::)

slave_needs_startup_reconfig() / clear_slave_startup_reconfig()​

pub fn slave_needs_startup_reconfig(&self, slave_index: u16) -> bool
pub fn clear_slave_startup_reconfig(&self, slave_index: u16)

slave_index is a 1-based slave index.

  • slave_needs_startup_reconfig() — true = this slave has gone through the reconfiguration path and its startup parameters need to be applied again. It is set when the recovery flow brings the slave back to PreOp; an invalid index (0 or beyond the slave count) returns false.
  • clear_slave_startup_reconfig() — clears the flag after the replay completes; clearing repeatedly is safe. An uncleared flag stays true.
Recommended usage

In the on_preop_reconfig callback, query slave_needs_startup_reconfig, replay that slave's startup parameters as needed, and call clear_slave_startup_reconfig when done.

register_preop_reconfig_callback()​

pub fn register_preop_reconfig_callback(callback: SlavePreOpReconfigCallback)

pub type SlavePreOpReconfigCallback = extern "C" fn(master_index: u16, slave_index: u16);

Registers the slave PREOP reconfiguration callback. It is an associated function (no &self), called on the type: EtherCATMaster::register_preop_reconfig_callback(cb). Registering once takes effect for every master instance in the process; the callback parameters carry the index of the master that triggered this reconfiguration and the slave index (1-based).

When it fires: when a slave completes INIT→PreOp on the reconfiguration path and its startup parameters need to be applied again; it also fires after the master's internal recovery flow has replayed the startup parameters. The reconfiguration flag is set before the callback, so it can be queried with slave_needs_startup_reconfig.

Thread context: it runs synchronously on the thread that triggered this reconfiguration -- a reconfiguration caused by your set_state(..) runs on the calling thread, one caused by the internal recovery flow runs on the recovery thread; it never runs on the PDO cycle thread. Keep the callback short and do not block.

Registration semantics: registration appends; several listeners are called in turn, and registering the same function pointer again is ignored. This entry point is a bare C ABI function pointer, so a closure cannot capture state; if you need a subscription that can be unregistered and can capture state, use master.events().on_preop_reconfig(..).

Watchdog​

pdi_watchdog_ms() / set_pdi_watchdog_ms()​

pub fn pdi_watchdog_ms(&self) -> u32
pub fn set_pdi_watchdog_ms(&self, ms: u32)

PDI watchdog timeout (ms). It monitors the slave's local application accesses to the ESC.

Default: 0 (use the slave default)

process_data_watchdog_ms() / set_process_data_watchdog_ms()​

pub fn process_data_watchdog_ms(&self) -> u32
pub fn set_process_data_watchdog_ms(&self, ms: u32)

Process data watchdog timeout (ms). It monitors PDO communication from the master to the slaves.

Default: 0 (use the slave default, usually 100ms)

Recommended settings

The process data watchdog timeout should be 10-100 times the PDO cycle. For example, with loop_cycle=1ms, set the watchdog to 100-200ms.

DC configuration​

drift_compensation() / set_drift_compensation()​

pub fn drift_compensation(&self) -> bool
pub fn set_drift_compensation(&self, enabled: bool)

DC drift compensation switch. When enabled, the master periodically measures the DC system time deviation and writes the compensation value (0x0920).

Default: false

note

You can also enable it with master.enable_drift_compensation(), which additionally lets you configure the threshold and gain parameters.

Mailbox configuration​

mailbox_timeout() / set_mailbox_timeout()​

pub fn mailbox_timeout(&self) -> u32
pub fn set_mailbox_timeout(&self, ms: u32) -> Result<()>

mailbox_timeout() returns a fixed reference value of 5000 milliseconds, not the actual value read back from a device: there is no master-level entry point for sending a mailbox timeout, and the per-slave mailbox timeout comes from the ESI.

set_mailbox_timeout() is not supported in the current version: there is no entry point that sends it, so it always returns Err(..) (the error message states that the configuration did not take effect) and writes one error log entry; the value you pass in is not stored and does not change any slave.

mailbox_retries() / set_mailbox_retries()​

pub fn mailbox_retries(&self) -> u32
pub fn set_mailbox_retries(&self, count: u32) -> Result<()>

mailbox_retries() returns a fixed reference value of 3 retries.

set_mailbox_retries() is not supported in the current version: there is no entry point that sends it, so it always returns Err(..) and writes one error log entry; the value you pass in is not stored.

Configuration export and persistence​

MasterConfig provides two read-only export methods that save a snapshot of the current configuration as a JSON string or an XML file; both only read the current values and change no configuration.

MethodReturnsDescription
export_config_string()Option<String>JSON text of the current configuration snapshot
save_config_xml(path)boolWrites the current configuration to an XML file; true = the write succeeded

export_config_string()​

pub fn export_config_string(&self) -> Option<String>

Returns a JSON snapshot of the current configuration with no trailing newline. The current implementation has no failure path and always returns Some(String).

GroupFields
Cycleloop_cycle_ns, dc_cycle_ns
Clock and transporthigh_resolution_timer, frame_high_priority, use_udp, udp_available, vlan_id, vlan_priority
PDOoverlapping_groups, packed_mode, filter_threshold, frame_repeat_count
Thread safetymutex_protection
Watchdogprocess_data_watchdog_ms, pdi_watchdog_ms
Timeoutsadaptive_timeout_enabled, timeout_init_to_preop, timeout_preop_to_safeop, timeout_safeop_to_op
DC and scanningdrift_compensation, scan_revision_match
Mailboxmailbox_timeout, mailbox_retries

Example output (values vary with the current configuration):

{
"loop_cycle_ns": 1000000,
"dc_cycle_ns": 0,
"high_resolution_timer": false,
"frame_high_priority": false,
"use_udp": false,
"udp_available": true,
"vlan_id": 0,
"vlan_priority": 0,
"overlapping_groups": false,
"packed_mode": false,
"mutex_protection": true,
"filter_threshold": 3,
"frame_repeat_count": 1,
"process_data_watchdog_ms": 0,
"pdi_watchdog_ms": 0,
"adaptive_timeout_enabled": true,
"timeout_init_to_preop": 3000,
"timeout_preop_to_safeop": 10000,
"timeout_safeop_to_op": 10000,
"drift_compensation": false,
"scan_revision_match": 2,
"mailbox_timeout": 5000,
"mailbox_retries": 3
}

save_config_xml()​

pub fn save_config_xml(&self, path: &str) -> bool

Writes the current configuration to an XML file. path is the target file path (a relative path is resolved against the process's current directory); an existing file is overwritten, and the parent directory must already exist.

Return value: true = the file was written; false = the write failed (directory does not exist, no permission, not enough disk space, and so on). A failure returns no specific reason and does not change the in-memory configuration.

What is written: the root element DarraEtherCATConfiguration (version="1.0"), containing a <Master> configuration section.

  • Time units are fixed at microseconds: the cycle is written as the nanosecond value divided by 1000, and any part below 1 µs is dropped.
  • When the DC cycle is 0 (not configured separately), the value of the cycle is written (the DC time base follows the cycle).
  • Booleans are written as true / false.

The XML covers only the <Master> fields listed above; the state transition timeouts and udp_available appear only in the JSON snapshot.

Example output (values vary with the current configuration):

<?xml version="1.0" encoding="utf-8"?>
<DarraEtherCATConfiguration version="1.0">
<Master>
<CycleTime unit="us">1000</CycleTime>
<DcCycleTime unit="us">1000</DcCycleTime>
<HighResolutionTimer>false</HighResolutionTimer>
<FrameHighPriority>false</FrameHighPriority>
<UseUdp>false</UseUdp>
<VlanId>0</VlanId>
<VlanPriority>0</VlanPriority>
<OverlappingGroups>false</OverlappingGroups>
<PackedMode>false</PackedMode>
<MutexProtection>true</MutexProtection>
<FilterThreshold>3</FilterThreshold>
<FrameRepeatCount>1</FrameRepeatCount>
<ProcessDataWatchdogMs>0</ProcessDataWatchdogMs>
<PdiWatchdogMs>0</PdiWatchdogMs>
<AdaptiveTimeout>true</AdaptiveTimeout>
<DriftCompensation>false</DriftCompensation>
<ScanRevisionMatch>2</ScanRevisionMatch>
<MailboxTimeout>5000</MailboxTimeout>
<MailboxRetries>3</MailboxRetries>
</Master>
</DarraEtherCATConfiguration>

IOmap locking​

lock_iomap / unlock_iomap / iomap_guard are methods of EtherCATMaster itself (not of MasterConfig); call them directly, for example master.lock_iomap().

lock_iomap() / unlock_iomap() / iomap_guard()​

// Methods on EtherCATMaster
pub fn lock_iomap(&self) -> bool // false = the lock was not acquired this time
pub fn unlock_iomap(&self)
pub fn iomap_guard(&self) -> Option<IomapGuard<'_>> // None = the lock was not acquired

Manually locks and unlocks the IOmap for batched atomic writes across multiple axes. When set_mutex_protection(false) is set, call this method manually to guarantee the atomicity of PDO data.

The Rust SDK additionally provides the RAII guard IomapGuard, which unlocks automatically when the scope ends.

Comparison of the three thread-safety modes:

  • Automatic mutex — set_mutex_protection(true) (default) — ~200ns — general use; no need to think about thread safety
  • Manual IOmap lock — set_mutex_protection(false) + lock_iomap/unlock_iomap — ~50ns — multi-axis interpolation that needs batched atomic writes
  • No lock — set_mutex_protection(false) without calling lock — 0 — single-threaded writes that guarantee no contention
Multi-axis interpolation

During coordinated multi-axis interpolation, the target positions of several slaves must take effect in the same PDO cycle. The manual IOmap lock guarantees that a batch of writes is committed atomically within one PDO frame.

Prefer iomap_guard

iomap_guard() returns an RAII guard (Option<IomapGuard>) that unlocks automatically at the end of the scope, so a forgotten unlock cannot deadlock the caller; None = the lock was not acquired this time -- do not treat it as locked.

Example (batched writes for multi-axis interpolation):

// Disable the automatic mutex and use the manual IOmap lock instead
master.config().set_mutex_protection(false);

// Batched write under the RAII guard (iomap_guard is on master)
if let Some(_guard) = master.iomap_guard() {
// All writes complete within the guard's lifetime, guaranteeing atomicity
master.write_slave_output(1, &target_pos1.to_le_bytes())
.expect("写入从站 1 输出失败"); // Failed to write slave 1 outputs
master.write_slave_output(2, &target_pos2.to_le_bytes())
.expect("写入从站 2 输出失败"); // Failed to write slave 2 outputs
master.write_slave_output(3, &target_pos3.to_le_bytes())
.expect("写入从站 3 输出失败"); // Failed to write slave 3 outputs
} // _guard goes out of scope and unlocks automatically

Full example​

let config = master.config();

// Cycle configuration
config.set_loop_cycle(1_000_000); // 1ms

// Network transport
config.set_frame_high_priority(true);

// State transition timeouts
config.set_timeout_preop_to_safeop(15000);

// Watchdog
config.set_pdi_watchdog_ms(100);
config.set_process_data_watchdog_ms(200);

// Frame repeat
config.set_frame_repeat_count(2);

// Mailbox configuration: the master-level values are read-only fixed references (5000ms / 3 times)
// and cannot be set in the current version
// (set_mailbox_timeout / set_mailbox_retries always return Err, so the example does not show them);
// the per-slave mailbox timeout comes from the ESI

println!("{}", config); // Display formatting

Timeout configuration best practices​

The various timeout fields involved in EtherCAT communication are independent of one another and directly affect how quickly network faults are detected and how long recovery takes. The table below summarizes the common fields, typical defaults and recommended ranges; in a real deployment, choose values by balancing cable length, interference level and real-time priority.

Key field quick reference​

  • loop_cycle (ns) — default 1,000,000 (1ms), recommended 125,000 ~ 4,000,000 — PDO cycle; determines the refresh rate and CPU load
  • timeout_init_to_preop (ms) — default 3000, recommended 3000 ~ 10000 — INIT→PREOP wait time (slow slaves / EEPROM loading)
  • timeout_preop_to_safeop (ms) — default 10000, recommended 10000 ~ 30000 — PREOP→SAFEOP wait time (includes SM/FMMU/PDO mapping; increase for large networks)
  • timeout_safeop_to_op (ms) — default 10000, recommended 10000 ~ 15000 — SAFEOP→OP wait time
  • process_data_watchdog_ms (ms) — default 0 (slave default ≈100), recommended loop_cycle × 10 ~ 100 — time after which a slave falls back to SafeOp when it loses the connection to the master
  • pdi_watchdog_ms (ms) — default 0 (slave default), recommended 0 ~ 200 — detection window for the slave's local firmware stopping its accesses to the ESC
  • mailbox_timeout (ms) — fixed reference value 5000 ms, read-only; cannot be adjusted with a master-level setter — reference single mailbox wait for an SDO / FoE / emergency message
  • mailbox_retries (times) — fixed reference value 3 times, read-only; cannot be adjusted with a master-level setter — reference number of mailbox retries after a failure

When to increase / decrease​

Increase when:

  • Long cables / across cabinets / across workshops -- large physical transmission delays; occasional RTT jitter needs headroom
  • High EMI / welding / near high-power inverters -- noise causes occasional frame loss, so retries need more room
  • Across VLAN / TSN composite networks -- passing through switches introduces queuing jitter
  • Large networks (>50 slaves) -- timeout_preop_to_safeop must be increased, otherwise the SafeOp transition fails
  • Slow slaves (large FoE file downloads / EEPROM writes) -- both the mailbox and Init→PreOp timeouts must be extended

Decrease when:

  • Fast fault detection matters most -- in industrial emergency-stop scenarios, set the watchdog to 5×loop_cycle so frame loss is detected within 50ms
  • Desktop with short cables / lab -- very low RTT, so the watchdog can go down to 20~50ms
  • Strict RT (≤ 250 µs cycle) -- the overall timing is tight, so every timeout must be short

Default / lab / industrial / high-EMI presets​

let config = master.config();

// Note: the master-level mailbox timeout and retry count are fixed reference values (5000ms / 3 times)
// and cannot be set in the current version (set_mailbox_timeout / set_mailbox_retries always return Err);
// the per-slave mailbox timeout comes from the ESI, so the four presets below do not show these two.

// (1) SDK default — suitable for a standard short cable + desktop ~ typical shop floor
config.set_loop_cycle(1_000_000); // 1ms
config.set_timeout_preop_to_safeop(10000); // default value
config.set_process_data_watchdog_ms(0); // slave default (~100ms)

// (2) Lab high speed — short cable + strict RT
config.set_loop_cycle(250_000); // 250 µs
config.set_timeout_preop_to_safeop(5000);
config.set_process_data_watchdog_ms(20); // very fast detection

// (3) Typical industrial — long cable + large network
config.set_loop_cycle(1_000_000);
config.set_timeout_preop_to_safeop(20000); // relaxed for a large network
config.set_process_data_watchdog_ms(200);

// (4) High EMI / welding site — tolerates occasional frame loss
config.set_loop_cycle(2_000_000); // 2ms
config.set_timeout_preop_to_safeop(30000);
config.set_process_data_watchdog_ms(500);
config.set_adaptive_timeout_enabled(true); // the adaptive timeout absorbs jitter
Side effects
  • Timeout too large -- a real fault is reported only when the timeout expires, so application alarms and safe stops are delayed
  • Timeout too small -- occasional jitter is misjudged as a fault, and noisy on_pdo_frame_loss / on_state_change alarms fire frequently
  • Watchdog < a few times loop_cycle -- it triggers even in normal operation and slaves repeatedly fall back to SafeOp
  • After adjusting, run a 24h communication stress test before going live
Combine with adaptive timeout

With set_adaptive_timeout_enabled(true) (on by default), the SDK computes the PDO single-frame timeout from the measured RTT automatically, so there is no need to tighten loop_cycle manually. The watchdog / state transition fields above still have to be set for the scenario.