Slave diagnostics
Each slave provides its own diagnostic properties and sub-objects for port errors, redundancy, Distributed Clocks (DC) synchronization and other information.
Drive exception handling from events (such as addSlaveStateChangedListener, addSlaveOfflineListener, addDCSyncLostListener) instead of polling.
Reading the slave diagnostic properties directly suits scenarios such as UI display.
Feature overview
| Category | Feature | R/W | Access path | Description |
|---|---|---|---|---|
| State mirror | State mirror | Read-only | slave.wcContributed() / mailboxHealth() and so on | Per-slave WcState / AL / mailbox health mirrors (WKC and mailbox read as the current value; the AL mirror is a cache sampled while the master is in OP) |
| Communication diagnostics | Communication diagnostics | Read-only | slave.diagnostics().readPortErrors() | ESC port error counters |
| Redundancy diagnostics | Redundancy diagnostics | Read-only | slave.redundancyActivated() and so on | Redundancy activation, primary / redundant line break detection |
| Per-slave diagnostics | Per-slave reachable leg / liveness reason / clean OP / SYNC0 armed | Read-only | master.events().tryGetSlaveOfflineReason(...) / master.diagnostics().evaluateSlaveRealOp(...) / slave.DC().sync0Armed() | Slave loss reason, clean OP, SYNC0 armed (the reachable leg currently has no public read entry point) |
| DC synchronization | DC synchronization | Read-only | slave.DC().getSyncWindowStatus() | Sync state, time difference |
Properties
| Category | Method | Type | R/W | Description |
|---|---|---|---|---|
| Communication diagnostics | readPortErrors() | EscPortErrors | Read-only | Read the ESC port error counters (slave.diagnostics()) |
| resetPortErrors() | boolean | Write-only | Reset the port error counters (slave.diagnostics()) | |
| linkQuality() | short | Read-only | Link quality (0-100%, -1 = unknown, 0 is not used to pretend 0%) (slave.diagnostics()) | |
| Redundancy diagnostics | redundancyActivated() | boolean | Read-only | Redundancy protection is running = master-level redundancyRingMode() >= 1 (Dual / Degraded); always false in linear / end fold-back topologies, and not an independent per-slave conclusion. A failed read cannot be told apart from "the value really is not activated"; use redundancyActivatedOrNull() when you need the difference |
| primaryLinkBroken() | boolean | Read-only | Primary line break. A break exists on the path from the primary port (port 0) to this slave. Use primaryLinkBrokenOrNull() when you need to tell a failed read apart | |
| secondaryLinkBroken() | boolean | Read-only | Redundant line break. A break exists on the path from the secondary port (port 1) back to this slave. Use secondaryLinkBrokenOrNull() when you need to tell a failed read apart | |
| DC synchronization | DC().getSyncWindowStatus() | SyncWindowStatus | Read-only | Sync window state (time difference, whether in sync, and so on) |
| Per-slave true WKC probe | getSlaveWkcProbeActual(short slaveIndex) | int | Read-only | Per-slave true WKC (value measured by the probe datagram): >=0 = true value (0 = there was an echo but this slave did not contribute; 0 is a valid reading) / -2 = sent but no echo (not disguised as 0) / -1 = no sample or read failed. slaveIndex is 1-based. Unreadable = unknown, never invented |
| getSlaveWkcProbeExpected(short slaveIndex) | int | Read-only | Expected WKC: 1 = expected / -1 = not probeable (no read mapping / out of range) or read failed. Unreadable = unknown, never invented | |
| getSlaveWkcProbeSampleAgeMs(short slaveIndex) | int | Read-only | Sample age: >=0 = milliseconds since the most recent sample / -1 = never sampled or read failed | |
| getPerSlaveWkcProbeMode() | int | Read-only | Probe mode: 0 = OFF / 1 = PROBE_READ / -1 = read failed (unknown, not disguised as 0 = OFF). The mode defaults to OFF, and while it is OFF it has no behaviour | |
| setPerSlaveWkcProbeMode(short mode) | boolean | Write-only | Set the probe mode (0 = OFF / 1 = PROBE_READ); true = the call was delivered, false = it could not be delivered (not provided by an older runtime / exception) and the mode change is unconfirmed. The read-only probe does not change the WKC contract (ExpectedWKC / ActualWKC semantics are unchanged), does not take a slave out of OP, and does not drive fault judgement or recovery |
The five per-slave true WKC probe items are called through new Diagnostics(master.MasterIndex) (com.darra.ethercat.master.Diagnostics), not through a method on the slave sub-object.
EscPortErrors struct:
| Field | Type | R/W | Description |
|---|---|---|---|
| RxError | byte[4] | Read-only | RX error count per port [ports 0-3] |
| InvalidFrame | byte[4] | Read-only | Invalid frame count per port [ports 0-3] |
| LostLink | byte[4] | Read-only | Link loss count per port [ports 0-3] |
| FwdRxError | byte[4] | Read-only | Forwarded RX error count per port [ports 0-3]; when it could not be read it is a placeholder of all 0s — use FwdRxErrorReadOK to tell |
| FwdRxErrorReadOK | boolean | Read-only | false = FwdRxError is a placeholder of all 0s and not a real value (do not conclude "no forwarding errors" from it); the other three fields are unaffected and remain trustworthy |
| hasErrors() | boolean | Read-only | Whether any error is present (FwdRxError does not take part in the decision when it could not be read) |
The redundancy and DC properties are always active.
readPortErrors() reads the slave in real time; do not call it at a high rate.
State mirror
A slave offers state mirror access: no extra frames are sent. wcContributed() and the mailbox health methods read as the current value; alStatusMirror() is not in that category (see the sampling semantics below). This suits high-rate UI refresh and slave loss detection.
| Category | Method | Type | R/W | Description |
|---|---|---|---|---|
| WKC contribution | wcContributed() | EcWcContributed | Read-only | Whether this slave contributed its expected WKC this cycle (a per-slave status bit) |
| AL state mirror | alStatusMirror() | EcAlStatusMirror | Read-only | Mirror of the slave AL state (a 16-bit raw cache sampled while the master is in OP; contains AL State + Error + AL Status Code; raw=0 = unknown when not in OP / not sampled) |
| Mailbox health | mailboxHealth() | EcMailboxHealth | Read-only | Mailbox health of this slave (real-time state). DEGRADED means the slave is in OP but its mailbox is half-failed (CoE/SDO may block); reported faithfully and never involved in WKC judgement |
| Mailbox health | isFreeRunDemoted() | boolean | Read-only | Whether this slave was forced down to FreeRun synchronization mode (real-time). 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 |
| Mailbox health | healthDegradedCount() | long | Read-only | Consecutive count of mailbox half-failure (approximately seconds; the unsigned uint32 has been restored with & 0xFFFFFFFFL). 0 = healthy or not evaluated; a rising value means the half-failure has not recovered, and the runtime triggers automatic repair after a few seconds |
| Mailbox health | recoverMailboxHealth() | boolean | Write-only | Manually trigger mailbox half-failure repair. Usually you do not need to call it — the runtime repairs automatically when it detects that the half-failure has lasted for a few seconds. Returns false on a communication error instead of throwing |
| Slave loss flag | isLost() | boolean | Read-only | Whether the slave is lost |
EcWcContributed enum
public enum EcWcContributed {
CONTRIBUTED(1), // this slave contributed its expected WKC this cycle (it responds on the bus)
NOT_CONTRIBUTED(0), // this slave did not contribute WKC this cycle (possibly lost / abnormal)
UNKNOWN(0xFF); // unknown — the runtime has not provided data for this slave yet (honest sentinel, never inventing online or lost)
}
isKnown()— whether the data is trustworthy (notUNKNOWN). The UI uses it to decide between showing a real value and showing "unknown".
EcAlStatusMirror struct
Parsed object returned by alStatusMirror(); it splits the 16-bit raw mirror into enums:
getRaw()(int) — the raw 16-bit mirror value (unsigned, 0..65535)getAlState()(EcState) — base AL State enum (without the Error flag)hasError()(boolean) — whether the slave is in an error state (bit 4 set)getAlStatusCode()(EcALState) — AL Status Code enum (valid only when Error is set, otherwiseNO_ERROR); when the mirror is not sampled (raw == 0) checkisKnown()first and do not treat the high byte'sNO_ERRORas "no error"isKnown()(boolean) — whether the data is trustworthy (raw == 0means no sample has been taken yet / the master is not currently in OP; the UI should show "unknown")
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.
mailboxHealth() / isFreeRunDemoted() / healthDegradedCount() / recoverMailboxHealth()
This makes the hidden fault "in OP but mailbox half-failed" (CoE/SDO blocking) visible to the layer above. 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 a few seconds); you can also call recoverMailboxHealth() to intervene manually. Everything is reported faithfully and does not affect the WKC judgement (the semantics of expected WKC and actual WKC are unchanged).
EcMailboxHealth enum
public enum EcMailboxHealth {
UNKNOWN(0), // unknown — no mailbox / not in OP / not provided by the runtime yet (honest sentinel)
HEALTHY(1), // healthy — in OP and the mailbox is available
DEGRADED(2); // degraded — in OP but the mailbox is half-failed (mailbox channel abnormal / DC demoted with 0x001F)
}
isKnown()— whether the data is trustworthy (notUNKNOWN). The UI uses it to decide between showing a real value and showing "unknown".
Example:
for (Slave slave : master.slaves()) {
// mailbox half-failure (in OP but CoE may block)
if (slave.mailboxHealth() == EcatSlaveDiag.EcMailboxHealth.DEGRADED) {
System.out.printf("从站 %d 邮箱半失效 %ds%s%n", // Slave %d mailbox partially failed for %ds%s%n
slave.SlaveNum, slave.healthDegradedCount(),
slave.isFreeRunDemoted() ? "(被迫 FreeRun)" : ""); // (forced FreeRun)
if (slave.healthDegradedCount() >= 5) {
slave.recoverMailboxHealth(); // usually the runtime has already repaired it; this is manual intervention
}
}
}
wcContributed(), alStatusMirror() and mailboxHealth() return UNKNOWN / unknown honestly while the data is not ready, and never invent an online or lost state.
Example:
for (Slave slave : master.slaves()) {
EcatSlaveDiag.EcWcContributed wc = slave.wcContributed();
if (wc == EcatSlaveDiag.EcWcContributed.NOT_CONTRIBUTED) {
System.out.printf("从站 %d 本周期未贡献 WKC,疑似掉站%n", slave.SlaveNum); // Slave %d did not contribute WKC this cycle, suspected slave loss%n
}
EcatSlaveDiag.EcAlStatusMirror al = slave.alStatusMirror();
if (al.isKnown() && al.hasError()) {
System.out.printf("从站 %d AL 错误: %s, Code=%s%n", // Slave %d AL error: %s, Code=%s%n
slave.SlaveNum, al.getAlState(), al.getAlStatusCode());
}
}
Communication diagnostics
readPortErrors()
public EscPortErrors readPortErrors()
Reads the slave ESC port error counters and returns the physical-layer error statistics per port.
Returns:
EscPortErrors-- port error counters; returnsnullwhen the read fails
Example:
for (Slave slave : master.slaves()) {
EscPortErrors errors = slave.diagnostics().readPortErrors();
if (errors != null && errors.hasErrors()) {
System.out.printf("从站 %d: RX错误=%s, 无效帧=%s, 链路丢失=%s%n", // Slave %d: RX errors=%s, invalid frames=%s, link loss=%s%n
slave.SlaveNum,
Arrays.toString(errors.RxError),
Arrays.toString(errors.InvalidFrame),
Arrays.toString(errors.LostLink));
}
}
resetPortErrors()
public boolean resetPortErrors()
Resets the port error counters of this slave (the ESC port error statistics are cleared).
Returns:
boolean—true= reset;false= not reset
linkQuality()
public short linkQuality()
Gets the link quality.
Returns:
short—0..100= link quality percentage;-1= read failed (unknown). The real value domain never contains-1, and0is not used to pretend "0% link quality".
Topology information
Access the slave-level SlaveTopology through slave.topology(); access the master-level topology through master.slaveTopology().
| Category | Method | Type | R/W | Description |
|---|---|---|---|---|
| Topology information | count() | int | Read-only | Number of root nodes at master level (the entry port type is MII, or ParentStation==0 connects directly to the master). An EBUS module attached under a coupler does not count as a root. The slave-level topology has no master list and returns 0. This is not master.slaveCount() (the total number of slaves on the network) |
| entryPort() | byte | Read-only | Entry port | |
| parentPort() | int | Read-only | Parent port number: 0..3, -1 = unknown or invalid parameter | |
| parentStation() | short | Read-only | Parent station address (note: this is actually the 1-based slave index, not a station address; 0 means the parent is the master) | |
| physicalType() | byte | Read-only | Physical type | |
| linkCount() | int | Read-only | Number of links: 1..4 = measured link count, -1 = unknown or invalid parameter (including the 0 placeholder when DLSTAT could not be read); unknown does not mean offline | |
| topologyType() | int | Read-only | Topology structure class (a configuration-time snapshot, not refreshed at run time; a different quantity from linkCount()): 0 = no link / 1 = end point / 2 = line intermediate node / 3 = branch point / 4 = crossing point / -1 = unavailable | |
| topologyByte() | int | Read-only | Compatibility alias of linkCount() (returns the measured link count, not the topology structure class; the name is historical) | |
| activePorts() | byte | Read-only | Active ports | |
| consumedPorts() | byte | Read-only | Number of ports in use |
Per-slave reachable leg / liveness reason / clean OP / SYNC0 armed
The per-slave conclusions are read through public high-level interfaces:
| Conclusion | Public interface | Returns | R/W | Description |
|---|---|---|---|---|
| Loss reason | master.events().tryGetSlaveOfflineReason(int) | SlaveOfflineReason | Read-only | Reads the cache / an existing conclusion only, no frame is sent; the categories are in events |
| Clean OP / real OP | master.diagnostics().evaluateSlaveRealOp(int) | SlaveRealOpState | Read-only | Per-slave real-OP verdict; SlaveRealOpState.alCleanOp is the clean OP |
| SYNC0 armed | slave.DC().sync0Armed() | Boolean (tri-state) | Read-only | null = the runtime cannot answer; it must not be folded into false |
The reachable leg / evidence bits currently have no public read entry point; for the public redundancy conclusions see slave.redundancyActivated() / slave.primaryLinkBroken() / slave.secondaryLinkBroken() in redundancy diagnostics.
"Cannot answer" (model not ready / insufficient evidence / criterion unavailable) is not the same as "not armed / no ring / not clean": treat it as "conclusion unavailable" across the board, and never fold it into false or 0.
Redundancy diagnostics
Access the redundancy state of a slave directly through Slave properties. It is meaningful only when redundancy is enabled on the master.
| Method | Type | R/W | Description |
|---|---|---|---|
| slave.redundancyActivated() | boolean | Read-only | Whether this slave is communicating over a working redundant path |
| slave.primaryLinkBroken() | boolean | Read-only | Whether the path from the primary port (port 0) to this slave is broken |
| slave.secondaryLinkBroken() | boolean | Read-only | Whether the path from the secondary port (port 1) back to this slave is broken |
| slave.diagnostics().redundancyActivatedOrNull() | Boolean | Read-only | Same as redundancyActivated(), but returns null when the read fails |
| slave.diagnostics().primaryLinkBrokenOrNull() | Boolean | Read-only | Same as primaryLinkBroken(), but returns null when the read fails |
| slave.diagnostics().secondaryLinkBrokenOrNull() | Boolean | Read-only | Same as secondaryLinkBroken(), but returns null when the read fails |
The boolean versions fold a failed read into false, which cannot be told apart from "the value really is no break / not activated"; when you need to tell a failure apart, use the *OrNull() versions (null = could not be read, not a conclusion).
Example:
for (Slave slave : master.slaves()) {
if (!slave.redundancyActivated()) continue;
System.out.print("从站 " + slave.SlaveNum + ": 冗余激活"); // Slave {slave.SlaveNum}: redundancy active
if (slave.primaryLinkBroken()) System.out.print(", 主线路断路"); // , primary link broken
if (slave.secondaryLinkBroken()) System.out.print(", 冗余线路断路"); // , redundancy link broken
System.out.println();
}
DC synchronization
Access the DC synchronization state of a slave through slave.DC().getSyncWindowStatus(). A failed read returns null, which is treated as "conclusion unavailable" and never folded into "synchronized".
Related read-only entry points:
| Method | Returns | Description |
|---|---|---|
| slave.DC().sync0Armed() | Boolean (tri-state) | Whether SYNC0 is armed; null = cannot answer, must not be folded into false |
| slave.diagnostics().syncTimeDifferenceOrNull() | Integer | Current time difference (nanoseconds); no DC / read failed / SYNC0 not armed ⇒ null, and 0 is not used to pretend "perfect synchronization" (a real 0 = a deviation of 0ns was actually measured) |
| slave.diagnostics().getDCDiagnostics() | SlaveDCDiagnostics | Aggregated DC diagnostics; returns null when DC is not supported, the read fails, or the arming conclusion is unknown |
SyncWindowStatus struct:
| Field | Type | R/W | Description |
|---|---|---|---|
| DiffNs | int | Read-only | Current time difference (nanoseconds) |
| MaxDiffNs | int | Read-only | Maximum time difference (nanoseconds) |
| MinDiffNs | int | Read-only | Minimum time difference (nanoseconds) |
| InSync | boolean | Read-only | Whether the slave is inside the sync window; always false when SYNC0 is not armed, and must not be read as synchronized |
| OutOfSyncCount | long | Read-only | Number of times the slave left the sync window (the uint32 is widened to long as an unsigned value) |
SlaveDCDiagnostics struct:
| Field | Type | R/W | Description |
|---|---|---|---|
| IsInSync | boolean | Read-only | Whether the slave can be treated as synchronized: true when this slave is the reference clock and SYNC0 is armed (the reference clock cannot be out of step with itself). That true does not mean a measured deviation exists, nor that the whole network clock has converged |
| SyncTimeDifference | Integer | Read-only | Current time difference (nanoseconds); null when unavailable, and 0 is not used to pretend "perfect synchronization" |
Example:
for (Slave slave : master.slaves()) {
if (!slave.hasDC()) continue;
DC.SyncWindowStatus status = slave.DC().getSyncWindowStatus();
if (status != null) {
System.out.printf("从站 %d: 时间差=%dns, 同步=%b%n", // Slave %d: time diff=%dns, in sync=%b%n
slave.SlaveNum, status.DiffNs, status.InSync);
}
}
Full example
for (Slave slave : master.slaves()) {
System.out.println("--- 从站 " + slave.SlaveNum + ": " + slave.name() + " ---"); // --- Slave {slave.SlaveNum}: {slave.name()} ---
// port errors
EscPortErrors errors = slave.diagnostics().readPortErrors();
if (errors != null && errors.hasErrors()) {
System.out.printf(" 端口错误: RX=%s, 无效帧=%s, 链路丢失=%s%n", // Port errors: RX=%s, invalid frames=%s, link loss=%s%n
Arrays.toString(errors.RxError),
Arrays.toString(errors.InvalidFrame),
Arrays.toString(errors.LostLink));
}
// redundancy (meaningful only in redundancy mode)
if (slave.redundancyActivated()) {
System.out.printf(" 冗余激活: 主线路断=%b, 冗余线路断=%b%n", // Redundancy active: primary link broken=%b, redundancy link broken=%b%n
slave.primaryLinkBroken(), slave.secondaryLinkBroken());
}
// DC synchronization
if (slave.hasDC()) {
DC.SyncWindowStatus status = slave.DC().getSyncWindowStatus();
if (status != null) {
System.out.printf(" DC: 时间差=%dns, 同步=%b%n", // DC: time diff=%dns, in sync=%b%n
status.DiffNs, status.InSync);
}
}
}