Skip to main content

Redundancy

EtherCAT redundancy provides link-level fault tolerance through dual NICs and a ring topology: the primary port carries primary frames, the secondary port carries secondary frames, and when any segment breaks the SDK merges the slave states completed from the WKC of both sides, so the whole network keeps running.

Read redundancy diagnostics through master.diagnostics_info. Redundancy is enabled automatically by the topology; there is no manual switch and no manual failover path.​

How it is enabled

Redundancy is enabled automatically by the topology: specify the secondary NIC through set_network(adapter, redundant_adapter) during initialization, and that is all — there is no manual enable call. No manual control is needed at runtime.

Related pages

RedundancyState​

RedundancyState has four values: NONE(0) no redundancy / PRIMARY(1) primary network only / SECONDARY(2) secondary network only / BOTH(3) both networks active with redundancy.

RedundancyStatus​

Detailed runtime redundancy status. The class name is exactly RedundancyStatus (there is no RedundancyStatusInfo alias).

@dataclass(frozen=True)
class RedundancyStatus:
state: RedundancyState # overall redundancy state
primary_link_up: bool # whether the primary link is up
secondary_link_up: bool # whether the secondary link is up
primary_tx_frames: int # frames sent on the primary port
primary_rx_frames: int # frames received on the primary port
secondary_tx_frames: int # frames sent on the secondary port
secondary_rx_frames: int # frames received on the secondary port
failover_count: int # failover count
last_failover_time: Optional[float] # time of the last failover (Unix timestamp, seconds; None when there is no failover record)

The redundancy API exposed at master level: set_redundancy_mode(mode) / check_redundancy_health(), plus the read-only properties redundancy_ring_mode / secondary_frame_link_state (three-state) / secondary_link_ok (a compatible boolean health check) / redundancy_mode / redundancy_status. force_failover() always returns False (bidirectional redundancy has no manual switch-over path; see below); RedundancyManager offers the same wrappers (get_status / check_health and so on), and mgr.get_status() -> RedundancyStatus gets a redundancy snapshot in one call.

force_failover()​

def force_failover(self) -> bool    # same name on EtherCATMaster and RedundancyManager

Always returns False: there is no manual failover path underneath — the bidirectional merge handles it automatically (frames run on both sides at the same time, so there is no primary/backup path to switch; the Windows edition always transmits on both ports for the same reason). The entry is kept only for API compatibility; calling it does not switch anything. Never treat False as a "failover failed" condition to retry, and never expect True.

if not master.force_failover():
print("未切换(预期行为): 冗余自动处理,无手动切换路径") # No switch performed (expected behavior): redundancy is handled automatically, there is no manual switch path

set_redundancy_mode(mode) / redundancy_mode​

def set_redundancy_mode(self, mode: int) -> bool   # EtherCATMaster

@property
def redundancy_mode(self) -> int # process-wide global value

Set / get the redundancy handling mode. This is a process-wide global switch that affects every master in the process. Modes: 0 = standard ETG redundancy (default), 1 = primary port only, 2 = dynamic bidirectional redundancy (transmit on both ports + merge).

  • Returns True: the mode was issued.
  • Returns False: not issued (the current platform does not support this mode, or mode is not 0/1/2). In that case redundancy_mode keeps its previous value and never reports the new mode falsely.
Platform difference: the Windows edition always transmits on both ports

The Windows edition always transmits on both ports — as long as the secondary port is bound, cycle frames go out of both the primary and the secondary port: this is the physical precondition for frames to leave through the secondary port and come back to form the protection ring in a ring topology. Therefore set_redundancy_mode(1) (primary port only) is not implemented on Windows: the call returns False explicitly and issues nothing; it is not silently ignored. Issuing it would amount to turning redundancy protection off. Only the Linux edition supports primary-port-only mode. To tell the transmit and receive paths apart on Windows, read redundancy_ring_mode / secondary_frame_link_state / the merged WKC; do not change the transmit/receive mode.

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 in this cycle; the merged value is the authoritative measure.

CategoryPropertyTypeR/WDescription
Merged WKCdiag.wkc_actual_mirrorOptional[int]read-onlyNumber of slaves that completed the exchange this cycle (authoritative value); None when the read fails
Expected WKCdiag.wkc_expected_mirrorOptional[int]read-onlyFixed value determined at configuration time; never lowered to accommodate a degraded bus; None when the read fails
Deficitdiag.wc_deficitOptional[int]read-only期望 - 合并实测; only >0 means slaves really dropped out; None when the read fails
Redundancy activediag.redundancy_activeboolread-onlyThe break has been covered by redundancy; always false on linear / folded topologies

Criterion: merged WKC == expected WKC → the network is intact, and a single-port WKC below the expected value is normal in that state; merged WKC < expected WKC → a slave really dropped out, so locate it slave by slave with slave.diagnostics.wc_contributed (the property lives on slave.diagnostics, not on Slave), 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 0xFFFF means no measurement (on the Python side it reads as None when it cannot be read).

The correct way to judge health — rely on the merged WKC:

diag = master.diagnostics_info

# correct: merged WKC == expected WKC, the network is intact (even when a break is covered by redundancy)
link_healthy = (diag.wkc_actual_mirror is not None
and diag.wkc_actual_mirror == diag.wkc_expected_mirror)

if link_healthy and diag.redundancy_active:
print(f"有断点, 但冗余已补齐, 网络仍完整 (合并 WKC={diag.wkc_actual_mirror})") # There is a break, but redundancy has compensated for it and the network is still complete (merged WKC={diag.wkc_actual_mirror})
elif not link_healthy:
print(f"真有从站掉了: 合并 WKC={diag.wkc_actual_mirror} " # A slave really has dropped: merged WKC={diag.wkc_actual_mirror}
f"< 期望={diag.wkc_expected_mirror} (缺额={diag.wc_deficit})") # < expected={diag.wkc_expected_mirror} (deficit={diag.wc_deficit})

Full example​

Redundant networking + health monitoring​

import time
from darra_ethercat import EtherCATMaster, EcState

with EtherCATMaster() as master:
# specify the primary and secondary NIC together (get_network_info() is the recommended way to detect the redundant pair automatically)
# redundancy is enabled automatically by the topology; there is no manual enable call (and none is needed)
master.set_network(
r"\Device\NPF_{primary-guid}",
r"\Device\NPF_{secondary-guid}",
)

master.set_state(EcState.OP)
master.start()

# subscribe to redundancy mode changes
master.on_redundancy_mode_changed(
lambda mi, old, new: print(f"冗余模式: {old} -> {new}") # Redundancy mode: {old} -> {new}
)

# periodic health check — read the redundancy state through the diagnostics module
diag = master.diagnostics_info
while True:
print(f"冗余: ring_mode={master.redundancy_ring_mode}, " # Redundancy: ring_mode={master.redundancy_ring_mode},
f"active={diag.redundancy_active}, "
f"primary_ok={diag.primary_port_ok}, "
f"secondary_ok={diag.secondary_port_ok}")
if diag.break_point is not None:
print(f"故障点: {diag.break_point}") # Fault point: {diag.break_point}
time.sleep(1)
Reference

ETG.1500 §5.7 Cable Redundancy