Skip to main content

Slave diagnostics

Each slave provides its own diagnostic properties and sub-objects for port errors, redundancy, Distributed Clocks (DC) synchronization and other information.

Use with events

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​

CategoryFeatureR/WAccess pathDescription
State mirrorState mirrorRead-onlyslave.wcContributed() / mailboxHealth() and so onPer-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 diagnosticsCommunication diagnosticsRead-onlyslave.diagnostics().readPortErrors()ESC port error counters
Redundancy diagnosticsRedundancy diagnosticsRead-onlyslave.redundancyActivated() and so onRedundancy activation, primary / redundant line break detection
Per-slave diagnosticsPer-slave reachable leg / liveness reason / clean OP / SYNC0 armedRead-onlymaster.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 synchronizationDC synchronizationRead-onlyslave.DC().getSyncWindowStatus()Sync state, time difference

Properties​

CategoryMethodTypeR/WDescription
Communication diagnosticsreadPortErrors()EscPortErrorsRead-onlyRead the ESC port error counters (slave.diagnostics())
resetPortErrors()booleanWrite-onlyReset the port error counters (slave.diagnostics())
linkQuality()shortRead-onlyLink quality (0-100%, -1 = unknown, 0 is not used to pretend 0%) (slave.diagnostics())
Redundancy diagnosticsredundancyActivated()booleanRead-onlyRedundancy 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()booleanRead-onlyPrimary 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()booleanRead-onlyRedundant 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 synchronizationDC().getSyncWindowStatus()SyncWindowStatusRead-onlySync window state (time difference, whether in sync, and so on)
Per-slave true WKC probegetSlaveWkcProbeActual(short slaveIndex)intRead-onlyPer-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)intRead-onlyExpected WKC: 1 = expected / -1 = not probeable (no read mapping / out of range) or read failed. Unreadable = unknown, never invented
getSlaveWkcProbeSampleAgeMs(short slaveIndex)intRead-onlySample age: >=0 = milliseconds since the most recent sample / -1 = never sampled or read failed
getPerSlaveWkcProbeMode()intRead-onlyProbe 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)booleanWrite-onlySet 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:

FieldTypeR/WDescription
RxErrorbyte[4]Read-onlyRX error count per port [ports 0-3]
InvalidFramebyte[4]Read-onlyInvalid frame count per port [ports 0-3]
LostLinkbyte[4]Read-onlyLink loss count per port [ports 0-3]
FwdRxErrorbyte[4]Read-onlyForwarded 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
FwdRxErrorReadOKbooleanRead-onlyfalse = 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()booleanRead-onlyWhether any error is present (FwdRxError does not take part in the decision when it could not be read)
note

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.

CategoryMethodTypeR/WDescription
WKC contributionwcContributed()EcWcContributedRead-onlyWhether this slave contributed its expected WKC this cycle (a per-slave status bit)
AL state mirroralStatusMirror()EcAlStatusMirrorRead-onlyMirror 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 healthmailboxHealth()EcMailboxHealthRead-onlyMailbox 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 healthisFreeRunDemoted()booleanRead-onlyWhether 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 healthhealthDegradedCount()longRead-onlyConsecutive 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 healthrecoverMailboxHealth()booleanWrite-onlyManually 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 flagisLost()booleanRead-onlyWhether 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 (not UNKNOWN). 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, otherwise NO_ERROR); when the mirror is not sampled (raw == 0) check isKnown() first and do not treat the high byte's NO_ERROR as "no error"
  • isKnown() (boolean) — whether the data is trustworthy (raw == 0 means 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 (not UNKNOWN). 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
}
}
}
Honest sentinel

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; returns null when 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, and 0 is 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().

CategoryMethodTypeR/WDescription
Topology informationcount()intRead-onlyNumber 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()byteRead-onlyEntry port
parentPort()intRead-onlyParent port number: 0..3, -1 = unknown or invalid parameter
parentStation()shortRead-onlyParent station address (note: this is actually the 1-based slave index, not a station address; 0 means the parent is the master)
physicalType()byteRead-onlyPhysical type
linkCount()intRead-onlyNumber 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()intRead-onlyTopology 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()intRead-onlyCompatibility alias of linkCount() (returns the measured link count, not the topology structure class; the name is historical)
activePorts()byteRead-onlyActive ports
consumedPorts()byteRead-onlyNumber 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:

ConclusionPublic interfaceReturnsR/WDescription
Loss reasonmaster.events().tryGetSlaveOfflineReason(int)SlaveOfflineReasonRead-onlyReads the cache / an existing conclusion only, no frame is sent; the categories are in events
Clean OP / real OPmaster.diagnostics().evaluateSlaveRealOp(int)SlaveRealOpStateRead-onlyPer-slave real-OP verdict; SlaveRealOpState.alCleanOp is the clean OP
SYNC0 armedslave.DC().sync0Armed()Boolean (tri-state)Read-onlynull = 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.

Unknown is not a negative answer

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

MethodTypeR/WDescription
slave.redundancyActivated()booleanRead-onlyWhether this slave is communicating over a working redundant path
slave.primaryLinkBroken()booleanRead-onlyWhether the path from the primary port (port 0) to this slave is broken
slave.secondaryLinkBroken()booleanRead-onlyWhether the path from the secondary port (port 1) back to this slave is broken
slave.diagnostics().redundancyActivatedOrNull()BooleanRead-onlySame as redundancyActivated(), but returns null when the read fails
slave.diagnostics().primaryLinkBrokenOrNull()BooleanRead-onlySame as primaryLinkBroken(), but returns null when the read fails
slave.diagnostics().secondaryLinkBrokenOrNull()BooleanRead-onlySame 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:

MethodReturnsDescription
slave.DC().sync0Armed()Boolean (tri-state)Whether SYNC0 is armed; null = cannot answer, must not be folded into false
slave.diagnostics().syncTimeDifferenceOrNull()IntegerCurrent 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()SlaveDCDiagnosticsAggregated DC diagnostics; returns null when DC is not supported, the read fails, or the arming conclusion is unknown

SyncWindowStatus struct:

FieldTypeR/WDescription
DiffNsintRead-onlyCurrent time difference (nanoseconds)
MaxDiffNsintRead-onlyMaximum time difference (nanoseconds)
MinDiffNsintRead-onlyMinimum time difference (nanoseconds)
InSyncbooleanRead-onlyWhether the slave is inside the sync window; always false when SYNC0 is not armed, and must not be read as synchronized
OutOfSyncCountlongRead-onlyNumber of times the slave left the sync window (the uint32 is widened to long as an unsigned value)

SlaveDCDiagnostics struct:

FieldTypeR/WDescription
IsInSyncbooleanRead-onlyWhether 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
SyncTimeDifferenceIntegerRead-onlyCurrent 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);
}
}
}