Redundancy
EtherCAT redundancy uses dual NICs plus a ring topology to provide 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 on both sides by WKC, so the whole network keeps running.
Read the redundancy state and the transmit/receive mode directly through master, and view redundancy diagnostics through master.diagnostics(); RedundancyManager (new RedundancyManager(master.MasterIndex)) provides the same set of conclusions plus the redundant process data switch.
Redundancy is enabled automatically by topology detection (the redundant process data mode is written according to the topology): name the secondary NIC with setNetwork(primary, secondary) when you construct the master, and closing the ring forms the protection. There is no manual on/off API and no manual forced-failover API, and none is needed. EnableRedundancy has been removed (no-op switch); ForceRedundancyFailover is a retired entry point that always returns FALSE (bidirectional redundancy with dual send + WKC merge provides the tolerance automatically, and there is no manual switching path), and the Java SDK does not expose enableRedundancy / forceRedundancyFailover. To observe the real state, read checkRedundancyHealth() / redundancyRingMode() / secondaryFrameLinkState().
- Redundancy link state change event:
addRedundancyModeChangedListener
Status and diagnostics
| Category | Method | Type | R/W | Description |
|---|---|---|---|---|
| Status | checkRedundancyHealth() | boolean | Read-only | Check the redundancy health state |
| redundancyStatus() | DarraCore.RedundancyStatus | Read-only | Redundancy state snapshot (state / primary and secondary link bits / frames sent and received per port / failover); returns null when it cannot be read, field table below | |
| redundancyRingMode() | int | Read-only | Raw value of the redundancy ring operating mode, convertible to the enum with EtherCATTypes.RingMode.fromValue(...); ringMode() is a compatibility alias | |
| secondaryFrameLinkState() | EtherCATTypes.PhyLinkState | Read-only | Frame-level link tri-state of the secondary port: UP=1, DOWN=0, UNKNOWN=-1 | |
| secondaryLinkStatus() | boolean | Read-only | Compatibility health check: true only when definitely Up; Down and unknown are both false | |
| diagnostics().isRedundancyActive() | boolean | Read-only | The break is covered by redundancy; always false in line / fold-back topologies | |
| Redundant process data | setRedProcessdata(int mode) | boolean | R/W | Set the redundancy processing mode (0 = standard ETG redundancy / 1 = primary port only / 2 = dynamic bidirectional redundancy). true = applied; false = not applied (the current platform does not support that mode, or mode is invalid — see the platform difference below) |
| redProcessdata() | int | R/W | Get the current redundancy processing mode (0/1/2) | |
| RedundancyManager | getStatus() | RedundancyStatus | Read-only | Raw counters and link bits (frames sent and received per port, failover count, and so on) |
| engineState() | RedundancyEngineState | Read-only | Redundancy state conclusion determined by the engine (healthy / A broken / B broken / middle broken / all lost / unknown) | |
| checkHealth() | boolean | Read-only | Check the redundancy health state (the same conclusion as master.checkRedundancyHealth()) | |
| getRedProcessdata() | int | Read-only | Get the current redundancy processing mode (the same switch as master.redProcessdata()) |
getStatus() / engineState() / checkHealth() / getRedProcessdata()
public RedundancyManager.RedundancyStatus getStatus()
public RedundancyEngineState engineState()
public boolean checkHealth()
public int getRedProcessdata()
Read-only entry points of RedundancyManager, constructed with new RedundancyManager(master.MasterIndex).
getStatus()— raw counters and link bits: frames sent and received on the primary / secondary port, failover count and the most recent failover time, and so on; returnsnullwhen it cannot be read.engineState()— redundancy state conclusion determined by the engine:Healthy/ALinkDown/BLinkDown/MiddleBroken/TotalLost/Unknown; values outside that domain map toUnknownand are never folded intoHealthy.checkHealth()— the same health conclusion asmaster.checkRedundancyHealth().getRedProcessdata()— the same process-wide switch reading asmaster.redProcessdata().
The methods of RedundancyManager throw IllegalStateException when the master has not been created, is shutting down, or has been released.
checkRedundancyHealth()
public boolean checkRedundancyHealth()
Check the redundancy health state.
redundancyStatus()
public DarraCore.RedundancyStatus redundancyStatus()
Returns a redundancy state snapshot. The return value is a self-contained value copy (DarraCore.RedundancyStatus, detached from the buffer it was read from), so the caller may hold it for a long time and read its fields freely. null = redundancy not enabled / not connected / read failed (a failed read is logged).
| Field | Type | Description |
|---|---|---|
| State | int | Redundancy state (0 = None, not enabled; 1 = Primary, primary port only; 2 = Secondary, secondary port only; 3 = Both, dual NICs) |
| PrimaryLinkUp | int | Whether the primary link is up (a value other than 0 = up) |
| SecondaryLinkUp | int | Whether the secondary link is up (a value other than 0 = up) |
| PrimaryTxFrames / PrimaryRxFrames | int | Frames sent / received on the primary link |
| SecondaryTxFrames / SecondaryRxFrames | int | Frames sent / received on the secondary link |
| FailoverCount | int | Number of failovers |
| LastFailoverTime | int | Time of the last failover (Unix timestamp, seconds) |
This method returns DarraCore.RedundancyStatus (a snapshot struct whose fields are int); RedundancyManager.getStatus() returns RedundancyManager.RedundancyStatus (a strongly typed wrapper with the RedundancyState enum and rawState). The two share a name but are not the same type; tell them apart by the entry point and do not mix them.
redundancyRingMode()
public int redundancyRingMode()
Get the raw value of the redundancy ring operating mode. Returns int (0 / 1 / 2), which can be converted to the strongly typed EtherCATTypes.RingMode enum:
int raw = master.redundancyRingMode();
EtherCATTypes.RingMode mode = EtherCATTypes.RingMode.fromValue(raw); // INACTIVE / DUAL / DEGRADED
EtherCATTypes.RingMode enum
public enum RingMode {
INACTIVE(0), // not active: redundancy monitoring not initialized
DUAL(1), // bidirectional redundancy: both ends send LRW
DEGRADED(2); // degraded mode: only the primary port is working
}
secondaryFrameLinkState() / secondaryLinkStatus()
public EtherCATTypes.PhyLinkState secondaryFrameLinkState()
public boolean secondaryLinkStatus()
Prefer secondaryFrameLinkState() to distinguish UP / DOWN / UNKNOWN. secondaryLinkStatus() is only for compatibility health checks: it is true only when definitely Up, and false for Down and for unknown.
setRedProcessdata(int mode) / redProcessdata()
public boolean setRedProcessdata(int mode) // same name on EtherCATMaster and RedundancyManager
public int redProcessdata() // EtherCATMaster; on RedundancyManager it is getRedProcessdata()
Set / get the redundancy processing mode. This is a process-wide global switch that affects every master in this process. Modes: 0 = standard ETG redundancy (default), 1 = primary port only, 2 = dynamic bidirectional redundancy (dual send + merge).
- Returns
true: applied. - Returns
false: not applied (the current platform does not support that mode, ormodeis not 0/1/2). In that caseredProcessdata()keeps its previous value and never reports a new mode that is not in effect.
The Windows edition always sends on both ports — as long as a secondary port is bound, every cyclic frame leaves through both the primary and the secondary port: this is the physical precondition for a frame to go out the secondary port and come back to form the protection ring in a ring topology. setRedProcessdata(1) (primary port only) is therefore not implemented on Windows; the call returns false explicitly and applies nothing — it is not silently ignored, since applying it would amount to turning off the redundancy protection. Primary-only mode is supported on Linux only. To distinguish the transmit and receive paths on Windows, read redundancyRingMode() / secondaryLinkStatus() / the merged WKC, not the processing mode.
Redundant WKC (merged WKC)
In ring redundancy the SDK merges the WKC from 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 | Return type | R/W | Description |
|---|---|---|---|---|
| Merged WKC | WKC() | short | Read-only | Slaves that completed the exchange this cycle (authoritative value) |
| Expected WKC | expectedWKC() | short | Read-only | Fixed true value determined at configuration time; never lowered to accommodate a degrading bus |
| Deficit | diagnostics().getWcDeficit() | int | Read-only | expectedWKC - WKC; only >0 means slaves really dropped out |
| Redundancy active | diagnostics().isRedundancyActive() | boolean | Read-only | The break is 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 the expected value is normal at that point; merged WKC < 期望 WKC → slaves really dropped out; locate them one by one with slave.wcContributed(), and the count returns to zero automatically once the slaves recover. Single-port WKC (primaryWkcRt() / secondaryWkcRt()) is used only to locate the break, not to judge health; on the diagnostics side, diagnostics().secondaryWkc() equal to WKC_UNKNOWN (0xFFFF) means there is no measurement in this cycle (0 is a valid reading; use diagnostics().secondaryWkcKnown() to test for "unknown").
if (master.WKC() != master.expectedWKC()) {
System.out.printf("真掉站: 缺额 %d,逐站查 slave.wcContributed()%n", // Real slave loss: deficit %d, check slave.wcContributed() slave by slave%n
master.diagnostics().getWcDeficit());
} else if (master.diagnostics().isRedundancyActive()) {
System.out.println("有断点,冗余已补齐,网络完整"); // There is a break, redundancy has covered it, the network is complete
}
Full example
Redundancy topology + health monitoring
try (EtherCATMaster master = EtherCATMaster.create()) {
// the secondary NIC is named at construction time; closing the ring forms the redundancy protection automatically, with nothing to enable by hand
master.setNetwork("\\Device\\NPF_{primary-guid}", "\\Device\\NPF_{secondary-guid}");
// subscribe to redundancy mode changes (the parameters are raw int values)
master.events().addRedundancyModeChangedListener((mi, oldMode, newMode) -> {
System.out.printf("冗余模式: %d -> %d%n", oldMode, newMode); // Redundancy mode: %d -> %d%n
});
if (!master.setState(EcState.OP)) {
System.out.println("进入 OP 失败, 状态 " + master.state()); // Failed to enter OP, state {master.state()}
return;
}
master.start();
// periodic health check
while (true) {
boolean healthy = master.checkRedundancyHealth();
int mode = master.redundancyRingMode();
boolean secOk = master.secondaryLinkStatus();
System.out.printf("冗余: healthy=%b ring_mode=%d secondary_link=%b%n", // Redundancy: healthy=%b ring_mode=%d secondary_link=%b%n
healthy, mode, secOk);
Thread.sleep(1000);
}
}
Break location
// merged WKC below expected = slaves really dropped out; single-port WKC only locates the direction of the break, it does not judge health
if (master.diagnostics().isRedundancyActive()) {
System.out.printf("断点已被冗余补齐: 主口 WKC=%d, 副口 WKC=%d%n", // The break has been covered by redundancy: primary port WKC=%d, secondary port WKC=%d%n
master.primaryWkcRt() & 0xFFFF, master.secondaryWkcRt() & 0xFFFF);
}
- ETG.1500 §5.7 Cable Redundancy