Redundancy
EtherCAT redundancy uses dual NICs plus a ring topology for link-level fault tolerance: the primary port carries primary frames, the secondary port carries secondary frames, and when any segment breaks the SDK merges the slave states completed by both sides through the Working Counter (WKC), so the whole network keeps running.
Redundancy is enabled automatically by topology detection + RedProcessdata; no manual switch is needed (and none exists). Read the real state through master.diagnostics_info() / RedundancyManager::status().
- Redundancy link state change event:
on_redundancy_mode_changed
Enabling and state
| Category | Method | Type | R/W | Description |
|---|---|---|---|---|
| Enabling and state | force_failover() | bool | write-only | Short name on RedundancyManager; the underlying call always returns false — bidirectional redundancy has no manual switchover path, merge handles it automatically |
| force_redundancy_failover() | Result<()> | write-only | Master wrapper: the underlying call always returns false and always maps to Err; do not treat it as a completed switchover | |
| check_redundancy_health() | bool | read-only | Checks the redundancy health state | |
| diagnostics_info().redundancy_ring_mode() | RingMode | read-only | Redundancy ring operating mode (enum, recommended) | |
| redundancy_ring_mode() | i32 | read-only | Raw value of the redundancy ring operating mode (0=Inactive, 1=Dual, 2=Degraded) | |
| secondary_frame_link_state() | PhyLinkState | read-only | Secondary port frame-level link tri-state: Up=1, Down=0, Unknown=-1 | |
| secondary_link_status() | bool | read-only | Compatibility health judgement: only an explicit Up is true; Down and unknown are both false |
force_failover() / force_redundancy_failover()
pub fn force_failover(&self) -> bool // RedundancyManager
pub fn force_redundancy_failover(&self) -> Result<()> // EtherCATMaster
The Rust short name is force_failover (RedundancyManager, returns bool). force_redundancy_failover() on the master maps the underlying false to Err.
There is no such thing as a manual switchover: under bidirectional redundancy (dual send + merge) both sides carry frames at the same time, merge handles the send and receive paths automatically, and there is no manual path that "switches the send path to the secondary port". The underlying ForceRedundancyFailover always returns FALSE, so force_failover() always yields false and force_redundancy_failover() always yields Err — this is not a "failed switchover"; that entry point simply does nothing at all. Do not call these two methods as debugging or maintenance tools; leave redundancy behaviour to the topology layer and observe the state with RedundancyManager::status() / check_redundancy_health().
check_redundancy_health()
pub fn check_redundancy_health(&self) -> bool
Checks whether the redundancy link is currently healthy.
redundancy_ring_mode() / RingMode enum
// Recommended: return the strongly typed enum through the diagnostics object
pub fn redundancy_ring_mode(&self) -> RingMode // MasterDiagnosticsInfo
// Raw value: returned directly as RedundancyManager on the master / i32
pub fn redundancy_ring_mode(&self) -> i32 // EtherCATMaster / RedundancyManager
Redundancy ring operating mode. master.diagnostics_info().redundancy_ring_mode() returns the strongly typed RingMode enum (recommended); master.redundancy_ring_mode() and RedundancyManager::redundancy_ring_mode() return the underlying raw i32, which corresponds one-to-one with the enum discriminant values.
#[repr(i32)]
pub enum RingMode {
Inactive = 0, // inactive: redundancy monitoring is not initialized
Dual = 1, // bidirectional redundancy: P1 open, both ends send LRW once the secondary is active
Degraded = 2, // degraded mode: the secondary link is unavailable, only the primary works
}
Redundant process data mode
EtherCATMaster::set_redundancy_mode() / EtherCATMaster::redundancy_mode()
pub fn set_redundancy_mode(mode: RedundancyMode) -> Result<()>
pub fn redundancy_mode() -> RedundancyMode
Associated function (EtherCATMaster::set_redundancy_mode(...), it does not take &self); it sets / reads the global redundant process data handling mode. The parameter is the RedundancyMode enum, not a bare i32: RedundancyMode::Standard = standard ETG redundancy (default), RedundancyMode::PrimaryOnly = primary port only, RedundancyMode::Dynamic = dynamic bidirectional redundancy (dual send + merge). A failed set returns Err (for example, on Windows PrimaryOnly is not supported, so it returns Err and the setting is not applied).
Redundancy WKC (merged WKC)
Under ring redundancy the SDK merges the WKC of both sides to obtain the number of slaves that really completed the PDO exchange this cycle; the merged value is the authoritative criterion.
| Category | Method | Returns | R/W | Description |
|---|---|---|---|---|
| Merged WKC | diagnostics_info().wkc() | u16 | read-only | Number of slaves that completed the exchange this cycle (authoritative value) |
| Expected WKC | diagnostics_info().expected_wkc() | u16 | read-only | Fixed true value determined at configuration time; never lowered to accommodate a degrading bus |
| Deficit | diagnostics_info().wc_deficit() | u16 | read-only | 期望 - 合并实测; only >0 means slaves really dropped |
| Redundancy active | diagnostics_info().redundancy_active() | bool | read-only | The break is already covered by redundancy; always false in line / fold-back topologies |
Criterion: merged WKC == expected WKC → the network is intact, and a single-port WKC below expected is normal at that point; merged WKC < expected WKC → slaves really dropped; locate them one by one with slave.wc_contributed(), and it returns to zero automatically once the slave recovers. Single-port WKC is only used to locate the break, not to judge health; a secondary port at 0xFFFF = nothing measured.
let diag = master.diagnostics_info();
if diag.wkc() != diag.expected_wkc() {
println!("真掉站: 缺额 {},逐站查 slave.wc_contributed()", diag.wc_deficit()); // Real slave loss: deficit {}, check slave.wc_contributed() slave by slave
} else if diag.redundancy_active() {
println!("有断点,冗余已补齐,网络完整"); // There is a break, redundancy has compensated, the network is complete
}
Full example
Dual NIC redundancy + health monitoring
use darra_ethercat::EtherCATMaster;
let mut master = EtherCATMaster::new()?;
master.set_network(r"\Device\NPF_{primary-guid}", r"\Device\NPF_{secondary-guid}")?;
// Redundancy is enabled automatically by topology detection + RedProcessdata; no manual switch is needed (and none exists).
master.set_state(EcState::Operational)?;
master.start();
// Subscribe to redundancy mode changes (callback parameters: master_index, old_mode, new_mode)
master.events().on_redundancy_mode_changed(|_master, old_mode, new_mode| {
println!("冗余模式: {} -> {}", old_mode, new_mode); // Redundancy mode: {} -> {}
});
// Periodic health check
loop {
let healthy = master.check_redundancy_health();
let mode = master.redundancy_ring_mode();
let sec_ok = master.secondary_link_status();
println!("冗余: healthy={} ring_mode={} secondary_link={}", healthy, mode, sec_ok); // Redundancy: healthy={} ring_mode={} secondary_link={}
std::thread::sleep(std::time::Duration::from_secs(1));
}
Failover (automatic, no manual entry point)
Under bidirectional redundancy, failover is completed automatically by merge; there is no manual switchover path:
// force_redundancy_failover() always returns Err (the underlying call is always false); this is not a "failed switchover", that entry point simply does nothing
match master.force_redundancy_failover() {
Ok(()) => { /* unreachable: the underlying call always returns false */ }
Err(_) => {
// Expected outcome: redundancy behaviour is left to the topology layer, observe the state with RedundancyManager::status() / check_redundancy_health()
}
}
- ETG.1500 §5.7 Cable Redundancy