Skip to main content

Redundancy

EtherCAT redundancy uses two 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 reported by both sides through the Working Counter (WKC), so the whole network keeps running.

Query redundancy state through master.Diagnostics; enable redundancy by naming both NICs at initialization.​

How to enable it

Redundancy is enabled at initialization by passing both NICs to SetNetwork(primary, redundant); there is no separate on/off API. Nothing needs to be controlled by hand at runtime.

Related pages

Redundancy state query API​

Query runtime redundancy state through the public properties of master.Diagnostics (type MasterDiagnosticsInfo); you do not create a redundancy manager yourself. Detailed line state comes straight from Diagnostics.RedundancyStatus. Common properties:

CategoryPropertyTypeRead/writeDescription
RedundancyRedundancyActiveboolRead-onlyRedundancy protection is running = RingMode>=1 (Dual/Degraded) and both ports carried frame traffic in this window; false for line / end-return topologies even when both ports carry frames
RedundancyRingModeRingModeRead-onlyRedundancy ring operating mode (Inactive / Dual / Degraded); the RingMode property is a compatibility alias
RedundancyStatusRedundancyStatus?Read-onlyDetailed redundancy line state (link up per line, failover count and time); null when unavailable or on failure
NICPrimaryPortOkboolRead-onlyWhether the primary port is healthy
SecondaryPortOkboolRead-onlyWhether the secondary port is healthy (always false without redundancy)
PrimaryPortErrorsuintRead-onlyErrors on the primary port in the last 5 seconds
SecondaryPortErrorsuintRead-onlyErrors on the secondary port in the last 5 seconds
FaultBreakPointBreakPointInfo?Read-onlyLocates the break / CRC fault point
RedundancyStatus structure / RedundancyState enum

The redundancy state object returned by Diagnostics.RedundancyStatus (the RedundancyStatus class):

CategoryPropertyTypeRead/writeDescription
Line stateStateRedundancyStateRead-onlyRedundancy state enum
PrimaryLinkUpboolRead-onlyWhether the primary link is up
SecondaryLinkUpboolRead-onlyWhether the secondary link is up
Frame countPrimaryTxFramesuintRead-onlyCumulative frames sent on the primary line
PrimaryRxFramesuintRead-onlyCumulative frames received on the primary line
SecondaryTxFramesuintRead-onlyCumulative frames sent on the secondary line
SecondaryRxFramesuintRead-onlyCumulative frames received on the secondary line
FailoverFailoverCountuintRead-onlyCumulative failover count
LastFailoverTimeDateTimeRead-onlyLocal time of the most recent failover; DateTime.MinValue if a failover never happened

RedundancyState has four values: None(0) no redundancy / Primary(1) primary network only / Secondary(2) secondary network only / Both(3) both networks active in redundancy.

Topology is the criterion (not "two NICs configured")​

"A secondary NIC is configured" is a configuration fact; it does not mean "there is a redundancy ring" or "there is a second path". In a purely line topology with two NICs fitted, the port link state and RedundancyActive may both look healthy, yet a break anywhere leaves no spare leg. To judge the protection actually available, read the topology model.

CategoryMemberTypeRead/writeDescription
Mastermaster.SecondaryLinkRoleSecondaryLinkRoleRead-onlyRole of the secondary port in the topology: Unknown / NoProtectionPath / ProtectionPath
Runtimemaster.Diagnostics.RedundancyRingModeRingModeRead-onlyHow the redundancy engine is running right now; Inactive does not mean a line topology
Runtimemaster.Diagnostics.RingModeRingModeRead-onlyCompatibility alias, same value as RedundancyRingMode

SecondaryLinkRole has three values: ProtectionPath — the secondary port is part of the protection path / NoProtectionPath — line topology or a single NIC, the secondary port carries no protection / Unknown — the topology cannot be determined.

Unknown folds to neither side

Unknown must be read neither as "redundancy protection is present" (the site would assume there is a backup) nor as "single path and already broken". Callers must degrade honestly while the value is Unknown.

var role = master.SecondaryLinkRole;
if (role == SecondaryLinkRole.ProtectionPath)
Console.WriteLine("副口是保护路径的一部分"); // The secondary port is part of the protection path
else if (role == SecondaryLinkRole.NoProtectionPath)
Console.WriteLine("无保护路径(线性拓扑),断线即失联"); // No protection path (linear topology); a cable break means loss of contact
else
Console.WriteLine("拓扑未知:不判断副口保护能力"); // Topology unknown: secondary port protection capability cannot be determined

Failover semantics​

Redundancy is enabled automatically by topology detection (just name both NICs in SetNetwork(primary, redundant) at initialization); there is no manual path switch: with bidirectional redundancy both sides carry frames at the same time and the SDK merges the send and receive paths, so there is no manual entry point for "switch the send path to the secondary port". There is also no API to force a failover by hand. Tolerance and recovery after a break are fully automatic; observe the real state with Diagnostics.RedundancyStatus / RedundancyActive / RedundancyRingMode / BreakPoint.

