Slave diagnostics
Each slave provides its own diagnostic properties and sub-objects for port errors, redundancy, Distributed Clocks (DC) synchronization and more.
Drive exception handling from events (such as SlaveStateChanged, SlaveOffline, DCSyncLost) instead of polling.
Reading the slave diagnostic properties directly suits scenarios such as UI display.
Feature overview
| Feature | Access path | Description |
|---|---|---|
| WKC and health mirror | slave.* | Per-slave Working Counter (WKC) / AL / mailbox health diagnostic mirror (WKC and mailbox read as the current value; the AL mirror is a cache sampled while the master is in OP, see AlStatusMirror / AlStatusCode) |
| Communication diagnostics | slave.Diagnostics.ReadPortErrors() | ESC port error counters |
| Redundancy diagnostics | slave.Diagnostics.* | Redundancy activation, primary / redundant line break detection |
| DC synchronization | slave.Diagnostics.DC.* | Sync state, time difference |
| Category | Property | Type | Access | Enable control | Description |
|---|---|---|---|---|---|
| WKC and health mirror | WcContributed | WcContribution | Read-only | Always on | Contribution state of this slave to the Working Counter; a read returns the real result for the current cycle. NotContributed ≠ master fault — it means this slave is not responding right now (possibly lost, or recovering from a hot-plug exchange) |
AlStatusMirror | EcSlaveStatus | Read-only | Always on | Low byte of the AL state of this slave (when the Error bit is set, call .HasFault()). It is a cache sampled while the master is in OP, not the live truth at read time; when not in OP / not sampled it is 0 = unknown | |
AlStatusCode | EcALState | Read-only | Always on | AL Status Code of this slave. Only meaningful when AlStatusMirror carries the Error bit; without Error it returns NoError. When not sampled it returns Unknown, and also when the Error bit is set but the mirror's high byte is 0 — unknown is never reported as no error | |
MailboxHealth | EcMailboxHealth | Read-only | Always on | Mailbox health of this slave. Degraded means the slave is in OP but its mailbox is half-failed (CoE/SDO may block); reported as measured and never involved in altering WKC | |
IsFreeRunDemoted | bool | Read-only | Always on | Whether this slave was forced down to FreeRun synchronization mode. true only when the configuration requires DC but the run-time fell back to FreeRun — the observation point for the root cause of a half-failure | |
HealthDegradedCount | uint | Read-only | Always on | Consecutive count of mailbox half-failure (approximately seconds). 0 = healthy or not evaluated; a rising value means the half-failure has not recovered, and reaching 3 triggers automatic repair | |
RecoverMailboxHealth() | bool | Read-only | Always on | Manually trigger mailbox half-failure repair. Usually you do not need to call it — repair happens automatically after about 3 seconds. Returns false on a communication error instead of throwing | |
| Communication diagnostics | ReadPortErrors() | EscPortErrors? | Read-only | Read the ESC port error counters. Reads the slave registers in real time; returns null on failure | |
| Redundancy diagnostics | RedundancyActivated | bool | Read-only | Always on | Redundancy protection running = master-level RingMode is Dual or Degraded (criterion: RingMode >= 1); always false in linear / fold-back topologies. This is not a per-slave conclusion, and CRC faults do not trigger it |
PrimaryLinkBroken | bool | Read-only | Always on | Primary line break. A break exists on the path from the primary port (Port0) to this slave. Detects physical breaks only, not CRC faults | |
SecondaryLinkBroken | bool | Read-only | Always on | Redundant line break. A break exists on the path from the secondary port (Port1) back to this slave. Detects physical breaks only, not CRC faults | |
| DC synchronization | DC.IsInSync | bool | Read-only | Always on | Whether the slave is inside the sync window (the threshold is controlled by master.Diagnostics.SyncWindowThreshold) |
DC.SyncTimeDifference | int? | Read-only | Always on | Current time difference from the reference clock (nanoseconds); null when the slave has no DC or the read fails |
WcContribution enumeration
| Value | Name | Description |
|---|---|---|
| 0x00 | NotContributed | This slave is not contributing WKC right now (possibly lost / recovering from a hot-plug exchange) |
| 0x01 | Contributed | This slave contributes WKC normally (it responds on the bus) |
| 0xFF | Unknown | Not filled in yet (PDO cycle not running / index out of range) — exposed honestly, never invented |
EcMailboxHealth enumeration
| Value | Name | Description |
|---|---|---|
| 0 | Unknown | Unknown / no mailbox / not in OP — mailbox health is meaningless here |
| 1 | Healthy | Healthy — in OP and the mailbox is available |
| 2 | Degraded | Degraded — in OP but the mailbox is half-failed (handler lost / DC demoted with 0x001F) |
EscPortErrors struct
| Category | Field | Type | Read/write | Description |
|---|---|---|---|---|
| Port errors | RxError | byte[] | Read-only | RX error count per port [Port0-3] |
| InvalidFrame | byte[] | Read-only | Invalid frame count per port [Port0-3] | |
| LostLink | byte[] | Read-only | Link loss count per port [Port0-3] | |
| HasErrors | bool | Read-only | Whether any error is present (read-only derived) |
The WKC / health mirror, redundancy and DC properties are "always on" (always active); you do not need to enable master.Diagnostics.Enabled.
ReadPortErrors() reads the slave in real time; do not call it at a high rate.
WKC and health mirror
These properties are read directly on slave (not under the slave.Diagnostics sub-object). A read returns the current bus diagnostic result without any refresh call. Together with the master-level master.Diagnostics.WcDeficit you can pinpoint the exact slave when one drops out.
WcContributed (slave WKC contribution)
public WcContribution WcContributed { get; }
The contribution state of this slave to the Working Counter (WKC).
Observability contract: NotContributed is not a master fault — it means this slave is not responding right now (possibly lost / recovering from a hot-plug exchange); after the repair it returns to Contributed automatically. Before the value is filled in it honestly returns Unknown (0xFF) instead of inventing one.
AlStatusMirror / AlStatusCode
public EcSlaveStatus AlStatusMirror { get; }
public EcALState AlStatusCode { get; }
AlStatusMirror is the AL state of this slave (low byte = AL State, bit4 = Error bit, test with .HasFault()). When the Error bit is set, AlStatusCode gives the EcALState error code; without Error it returns EcALState.NoError.
This value is a cache refreshed by the master only while it is in OP; it is not the live truth at read time. When the master is not currently in OP (or no sample has been taken yet) the getter returns 0 = not sampled / unknown; only a value other than 0 is a trustworthy sample. Once the master leaves OP the sampler stops and the cache keeps its last sample, so this property no longer claims realtime behaviour.
AlStatusCode extra semantics: Returns Unknown when not sampled, and also when the Error bit is set but the mirror's high byte is 0 — the SDK never reports "unknown" as NoError.
MailboxHealth / IsFreeRunDemoted / HealthDegradedCount / RecoverMailboxHealth()
Makes the hidden fault "in OP but mailbox half-failed" (CoE/SDO blocking) visible to the upper layer. MailboxHealth == Degraded means the slave is still in OP but its mailbox channel is half-failed. A rising HealthDegradedCount means the half-failure has not recovered (it repairs automatically after about 3 seconds); you can also call RecoverMailboxHealth() to intervene manually. Everything is reported faithfully and never involved in altering WKC.
Example:
foreach (var slave in master.Slaves)
{
// WKC contribution: locate a lost slave
if (slave.WcContributed == WcContribution.NotContributed)
Console.WriteLine($"从站 {slave.SlaveNum} 未贡献 WKC, AL={slave.AlStatusCode}"); // Slave {slave.SlaveNum} not contributing WKC, AL={slave.AlStatusCode}
// mailbox half-failure (in OP but CoE may block)
if (slave.MailboxHealth == EcMailboxHealth.Degraded)
{
Console.WriteLine($"从站 {slave.SlaveNum} 邮箱半失效 {slave.HealthDegradedCount}s" + // Slave {slave.SlaveNum} mailbox partially failed for {slave.HealthDegradedCount}s
(slave.IsFreeRunDemoted ? " (被迫 FreeRun)" : "")); // (forced FreeRun)
if (slave.HealthDegradedCount >= 5)
slave.RecoverMailboxHealth(); // usually already repaired automatically; this is manual intervention
}
}
Communication diagnostics
ReadPortErrors()
public EscPortErrors? ReadPortErrors()
Reads the slave ESC port error counters and returns the per-port physical-layer error statistics.
Return value:
EscPortErrors?— port error counters;nullwhen the read fails
Example:
foreach (var slave in master.Slaves)
{
var errors = slave.Diagnostics.ReadPortErrors();
if (errors?.HasErrors == true)
{
var e = errors.Value;
Console.WriteLine($"从站 {slave.SlaveNum}: " + // Slave {slave.SlaveNum}:
$"RX错误=[{string.Join(",", e.RxError)}], " + // RX errors=[{string.Join(
$"无效帧=[{string.Join(",", e.InvalidFrame)}], " + // Invalid frames=[{string.Join(
$"链路丢失=[{string.Join(",", e.LostLink)}]"); // Link loss=[{string.Join(
}
}
Redundancy diagnostics
Access the redundancy state of a slave through slave.Diagnostics. It is meaningful only when redundancy is enabled on the master.
Example:
foreach (var slave in master.Slaves)
{
if (!slave.Diagnostics.RedundancyActivated) continue;
Console.Write($"从站 {slave.SlaveNum}: 冗余激活"); // Slave {slave.SlaveNum}: redundancy active
if (slave.Diagnostics.PrimaryLinkBroken)
Console.Write(", 主线路断路"); // , primary link broken
if (slave.Diagnostics.SecondaryLinkBroken)
Console.Write(", 冗余线路断路"); // , redundancy link broken
Console.WriteLine();
}
DC synchronization
Access the DC synchronization state of a slave through slave.Diagnostics.DC.
IsInSync does and does not meanIsInSync (bool) is the historical boolean contract for whether the slave can be treated as synchronized: it is false when the slave has no DC, when SYNC0 is known to be unarmed, when the read fails, or when the arming result is unknown (failures are visible through ReadFaulted and a Warning log); it returns true when this slave is the reference clock and SYNC0 is armed — 0x092C is by definition N/A for the reference clock itself (no in-sync value is reported for it), and the reference clock cannot be out of step with itself. Both the sync-axis start gate and the clearing of the DC失步 alarm depend on this. That true only means "can be treated as synchronized"; it does not mean a measured deviation exists, nor that the whole network clock has converged.
To tell "known not synchronized" apart from "cannot be determined", use the tri-state slave.Diagnostics.DC.SyncState (DcSyncState): both the reference clock itself and a stale sample are Unknown, and you must not read Unknown as out of sync. The two intentionally differ at the reference clock; do not substitute one for the other.
Example:
foreach (var slave in master.Slaves)
{
if (!slave.HasDC) continue;
var dc = slave.Diagnostics.DC;
Console.WriteLine($"从站 {slave.SlaveNum}: " + // Slave {slave.SlaveNum}:
$"时间差={dc.SyncTimeDifference?.ToString() ?? "n/a"}ns, " + // Time diff={dc.SyncTimeDifference?.ToString() ??
$"同步={dc.IsInSync}"); // In sync={dc.IsInSync}
}
Full example
foreach (var slave in master.Slaves)
{
Console.WriteLine($"--- 从站 {slave.SlaveNum}: {slave.Name} ---"); // --- Slave {slave.SlaveNum}: {slave.Name} ---
// port errors
var errors = slave.Diagnostics.ReadPortErrors();
if (errors?.HasErrors == true)
{
var e = errors.Value;
Console.WriteLine($" 端口错误: RX=[{string.Join(",", e.RxError)}], " + // Port errors: RX=[{string.Join(
$"无效帧=[{string.Join(",", e.InvalidFrame)}], " + // Invalid frames=[{string.Join(
$"链路丢失=[{string.Join(",", e.LostLink)}]"); // Link loss=[{string.Join(
}
// redundancy (meaningful only in redundancy mode)
if (slave.Diagnostics.RedundancyActivated)
{
Console.WriteLine($" 冗余激活: 主线路断={slave.Diagnostics.PrimaryLinkBroken}, " + // Redundancy active: primary link broken={slave.Diagnostics.PrimaryLinkBroken},
$"冗余线路断={slave.Diagnostics.SecondaryLinkBroken}"); // redundancy link broken={slave.Diagnostics.SecondaryLinkBroken}
}
// DC synchronization
if (slave.HasDC)
{
Console.WriteLine($" DC: 时间差={slave.Diagnostics.DC.SyncTimeDifference?.ToString() ?? "n/a"}ns, " + // DC: time diff={slave.Diagnostics.DC.SyncTimeDifference?.ToString() ??
$"同步={slave.Diagnostics.DC.IsInSync}"); // In sync={slave.Diagnostics.DC.IsInSync}
}
}