Redundancy WKC (merged WKC)​

In 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.

CategoryPropertyTypeRead/writeDescription
Merged WKCDiagnostics.WKCushortRead-onlySlaves that completed the exchange this cycle (authoritative value)
Expected WKCDiagnostics.ExpectedWKCushortRead-onlyFixed true value determined at configuration time; never lowered to accommodate a degrading bus
DeficitDiagnostics.WcDeficitintRead-onlyExpectedWKC - WKC; only >0 means slaves really dropped
Redundancy activeDiagnostics.RedundancyActiveboolRead-onlyThe 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 expected is normal at that point; merged WKC < expected WKC → slaves really dropped; locate them one by one with slave.WcContributed, and it returns to zero automatically once the slaves recover. Single-port WKC (PrimaryWKC / SecondaryWKC) only locates the break; it does not judge health. A secondary port that stays at 0xFFFF means nothing was measured.

var diag = master.Diagnostics;
if (diag.WKC != diag.ExpectedWKC)
Console.WriteLine($"真掉站: 缺额 {diag.WcDeficit},逐站查 slave.WcContributed"); // Real slave loss: deficit {diag.WcDeficit}, check slave.WcContributed slave by slave
else if (diag.RedundancyActive)
Console.WriteLine("有断点,冗余已补齐,网络完整"); // There is a break, redundancy has covered it, the network is complete

Redundant process data mode (RedProcessdata)​

Process data mode for ring + branch topologies. It is process-wide: changing it affects redundant dual sending for every master in this process.

RedProcessdata​

public static RedProcessdataMode RedProcessdata { get; }

Reads the current redundant process data mode.

Related type:

public enum RedProcessdataMode : int
{
Standard = 0, // standard ETG redundancy (default)
PrimaryOnly = 1, // primary port only; not implemented on Windows (always dual send), the setting is refused truthfully
DualSendMerge = 2 // dynamic bidirectional redundancy (dual send + merge)
}

Exceptions:

  • InvalidOperationException — the SDK returned a value other than 0/1/2 (the contract allows these three only; no guessing, no folding)

SetRedProcessdata(RedProcessdataMode mode)​

public static bool SetRedProcessdata(RedProcessdataMode mode)

Sets the process data mode for ring + branch topologies (process-wide; affects every master in this process).

Parameters:

  • mode (RedProcessdataMode) — Standard = standard ETG redundancy; PrimaryOnly = primary port only; DualSendMerge = dynamic bidirectional redundancy (dual send + merge). Anything other than 0/1/2 throws ArgumentOutOfRangeException

Returns:

  • bool — true = applied; false = not applied (the current platform does not support that mode)
Windows always sends on both ports

On Windows, as long as a secondary port is configured, every cyclic frame leaves through both the primary and the secondary port (in a ring topology a frame has to go out the secondary port and come back to form the protection ring). PrimaryOnly is therefore not implemented on Windows: SetRedProcessdata(RedProcessdataMode.PrimaryOnly) returns false truthfully and sends not a single byte — it is not silently ignored and not folded into another mode. When nothing is applied, RedProcessdata keeps its previous value and never reports a new mode that is not in effect.

Example:

bool applied = DarraEtherCAT.SetRedProcessdata(RedProcessdataMode.DualSendMerge);
Console.WriteLine($"当前模式 {DarraEtherCAT.RedProcessdata},下发={applied}"); // Current mode {DarraEtherCAT.RedProcessdata}, applied={applied}

Full example​

Enable redundancy and monitor health​

// Enable redundancy through two NICs (prefer GetNetworkInfo to detect the redundancy pair automatically)
var adapters = DarraEtherCAT.GetNetworkInfo();
var pair = adapters.Where(a => a.RedundantSlaveNum > 0).Take(2).ToList();
if (pair.Count < 2) return;

var master = new DarraEtherCAT()
.SetNetwork(pair[0], pair[1])
.SetENI(@"C:\config.deni")
.Build()
.Master;
if (master == null) return;

// Subscribe to redundancy mode changes (callback signature: ushort masterIndex, int oldMode, int newMode)
master.Events.RedundancyModeChanged += (masterIndex, oldMode, newMode) =>
{
Console.WriteLine($"冗余模式: {oldMode} -> {newMode}"); // Redundancy mode: {oldMode} -> {newMode}
};

master.SetState(EcState.OP);

// Periodic health check — read redundancy state through the diagnostics module
var diag = master.Diagnostics;
while (true)
{
Console.WriteLine($"冗余: ring_mode={diag.RedundancyRingMode}, " + // Redundancy: ring_mode={diag.RedundancyRingMode},
$"active={diag.RedundancyActive}, " +
$"primary_ok={diag.PrimaryPortOk}, secondary_ok={diag.SecondaryPortOk}");
if (diag.BreakPoint != null)
Console.WriteLine($"故障点: {diag.BreakPoint}"); // Fault point: {diag.BreakPoint}
Thread.Sleep(1000);
}