Slave properties and methods
Access via master.getSlave(n) (1-based index), or get the list with master.slaves(). The DENI one-step initialization path does not populate that list (getSlave throws IndexOutOfBoundsException and slaves() is empty); instead construct new Slave(master.MasterIndex, (short) 1, master) directly from the master index + station number. See ENI/DENI configuration loading.
Properties
| Category | Property | Type | Read/write | Description |
|---|---|---|---|---|
| Basic identity | SlaveNum | short (public final) | read-only | Slave index (1-based, immutable value) |
| MasterIndex | short (public final) | read-only | Owning master number (immutable value) | |
| name() | String | read-only | Device name (read from the EEPROM) | |
| driveName() | String | read-only | Drive name (read from SDO 0x1008) | |
| Device information | vendorId() | int | read-only | Vendor ID (read from the SII EEPROM) |
| vendorName() | String | read-only | Vendor name (read from the ESI file) | |
| productId() | int | read-only | Product ID | |
| revId() / revision() | int | read-only | Revision number (revision() is a synonymous alias) | |
| serialNumber() | int | read-only | Serial number (native runtime identity snapshot); 0 has three meanings — 「not read / real value 0 / read failed」; use tryGetSerialNumber(int[]) for the real value | |
| hasMDP() | boolean | read-only | Whether a modular device profile is supported (ETG.5001) | |
| blockLRW() | boolean | read-only | Logical read/write operation block flag | |
| Address | configAddr() | short | read-only | Physical configuration address |
| aliasAddress() | short | read-only | Alias address | |
| index() | int | read-only | Slave index (alias of SlaveNum) | |
| Status | state() | EcState | read-only | Current EtherCAT state of the slave (from the lower-layer cache, refreshed by the PDO thread while in OP). Only the low 4 basic-state bits are returned; bit4 = the Error bit is discarded: 0x18 also reports OP; to judge a fault use hasError() / stateRaw() / status() |
stateRaw() | int | read-only | Raw wire AL Status byte (& 0xFF, Error bit fully preserved); returns 0 when it cannot be read | |
hasError() | boolean | read-only | (stateRaw() & 0x10) != 0 | |
status() | EcState.Status | read-only | Named composite state: 0x14 → SAFE_OP_FAULT, 0x18 → OP_FAULT; out-of-table values keep the raw value (isUnknown()), not folded into NONE | |
| stateLive() | EcState | read-only | Current state (forces one live frame read, bypassing the cache; for OP-loss detection/debugging, degrades to NONE on read failure) | |
| stateRawLive() | int | read-only | Raw AL Status byte (forced real-time read, bypassing the cache); returns 0 on read failure | |
| stateLiveRead() | LiveRead | read-only | Live state read (forces one real read) plus four-state trust; value is the raw AL Status byte (low 4 bits = base state, bit4 = Error), usable as the current state only when isValid(). Use state() / stateRaw() for the cached view | |
| hasErrorLive() | boolean | read-only | Error bit judgement (forced real-time read, bypassing the cache) | |
| errorCode() | EcALState | read-only | AL Status Code error code (real read: the full 16-bit ALstatuscode in the slave structure; reads the polled cache while in OP and refreshes with one live frame otherwise; not the high byte of alStatusMirror(). Use errorCodeLive() to force an on-the-spot re-read) The enum view lists only codes in the ETG.1020 table; out-of-table codes fall to UNKNOWN (0xFFFF), the same value as "not read"; for the lossless raw value use errorCodeRaw() | |
| errorCodeRaw() | int | read-only | AL Status Code lossless 16-bit raw value: 0xFFFF = not read, 0 = device confirmed no error, others = real device code (including out-of-table codes) | |
| errorCodeLive() | EcALState | read-only | AL Status Code (forced live read, bypassing the cache). Out-of-table codes fall to UNKNOWN as in errorCode(); an untrusted read also falls to UNKNOWN (four states in alStatusCodeLiveRead()) | |
| errorCodeRawLive() | int | read-only | AL Status Code lossless 16-bit raw value (forced real-time read, bypassing the cache); returns 0xFFFF on read failure. A lost slave / no response and other untrusted cases also give 0xFFFF (four states in alStatusCodeLiveRead()) | |
| alStatusCodeLiveRead() | LiveRead | read-only | Live AL Status Code (lossless 16-bit) plus four-state trust. When the slave is lost / not responding native returns 0; this entry point files it as STALE and never reports it as NO_ERROR | |
| errorCodeLiveOutcome() | ReadOutcome | read-only | Three-state verdict for the live AL code: NORMAL = read and no error / ABNORMAL = read and error / UNKNOWN = untrusted (slave lost / read failure / insufficient evidence). Only a VALID read produces either of the first two | |
| isLost() | boolean | read-only | Whether the slave is lost (disconnected) | |
| liveness() | SlaveLivenessState | read-only | Liveness three-state: Alive = confirmed alive / Lost = confirmed offline / Unknown = insufficient evidence. isLost() only answers "is it confirmed lost"; use this method to tell "insufficient evidence" | |
| offlineReason() | SlaveOfflineReason | read-only | Offline reason classification: RealOffline = truly offline / Unreachable = not confirmed by the server — the server/probe did not see it, but the process data proves it is still contributing (not a confirmed offline) / Unknown = insufficient evidence | |
| hasEnteredOperational() | boolean | read-only | Whether it has ever successfully entered OP during this run (event-latched; falls back to the current-cycle state when the event surface is not ready) | |
| droppedFromOperational() | boolean | read-only | Whether it "entered OP but is not in OP now" (dropped out of OP at runtime) | |
| outOfOpDurationMs() | Long | read-only | Monotonic duration the slave has continuously been out of OP (ms); null = no provable start of the out-of-OP period. System clock changes do not affect this value | |
| outOfOpDuration() | java.time.Duration | read-only | How long it has continuously been out of OP; null has the same meaning as above | |
| outOfOpSinceUtc() | java.time.Instant | read-only | Start of the out-of-OP period (UTC, derived from "current UTC - monotonic duration"); null has the same meaning as above | |
| wcContributed() | EcWcContributed | read-only | This cycle's contribution state to the working counter (WKC) (zero-frame real-time mirror) | |
| inputDataValidity() | PdoInputValidity | read-only | Four-state validity of the input process data: VALID = this cycle's data is valid; DEGRADED = this cycle has no full evidence (the group's inputs are incomplete for this cycle; on a single dropped frame / WKC=0 the data is the previous valid frame (last-good); when some slaves are missing, the input bytes of the absent slave and everything downstream may be the process-image initial values established at startup, do not treat it as definitely trustworthy); STALE = cannot be used as the current value; UNKNOWN = no evidence. Use this property to decide "can this frame of data be used"; use isLost() to decide "has the slave been confirmed offline" | |
| alStatusMirror() | EcAlStatusMirror | read-only | AL status mirror (includes AL State + Error + Code; a cache sampled while the master is in OP, not the live truth at read time) | |
| Topology | linkCount() | int | read-only | Link count: 1..4 = measured connection count for the current sample (popcount of the low 4 bits of activePorts()), -1 = unknown or invalid parameter (a 0 placeholder when DLSTAT was not read also counts as unknown); refreshed periodically, unknown does not mean the link is down; this is not the configuration-time structure classification |
| topologyType() | int | read-only | Configuration-time structure classification snapshot: 0 = NoLink / 1 = EndPoint / 2 = Line / 3 = Fork / 4 = Cross; -1 = unavailable (lower-layer 0xFF / out-of-range value, unsupported by older versions, invalid parameter); determined once at configuration time, unchanged by unplugging a cable; not a measurement for the current sample. slave.topology().topologyType() returns the same value | |
| parentStation() | int | read-only | Station address of the parent slave (note: this is actually a 1-based slave index, not a station address; 0 means the parent node is the master) | |
| parentPort() | int | read-only | Parent port number: 0..3, -1 = unknown or invalid parameter; unknown does not mean P0 | |
| entryPort() | byte | read-only | Entry port number | |
| activePorts() | byte | read-only | Active port bitmask | |
| physicalType() | byte | read-only | Physical port type | |
| PDO data | ibits() / obits() | short | read-only | Input/output data bit count |
| ibytes() / obytes() | int | read-only | Input/output data byte count | |
| ioffset() / ooffset() | int | read-only | Input/output offset within the process data | |
| istartbit() / ostartbit() | byte | read-only | Input/output start bit | |
| ESI/configuration | hasEsi() | boolean | read-only | Whether an ESI file has been loaded |
| esiVersion() | String | read-only | ESI version | |
| EEPROM | eep8ByteAddressing() | boolean | read-only | EEPROM addressing mode (true = 8-byte, false = 4-byte) |
| eepPDI() | byte | read-only | Physical device interface (PDI) type | |
| ebusCurrent() | short | read-only | E-bus current consumption (mA) | |
| Mailbox | mbxProto() | EnumSet<EtherCATTypes.MailboxProtocol> | read-only | Supported mailbox protocol capability bitmap (SII mbx_proto: bit0=AoE, bit1=EoE, bit2=CoE, bit3=FoE, bit4=SoE, bit5=VoE); returns null on read failure |
| mbxLength() | short | read-only | Mailbox send buffer size | |
| mbxReadLength() | short | read-only | Mailbox receive buffer size | |
| mbxReadOffset() / mbxWriteOffset() | short | read-only | Mailbox read/write offset | |
| mbxCount() | byte | read-only | Mailbox protocol counter | |
| Protocol details | coeDetails() | byte | read-only | CoE protocol feature flags (SDO/PDO Assign/Complete Access, etc.) |
| eoeDetails() | byte | read-only | EoE protocol feature flags (send frame/receive frame/IP parameters, etc.) | |
| foeDetails() | byte | read-only | FoE protocol details (from the SII EEPROM) | |
| soeDetails() | byte | read-only | SoE protocol details (from the SII EEPROM) | |
| FMMU | fMMU0Function() | byte | read-only | FMMU0 function type (bit 0 = output, bit 1 = input) |
| fMMU1Function() | byte | read-only | FMMU1 function type | |
| fMMU2Function() | byte | read-only | FMMU2 function type | |
| fMMU3Function() | byte | read-only | FMMU3 function type | |
| DC | hasDC() | boolean | read-only | Whether DC is supported |
| dcActive() | int | read-only | Landed value of 0x0980 (0 = not active). A value other than 0 only means the register has been written, not that it is armed or synchronized; for armed state check slave.DC().sync0Armed(), for synchronization check dcSyncWindow().inSync | |
| dcCycle0() / dcCycle1() | int | read-only | SYNC0/SYNC1 cycle (ns) | |
| dcShift() | int | read-only | Phase shift (ns) | |
| pDelay() | int | read-only | Propagation delay of a frame from the master to this slave (ns) | |
| dcNext() | int | read-only | Index of the next slave in the DC chain | |
| dcPrevious() | int | read-only | Index of the previous slave in the DC chain | |
| dcParentPort() | int | read-only | Compatibility entry for parentPort(); same 0..3 / -1, not another DC-specific field | |
| dcReceiveTimeA/B/C/D() | int | read-only | Receive time of port A/B/C/D (ns) | |
| Topology extension | supportsFrameRepeat() / supportsFrameRepeat(boolean) | boolean | read/write | Whether the frame repeat function is supported (ETG.1500 5.4.3) |
| Redundancy | redundancyActivated() | boolean | read-only | Redundancy protection active = same master-level criterion redundancyRingMode() >= 1 (Dual / Degraded); always false for linear / end-return topologies, not a per-slave independent conclusion |
| primaryLinkBroken() | boolean | read-only | Primary link broken | |
| secondaryLinkBroken() | boolean | read-only | Redundant link broken | |
| Configuration | group() / group(byte) | byte | read/write | Slave group number (0-7; 0 = unassigned marker, automatically placed in group 1 before mapping, valid PDO groups are 1-7; must be set before SAFE_OP) |
| isOptional() / isOptional(boolean) | boolean | read/write | Optional slave marker; when absent it does not affect the WKC check and does not trigger a group offline alarm (must be set before OP) |
group(byte)— a group number outside0-7(byteis signed, so negative values are equally invalid) throwsIllegalArgumentException; the runtime refusing the write (when no longer before SAFE_OP) throwsIllegalStateExceptionisOptional(boolean)/supportsFrameRepeat(boolean)— the runtime refusing the write throwsIllegalStateExceptionand does not returnfalsepretending success
mbxProto() returns the SII mbx_proto capability bitmap (EtherCATTypes.MailboxProtocol bit set: AoE=0x01, EoE=0x02, CoE=0x04, FoE=0x08, SoE=0x10, VoE=0x20), not the mailbox frame header type code MailboxType (the old short type code semantics are deprecated; use mbxProtoRaw() if you want the raw bitmap); on read failure it returns null, not an empty set. Judge capabilities with supportsCoE() / supportsFoE() / supportsEoE() / supportsSoE() / supportsAoE() / supportsVoE(), or hasProtocol(EtherCATTypes.MailboxProtocol.COE).
supportsCoE() / supportsFoE() / supportsEoE() / supportsSoE() / supportsAoE() / supportsVoE() are now uniformly boolean views of each protocol object's isSupported(): true only when support is confirmed; when mbx_proto cannot be read they return false (fail-closed) and no longer treat "unknown" as "supported". The return type is the primitive boolean (supportsFoE() included), and comparing it with null fails to compile. To distinguish "unknown" from "confirmed unsupported", use the tri-state methods coeSupportState() / foeSupportState() / eoeSupportState() / soeSupportState() / aoeSupportState() / voeSupportState() (returning Boolean, null = unknown), or the protocol object's supportState() / isSupportKnown().
EcState.Status value object (Error bit)
The low 4 bits of AL Status are the state, and bit4 (0x10) is the Error bit. state() / stateLive() only give the low 4 bits (EcState is a closed enum that cannot hold 0x14 / 0x18, and keeping the return value unchanged is a compatibility convention); for Error information go through stateRaw() / hasError() / status().
status() returns EcState.Status: an immutable value object, not an enum (same pattern as NetworkInfo.NicScanStatus). The named constants are NONE / INIT / PRE_OP / BOOT / SAFE_OP / OP / ERROR_FLAG / INIT_FAULT / PRE_OP_FAULT / BOOT_FAULT / SAFE_OP_FAULT / OP_FAULT; out-of-table composite values (such as 0x1A) keep the raw value — getValue() is the wire raw code, isUnknown() is true, pretty() prints "0x1A", and it is not folded into NONE.
public static final class EcState.Status {
public static final EcState.Status NONE, INIT, PRE_OP, BOOT, SAFE_OP, OP,
ERROR_FLAG, INIT_FAULT, PRE_OP_FAULT, BOOT_FAULT, SAFE_OP_FAULT, OP_FAULT;
public static EcState.Status fromRaw(int raw); // raw & 0x1F looks up the named value; on miss -> new Status(raw & 0xFF)
public int getValue(); // wire raw code (values outside the table = raw & 0xFF)
public boolean isUnknown(); // Composite value outside the table = true
public EcState baseState(); // Base state in the low 4 bits
public boolean hasFault(); // bit4 = Error
public boolean isRunning(); // SAFE_OP / OP and no Error
public boolean isOp(); // OP and no Error
public String pretty(); // "OP_FAULT (OP+Error)" / "0x1A"
public boolean equals(Object o); // Compare by value (do not use ==)
}
Compare with .equals(...): named constants may use ==, but every fromRaw() on an out-of-table value returns a new instance.
EcWcContributed enum
wcContributed() returns this enum, reflecting whether the slave contributes to the working counter (WKC) in the current cycle.
public enum EcWcContributed {
CONTRIBUTED, // This slave contributes WKC normally this cycle (online response), getValue() = 1
NOT_CONTRIBUTED, // This slave did not contribute this cycle (suspected slave loss / hot-plug in progress), getValue() = 0
UNKNOWN; // Contract not ready (0xFF) — reported honestly, never fabricated as 1/0
public int getValue();
public static EcWcContributed fromByte(int v);
public boolean isKnown(); // Whether the data is trustworthy (not UNKNOWN)
}
EcAlStatusMirror parsed object
alStatusMirror() returns this object (a cache mirror sampled while the master is in OP, not the live truth at read time), containing AL State + Error bit + AL Status Code. When raw == 0, isKnown() is false (no sample has been taken yet / the master is not currently in OP).
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.
public static final class EcAlStatusMirror {
public static EcAlStatusMirror fromRaw(int rawUnsigned);
public int getRaw(); // Raw 16-bit mirror value (unsigned 0..65535)
public EcState getAlState(); // AL State (low byte; drop the Error bit and take the low 4 bits)
public boolean hasError(); // Error bit (bit4)
public EtherCATTypes.EcALState getAlStatusCode(); // low 8 bits of the mirror high byte; valid only with the Error bit, codes >=0x0100 truncated; NO_ERROR when the Error bit is clear
public boolean isKnown(); // true when raw != 0
}
EcTopologyType enum
public enum EcTopologyType {
NO_LINK(0), // No link
END_POINT(1), // End point
LINE(2), // Intermediate node (linear topology)
FORK(3), // Fork point
CROSS(4); // Cross point
}
MailboxType enum
public enum MailboxType {
ERROR_MAILBOX(0x00), // Error mailbox
ADS_OVER_ETHERCAT(0x01), // AoE
ETHERNET_OVER_ETHERCAT(0x02), // EoE
CANOPEN_OVER_ETHERCAT(0x03), // CoE
FILE_OVER_ETHERCAT(0x04), // FoE
SERVO_OVER_ETHERCAT(0x05), // SoE
VENDOR_OVER_ETHERCAT(0x0F); // VoE
}
Sub-object access
| Category | Method | Type | Read/write | Description |
|---|---|---|---|---|
| Sub-object access | coe() | CoE | read-only | CANopen over EtherCAT |
| soe() | SoE | read-only | Servo over EtherCAT | |
| foe() | FoE | read-only | File over EtherCAT | |
| eoe() | EoE | read-only | Ethernet over EtherCAT | |
| aoe() | AoE | read-only | ADS over EtherCAT | |
| voe() | VoE | read-only | Vendor over EtherCAT | |
| fsoe() | FSoE | read-only | Functional safety | |
| cia402() | CiA402 | read-only | CiA 402 drive | |
| cia401() | CiA401 | read-only | CiA 401 I/O module | |
| sii() | Sii | read-only | SII Category tri-state reads (see EEPROM (SII) access) | |
| DC() | DC | read-only | DC synchronization configuration | |
| PDO() | PDO | read-only | PDO data access | |
| slavePdo() | SlavePdo | read-only | Whole-frame read/write entry. Inputs/Outputs are generation snapshots (the recommended path is inputsMapping / outputsMapping on PDO() for direct mapping) | |
| diagnostics() | SlaveStats | read-only | Slave diagnostics statistics | |
| topology() | SlaveTopology | read-only | Slave topology information. The master-level master.slaveTopology().count() is the number of root nodes (ParentStation==0 or MII) | |
| MDP() | MDP | read-only | Modular device | |
| startupParameters() | StartupParameterList | read-only | Startup parameter list |
All sub-objects use lazy creation and are instantiated automatically on first access.
In Java you can use Optional<Slave> to chain sub-object/topology access (MasterStreams.slaveOpt(master, idx).map(Slave::topology)...); on out-of-range / already disposed / not built it safely returns empty instead of throwing IndexOutOfBoundsException.
FMMU properties
| Category | Property | Type | Read/write | Description |
|---|---|---|---|---|
| FMMU | fMMU0Function() | byte | read-only | FMMU0 function type |
| fMMU1Function() | byte | read-only | FMMU1 function type | |
| fMMU2Function() | byte | read-only | FMMU2 function type | |
| fMMU3Function() | byte | read-only | FMMU3 function type |
Use fMMU0Function() ~ fMMU3Function() to obtain each FMMU function type separately.
Watchdog query
| Category | Method | Type | Read/write | Description |
|---|---|---|---|---|
| Watchdog query | getWatchdogConfig() | int[] | read-only | Watchdog configuration [divider, PDI timeout, PD timeout]; null = cannot read (≠ a configuration value of 0) |
| watchdogConfigKnown() | boolean | read-only | Whether the configuration reading is known (getWatchdogConfig() != null) | |
| getWatchdogStatus() | int[] | read-only | Watchdog status [status, 0x0442 counter, divider, PD timeout, 0x0443 PDI counter, valid_mask]; returns null when the whole read fails | |
| watchdogStatusKnown() | boolean | read-only | Whether the 0x0440 status reading is trustworthy (valid_mask bit0 set) | |
| Constants | WATCHDOG_STATUS_UNKNOWN | int | read-only | Status byte "read failed / unknown" sentinel 0xFF (kept only for legacy callers) |
| WATCHDOG_MAX_MS | int | read-only | Upper limit of the watchdog counter register (6553 ms), the parameter limit for setWatchdog / setPdiWatchdog |
getWatchdogStatus() returns 6 elements. Whether each field is trustworthy is given by valid_mask (bit definitions: bit0 = 0x0440 status, bit1 = 0x0442 counter, bit2 = 0x0400 divider, bit3 = 0x0420 PD timeout, bit4 = 0x0443 PDI counter). A valid_mask bit of 0 means that register failed to read this time and the corresponding field is fixed at 0, which does not represent the device's real value. The ETG semantics of 0x0440 bit0: 0 = overflowed/expired, 1 = normal or not enabled; individual devices (such as the EK1100) also report 0 when healthy, so do not judge a fault from this bit alone. When the whole read fails it returns null; to tell 「read 0」 from 「not read」, use watchdogStatusKnown() rather than guessing from the status byte. WATCHDOG_STATUS_UNKNOWN (0xFF) is kept only for legacy callers.
getWatchdogConfig() returning null means it cannot be read (invalid slave index / master not built / lower-layer call failed / the slave does not respond), strictly distinct from reading the configuration value {0,0,0}; use watchdogConfigKnown() to judge whether the reading is known. 0x0442 / 0x0443 are watchdog overflow counters (write 0 to reset, reads do not clear them) and are not the same thing as the 0x0440 status bit.
The 6 elements returned by getWatchdogStatus() (int[], fixed order):
| Index | Field | Description |
|---|---|---|
| 0 | Raw status byte (0x0440) | 0xFF = this read failed; see above for bit0 semantics |
| 1 | 0x0442 overflow counter | Write 0 to reset, reads do not clear it |
| 2 | 0x0400 divider | |
| 3 | 0x0420 process data watchdog value | |
| 4 | 0x0443 PDI overflow counter | Write 0 to reset, reads do not clear it |
| 5 | valid_mask | Per-field valid bits: bit0 = 0x0440 status, bit1 = 0x0442 counter, bit2 = 0x0400 divider, bit3 = 0x0420 PD timeout, bit4 = 0x0443 PDI counter; a mask bit of 0 means that register failed to read this time and the corresponding field is fixed at 0, which does not represent the device's real value |
When the whole read fails it returns null; to tell 「read 0」 from 「not read」, use watchdogStatusKnown().
Operation methods
setState(EcState targetState, int timeoutMs)
public boolean setState(EcState targetState, int timeoutMs)
public boolean setState(EcState targetState)
Set the EtherCAT state of a single slave, blocking until the transition completes or times out. The overload without timeoutMs uses a default of 3000 ms.
Parameters:
targetState(EcState) — target state (INIT / PRE_OP / SAFE_OP / OP)timeoutMs(int) — timeout (ms)
Returns:
boolean— true on success, false on failure or timeout
Throws:
IllegalArgumentException—timeoutMsis negative (the runtime parameter is unsigned 32-bit, so a negative value wraps into a huge timeout; this method rejects it explicitly instead of silently clamping)
Example:
Slave slave = master.getSlave(1);
if (!slave.setState(EcState.PRE_OP)) {
System.out.println("从站 1 切换 PRE_OP 失败"); // Failed to switch slave 1 to PRE_OP
}
slave.setState(EcState.OP, 5000);
setWatchdog(int timeoutMs)
public boolean setWatchdog(int timeoutMs)
Set the process data watchdog timeout (ms), 0 = disabled.
Parameter range: 0 .. 6553 (WATCHDOG_MAX_MS, upper limit of the watchdog counter register).
Returns: boolean — answers only "does the actual written value == the requested value": returns true when they are equal and the register write succeeded; for the other forms see below.
Failure forms (three states reported honestly, not the same thing):
timeoutMsbelow 0 or above6553→ throwsIllegalArgumentException(the runtime rejects it too; this check stops it first, with no silent clamping and no wrap-around);- The request exceeds the 6553 ms register limit (0x0420 = u16 × 0.1 ms; lower-layer last-error
87=ERROR_INVALID_PARAMETER) → throwsIllegalArgumentException: rejected, not a single byte written, no truncation, no sneaky rewrite to 6553; - The requested value is raised by the topology safety floor and written (lower-layer last-error
0x20000011; actual value ≠ requested value; the floor is 5000 ms for branch slaves and 400 ms for PDO slaves on a ring) → throwsIllegalStateException, with the read-back actual value in the exception message (marked unknown if it cannot be read); - Other failures (register write failure / invalid index, last-error
0) → returnsfalse.
false ≠ "not set"The 0x20000011 case is written but raised by the safety floor, not a failure; do not skip subsequent handling as if it failed. To get the actual milliseconds read getWatchdogConfig(): actual PD watchdog ms = item 3 ÷ 10 (raw unit 0.1 ms), PDI likewise item 2 ÷ 10.
setPdiWatchdog(int timeoutMs)
public boolean setPdiWatchdog(int timeoutMs)
Set the PDI watchdog timeout (ms), 0 = disabled. The PDI channel has no topology safety floor rise (no 0x20000011, and no third form above); the rest of the contract is the same as setWatchdog.
Parameter range: 0 .. 6553 (WATCHDOG_MAX_MS); below 0 or above 6553 throws IllegalArgumentException.
Returns: boolean — true when the actual written value == the requested value and the register write succeeded; the runtime rejecting an out-of-range value (last-error 87) throws IllegalArgumentException (not a single byte written), while a register write failure / invalid index returns false.
configureDC(int sync0CycleNs, int sync1CycleNs, int shiftNs)
public void configureDC(int sync0CycleNs, int sync1CycleNs, int shiftNs)
public void disableDC()
Configure/disable DC synchronization (per slave, independent of other slaves). Passing 0 for the SYNC0 cycle = disarm SYNC0 (back to FreeRun); 0 for the SYNC1 cycle = disabled.
Parameters:
sync0CycleNs(int) — SYNC0 cycle (ns),0= not armedsync1CycleNs(int) — SYNC1 cycle (ns),0= disabledshiftNs(int) — phase shift (ns):DC.DC_SHIFT_UNSPECIFIED= unspecified (left to the device description to resolve),0= literal 0 phase, negative values are legal and sent as-is
Throws:
IllegalArgumentException— the SYNC0 / SYNC1 cycle is negative (the runtime parameter is unsigned 32-bit, so a negative value wraps into a huge cycle; negative phase values are not in this category)
Diagnostics mirror
wcContributed() reads the current state directly on every call, sends and receives no frames, and returns the bus reality at that instant — no manual refresh needed. alStatusMirror() is not in that category.
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. When an older runtime does not support them, they degrade to UNKNOWN / raw=0, reported honestly and never fabricated.
PdoInputValidity — input data validity
inputDataValidity() answers "can this frame of input data be used as the current value", which is a different fact from "has the slave been confirmed offline" (isLost()).
| Value | What you see | Recommended use |
|---|---|---|
VALID | This cycle's PDO exchange was complete; the input image is the current value | Use normally |
DEGRADED | This cycle has no full evidence: the group's inputs are incomplete for this cycle. On a single dropped frame / WKC=0 the data is the previous valid frame (last-good); when some slaves are missing, the input bytes of the absent slave and everything downstream may be the process-image initial values established at startup, not the last valid value | Do not treat this as "the data is definitely trustworthy": either wait for recovery, or cross-check isLost() / offlineReason() / inputDataValidity() to see which slaves are untrustworthy. It turns STALE only after N full cycles without recovery (N is computed from the group cycle and the slave watchdog) |
STALE | The input image cannot be used as the current value (WKC short / no frame this cycle / slave lost / exchange stalled) | Do not use as a live value; take the safe fallback |
UNKNOWN | No evidence (no input PDO / group expectation not established / never exchanged / read failed) | Unknown is not valid; treat it as unavailable |
A read failure / out-of-range index / an older runtime without this capability returns UNKNOWN (fail-closed).
Note: the native-side comment still says "three-state / degradation pending", which is stale text awaiting sync in the native domain; the public SDK contract is the four states in this section.
MasterDiagnosticsInfo.staleInputCount()counts only slaves confirmedSTALE; it does not count whileDEGRADEDapplies.
LiveRead — live-read four states
stateLiveRead() / alStatusCodeLiveRead() both return LiveRead: the raw value plus an evidence level. Only a value that passes isValid() (that is, validity() == VALID) may be used as the current value; the other three states must never be taken as "this is how it is right now".
| Value | Meaning | Usable as the current value |
|---|---|---|
UNKNOWN(0) | No usable read (call failed / old DLL missing the entry point / invalid handle) | No. Unknown != normal |
VALID(1) | This measurement produced a result usable as the current value | Yes |
STALE(2) | A value was obtained, but it is confirmed not current (the lower layer uses 0 as a placeholder when the slave is lost / not responding) | No, this is a residual value |
DEGRADED(3) | A value was obtained, but only partial evidence is available (liveness state / probe unreadable or unknown) | Not as confirmation |
Live state criterion: 0 / 0xFF / low 4 bits are 0 -> UNKNOWN; otherwise -> VALID. value keeps the bit4 Error bit; to test the Error bit use hasErrorLive() or look at the raw byte.
Live AL code criteria:
| Verdict | Trigger | value() |
|---|---|---|
UNKNOWN | The call failed, or it returned 0xFFFF (the unavailable sentinel) | 0xFFFF |
DEGRADED | The liveness state / probe read failed | Raw code |
STALE | isLost() is true, or the probe confirms no response | Raw code (residual) |
DEGRADED | Probe evidence is insufficient (unknown) | Raw code |
VALID | isLost() is false and the probe confirms the slave is online | Raw code |
The lower layer returns 0 for a lost / non-responding slave; that 0 is the "no data" placeholder, not "no error". alStatusCodeLiveRead() uses the liveness state and probe evidence to file it as STALE; the convenience entry points errorCodeLive() / errorCodeRawLive() give UNKNOWN / 0xFFFF, and errorCodeLiveOutcome() gives UNKNOWN. Never read 0 / 0xFFFF / UNKNOWN as "the device confirmed no fault".
The AL mirror (alStatusMirror()) carries only the low 8 bits of the code, and codes >= 0x0100 are truncated; for the full 16-bit code always use errorCodeRaw() or alStatusCodeLiveRead() in this section.
WKC contribution semantics
wcContributed() reflects whether this slave is really responding right now:
CONTRIBUTED— the slave contributes the working counter (WKC) normally, i.e. when the aggregate WKC is complete (actual == expected, that is, the deficitmaster.diagnostics().getWcDeficit() == 0) every per-slave byte comparison is "full".NOT_CONTRIBUTED— the slave is not contributing WKC at this moment (suspected slave loss / hot-plug recovery in progress). This is not a master fault; after the slave recovers the mirror returns toCONTRIBUTEDnaturally.UNKNOWN— contract not ready (the lower layer has no mirror for this slave yet), exposed honestly rather than fabricated as "contributed".
This method only "reports bus reality truthfully" and takes part in no WKC tampering / accommodation logic. The per-slave contribution bits are the per-slave breakdown of the aggregate WKC deficit (expected - actual): a deficit greater than 0 means some slave is not contributing right now and should be alarmed + diagnosed, without lowering expected and without stopping OP.
Example:
for (Slave slave : master.slaves()) {
if (slave.wcContributed() == EcatSlaveDiag.EcWcContributed.NOT_CONTRIBUTED) {
EcatSlaveDiag.EcAlStatusMirror al = slave.alStatusMirror();
System.out.printf("从站 %d 此刻未贡献 WKC(疑似掉站),%s%n", slave.SlaveNum, al); // Slave %d is not contributing WKC right now (suspected slave loss), %s%n
}
}
Register read/write
// Read a register (FPRD)
byte[] data = slave.readRegister(0x0130, 2); // read register
// Write a register (FPWR)
boolean ok = slave.writeRegister(0x0130, new byte[]{0x01, 0x00}); // write register
| Category | Method | Type | Read/write | Description |
|---|---|---|---|---|
| Register read/write | readRegister(int offset, int size) | byte[] | read-only | Read a slave register, returns null on failure |
| writeRegister(int offset, byte[] data) | boolean | write-only | Write a slave register |
Read failures / write failures / call exceptions all write logs (read failure DEBUG, write failure WARNING, exception WARNING); the log carries the slave index and the register offset so the exact station can be located. readRegister returning null means it was not read, strictly distinct from 「read all 0s」.
SyncManager configuration
// Configure SyncManager: SM number, start address, length, control byte, enable
slave.configureSyncManager(2, 0x1100, 128, 0x24, true); // SM2 output
// Enable/disable the output SyncManager
slave.enableOutputSyncManager();
slave.disableOutputSyncManager();
| Category | Method | Type | Read/write | Description |
|---|---|---|---|---|
| SyncManager configuration | configureSyncManager(int smIndex, int startAddr, int length, int control, boolean enable) | boolean | write-only | Configure a SyncManager; smIndex 0-7 / startAddr 0-65535 / length 0-65535 / control 0-255, out of range throws IllegalArgumentException |
| enableOutputSyncManager() | boolean | write-only | Enable the output SyncManager | |
| disableOutputSyncManager() | boolean | write-only | Disable the output SyncManager |
configureFMMU(...) is a package-visible method that SDK users cannot call (user code that calls it does not compile); the slave FMMU is exposed read-only through fMMU0Function() ~ fMMU3Function().
Slave identity verification
// Get the slave identity information
int[] identity = slave.getSlaveIdentity(); // [VendorId, ProductCode, RevisionNo, SerialNo]
// Verify whether the slave identity matches
boolean match = slave.verifySlaveIdentity(0x00000002, 0x03F03052, 0, 0, true, false);
| Category | Method | Type | Read/write | Description |
|---|---|---|---|---|
| Slave identity verification | getSlaveIdentity() | int[] | read-only | Get the identity information [VendorId, ProductCode, RevisionNo, SerialNo], returns null on failure |
| verifySlaveIdentity(int vendorId, int productCode, int revisionNo, int serialNo, boolean checkRev, boolean checkSerial) | boolean | read-only | Verify whether the identity matches | |
| tryGetSerialNumber(int[] outSerial) | boolean | read-only | Read the device's true serial number: a native snapshot other than 0 is returned directly, only a 0 snapshot triggers a live read of SII word 0x000E..0x000F; true = a real value was obtained (may be 0), false = cannot be read (the out-parameter is set to 0 = unknown) |
In Java you can use SlaveIdentity, a record-like immutable identity object, to take a snapshot — safe to pass across threads, usable as a HashMap key, easy to serialize; upgrading to a real record on Java 14+ requires no changes to calling code.
The three meanings of serial number 0 (serialNumber() vs tryGetSerialNumber):
serialNumber() is a native runtime identity snapshot, and 0 can mean any of three things:
| Case | Meaning | Correct way to read it |
|---|---|---|
| Not read | Cold configuration only reads the SER word for slaves that miss the ESI (a performance trade-off); slaves that hit the ESI keep 0 | tryGetSerialNumber(...) |
| Real value 0 | The serial number declared in the device's SII really is 0 | tryGetSerialNumber(...) returns true with an out-parameter of 0 |
| Read failed | The SII cannot be read | tryGetSerialNumber(...) returns false |
tryGetSerialNumber(int[] outSerial) order: (a) the native snapshot is not 0 → return it directly without touching the EEPROM; (b) the snapshot is 0 → read the two SII words live.
true= a real value was obtained (outSerial[0]may be 0 — the device declares exactly 0)false= cannot be read (outSerial[0]is set to 0 = unknown, not equal to 「the device serial number is 0」)- A
nullout-parameter or one shorter than 1 throwsIllegalArgumentException - While the snapshot is 0, every call really reads the EEPROM — callers that need it frequently should cache it themselves
int[] serial = new int[1];
if (slave.tryGetSerialNumber(serial)) {
// int carries the uint32 bit pattern, the same convention as serialNumber()
System.out.println("序列号 = " + Integer.toUnsignedString(serial[0])); // Serial number =
} else {
// Cannot be read — unknown; do not treat it as serial 0
}
ESM timeout configuration
// Get the current ESM state transition timeout configuration
int[] timeouts = slave.getEsmTimeouts(); // [IP, PS, SO, OS, SP, PI, BI, IB] (ms)
// Set the ESM state transition timeouts
slave.setEsmTimeouts(3000, 10000, 5000, 5000, 3000, 3000, 3000, 3000);
setEsmTimeouts(...) throws IllegalArgumentException if any timeout is negative (the runtime structure is unsigned 32-bit, so a negative value would wrap into a huge timeout; it is no longer sent silently).
| Category | Method | Type | Read/write | Description |
|---|---|---|---|---|
| ESM timeout configuration | getEsmTimeouts() | int[] | read-only | Get the ESM timeouts [IP, PS, SO, OS, SP, PI, BI, IB] (ms), returns null on failure |
| setEsmTimeouts(int ip, int ps, int so, int os, int sp, int pi, int bi, int ib) | boolean | write-only | Set the ESM timeouts |
Hot-plug / flags
// Hot-plug reconfiguration flag
boolean needsReconfig = slave.getNeedsStartupReconfig();
slave.clearNeedsStartupReconfig();
// OpOnly flag (exchange data only in OP state)
boolean opOnly = slave.getOpOnlyFlag();
// Error acknowledge (clear the AL error)
slave.setErrorAck(true);
// Device emulation flag
boolean emulation = slave.getDeviceEmulationFlag();
| Category | Method | Type | Read/write | Description |
|---|---|---|---|---|
| Hot-plug / flags | getNeedsStartupReconfig() | boolean | read-only | Whether startup reconfiguration is needed (after hot-plug) |
| clearNeedsStartupReconfig() | void | write-only | Clear the startup reconfiguration flag | |
| getOpOnlyFlag() | boolean | read-only | Get the OpOnly flag | |
| setErrorAck(boolean setAck) | boolean | write-only | Set the error acknowledge (clear the AL error) | |
| getDeviceEmulationFlag() | boolean | read-only | Get the device emulation flag |
Output data write
The whole-frame write entry is slave.slavePdo().outputs(byte[]); the length must equal the current output mapping, otherwise it is rejected outright with no truncation; returning false means it was not written. The legacy entry writeOutput(byte[]) is deprecated and equivalent to this.
Language boundary: writeOutput(byte[]) on this page is a real write entry (whole-frame submission; a failure return means nothing was written). The C ABI entries WriteSlaveOutput / WriteSlaveOutputByte are retired empty implementations that always fail; they are not the same thing as this entry. Do not infer this language's behavior from the C ABI names.
// Whole-frame commit (length must equal the output mapping)
boolean ok = slave.slavePdo().outputs(new byte[]{0x0F, 0x00});
// Whole-frame read-back
byte[] in = slave.slavePdo().inputs();
// Short frame / partial: patch a chunk of bytes at an offset
boolean ok2 = slave.PDO().writeFromTyped(new byte[]{0x0F, 0x00}, 0);
// Direct whole-frame write, returns the number of bytes written
int n = slave.PDO().writeOutputDataDirect(new byte[]{0x0F, 0x00});
| Category | Method | Type | Read/write | Description |
|---|---|---|---|---|
| Output data write | slavePdo().inputs() | byte[] | read-only | Whole input frame snapshot |
| slavePdo().outputs(byte[] data) | boolean | write-only | Whole-frame commit, length must equal the output mapping |
For single-point / few-field writes use the element view: slave.PDO().out().get(offset).asUInt8((byte) 0x0F) (the same family also has asInt16 / asUInt16 / asInt32 / asUInt32 / asFloat / asBool, and the parameterized overloads write). An element-view offset or width out of range throws IllegalArgumentException; a process image that is not ready (not in OP / not mapped) throws IllegalStateException.
ESI automatic configuration
Automatic startup runs on the master side: master.setENI(...) / master.setEsiFile(...) / master.setEsiFiles(...) / master.enableAutoStartup() (ENI/DENI used as-is when present, MDP devices automatic); refresh manually only when a single slave needs reconfiguration.
// Manually refresh the SM/FMMU/PDO mapping of this slave
boolean ok1 = slave.configureFromEsi();
// Equivalent entry (same implementation, does not configure DC)
boolean ok2 = slave.configByEsi();
| Category | Method | Type | Read/write | Description |
|---|---|---|---|---|
| ESI automatic configuration | setEsiFile(String filePath) | int | write-only | Set the ESI file path for this slave (0 = success, negative = error) |
| configureFromEsi() | boolean | write-only | Automatically configure the SM/FMMU/PDO mapping from the ESI file; failure is declared when not a single SM was configured | |
| configByEsi() | boolean | write-only | Equivalent entry of configureFromEsi(), does not configure DC (use DC().configureDC(...) for DC) |
Configuration source declaration (ConfigSource)
ConfigSource (com.darra.ethercat.data.ConfigSource) records which network configuration file this slave's startup parameters / PDO configuration came from. Both the declaration and the read-back live on Slave, and it is a pure declaration: it does not load files, read or write the slave, or issue any bus operation. Actually loading still goes through the master's ENI setup and build entry points.
public enum ConfigSource {
UNKNOWN(0), // Undeclared (instance default; must not be written explicitly)
ENI(1), // Configuration came from ENI (standard ETG.2100 network configuration XML)
DENI(2); // Configuration came from DENI (Darra extended network configuration, an ENI superset)
public final int value;
public int value(); // Raw numeric value
public static ConfigSource fromValue(int value); // Unknown codes return null (no guessing)
}
| Category | Method | Type | Read/write | Description |
|---|---|---|---|---|
| Configuration source | getConfigSource() | ConfigSource | read-only | Reads back the most recently declared source; UNKNOWN when never declared |
| setConfigSource(ConfigSource source) | void | write-only | Declares the source; only ENI / DENI are accepted, null or UNKNOWN throws IllegalArgumentException |
Write semantics:
- Only
ConfigSource.ENI/ConfigSource.DENIare accepted;nullandConfigSource.UNKNOWNthrowIllegalArgumentException— "unknown" is the undeclared default, and writing it explicitly would be fabricating a source - May be called repeatedly: a later declaration overwrites the previous one (ENI ↔ DENI switching is supported) and is read back through
getConfigSource() - Each declaration writes one DEBUG log entry (with the slave index and the before/after values)
- It issues no bus operation and does not change the already loaded configuration
ConfigSource.fromValue(int)returnsnullhonestly for unknown codes rather than guessing
slave.setConfigSource(ConfigSource.DENI);
ConfigSource src = slave.getConfigSource(); // DENI
native does not record the ENI / DENI source per slave — it only records two things per slave: "explicitly planned (explicit_replace)" and "merged ESI defaults (esi_installed)". getConfigSource() returns the declaration value kept on the SDK side: it reads back whatever the caller declared, not a read-back from the slave.
Slave ESI parsing
Besides file binding / the version number, slave.esi() can read ESI file contents directly. Device selection matches a unique <Device> exactly against this slave's identity in three steps: VendorId → ProductCode → RevisionNo; when the identity cannot be read it is treated as "identity unknown"; when multiple candidates cannot be narrowed to one it returns null / an empty list and never silently takes the first Device in the file.
| Category | Method | Type | Read/write | Description |
|---|---|---|---|---|
| ESI parsing | esi().loadDeviceInfo(String filePath) | ESI.DeviceInfo | read-only | Full device information; returns null when the file is unreadable / no Device matches / multiple candidates cannot be decided |
| esi().loadSyncManagers(String filePath) | List<ESI.SyncManagerInfo> | read-only | SM details of the matched Device (including PDO assignment stubs); returns an empty list when nothing matches | |
| esi().loadPdoConfiguration(String filePath) | ESI.PDOConfiguration | read-only | Rx/Tx PDO configuration (including Entry and Exclude); returns null when nothing matches | |
| esi().loadStartupParameters(String filePath) | List<Startup.StartupParameter> | read-only | InitCmd startup parameters (including transition / writeTiming / priority); returns an empty list when there is no InitCmd |
The return types of loadDeviceInfo / loadSyncManagers / loadPdoConfiguration come from com.darra.ethercat.internal.ESI (ESI.DeviceInfo / ESI.SyncManagerInfo / ESI.PDOConfiguration). These types are not part of the public SDK contract and must not be relied on as public API. The supported ESI entries are slave.setEsiFile(String) / slave.configureFromEsi() / slave.configByEsi() and master.setEsiFile / master.setEsiFiles; the return structures of the four parsing methods above are pending at the public contract level.
ESC register access (advanced)
Directly read and write slave ESC (EtherCAT Slave Controller) registers, used for fault diagnosis, custom ESC operations and low-level debugging. When both the primary and secondary ports are unavailable, writes automatically fall back to broadcast.
No call is needed during normal SDK use — the SDK already configures registers for state transitions / PDO / mailbox flows. This API is for deep diagnostics and special scenarios (for example reading error counters, forcing a port policy, debugging an ESI flash that does not take effect).
Register definitions are in ETG.1000.4 §6 / ETG.1000.6 §5 (public standards), for example:
| Register | Description |
|---|---|
| 0x0000 | Type / Revision / Build (device type) |
| 0x0030 | AL Control (master issues a state request) |
| 0x0130 | AL Status (current slave state) |
| 0x0134 | AL Status Code (error code) |
| 0x0300-0x030F | Error counters for ports 0-3 |
| 0x0400-0x043F | Watchdog configuration / counting |
| 0x0440-0x0443 | SM watchdog status / overflow counters: 0x0440 bit0 (0 = overflowed/expired, 1 = normal or not enabled; 0xFF = read failed/unknown); 0x0442/0x0443 write 0 to reset, reads do not clear |
readRegister(int offset, int size)
public byte[] readRegister(int offset, int size)
Read slave ESC registers (FPRD).
Parameters:
offset(int) — register address (for example0x0130= AL Status)size(int) — number of bytes to read (1 / 2 / 4, etc.)
Returns:
byte[]— byte array on success;nullon failure (slave offline / timeout)
writeRegister(int offset, byte[] data)
public boolean writeRegister(int offset, byte[] data)
Write slave ESC registers (FPWR).
Parameters:
offset(int) — register addressdata(byte[]) — data to write
Returns:
boolean—trueon success
Example:
Slave slave = master.getSlave(1);
// Read AL Status (0x0130, 2 bytes)
byte[] alStatus = slave.readRegister(0x0130, 2);
if (alStatus != null) {
int state = (alStatus[0] & 0xFF) | ((alStatus[1] & 0xFF) << 8);
System.out.printf("AL Status = 0x%04X (state=%d, err=%b)%n",
state, state & 0x0F, (state & 0x10) != 0);
}
// Read AL Status Code (0x0134, error code)
byte[] alCode = slave.readRegister(0x0134, 2);
if (alCode != null) {
int code = (alCode[0] & 0xFF) | ((alCode[1] & 0xFF) << 8);
System.out.printf("AL Status Code = 0x%04X%n", code);
}
// Write AL Control = 0x04 (request SafeOp)
slave.writeRegister(0x0030, new byte[]{0x04, 0x00});
EEPROM (SII) access
Read and write the slave SII EEPROM (Slave Information Interface, ETG.1000.6 §6). The EEPROM stores device identity and configuration information such as VendorID / ProductCode / RevisionNo / SerialNo / SyncManager / FMMU / PDO mapping / Strings. The SDK already reads it automatically during configuration, so applications generally do not need direct access.
Use EEPROM writes with care — a wrong write can corrupt the slave identity information and, in the worst case, brick the slave, requiring vendor tools to recover. Use only in the following scenarios:
- Flashing an alias address (ESC
0x0012) - Repairing factory data that was overwritten by mistake
- Vendor-authorized firmware / parameter flashing
EEPROM writes require the slave to be in Init / PreOp state; writes are rejected in OP.
EEPROM size is usually 1 KB - 16 KB (word-addressed, 1 word = 2 byte). The first 8 words hold basic vendor information, followed by the Category chain (Strings / General / FMMU / SyncM / TxPdo / RxPdo / DC / End=0xFFFF).
readEeprom(int byteOffset, int byteLength)
public byte[] readEeprom(int byteOffset, int byteLength)
Read a byte range from the slave SII EEPROM. The SDK handles BUSY polling and word alignment automatically.
Parameters:
byteOffset(int) — start byte offset (even alignment recommended)byteLength(int) — number of bytes to read (even number recommended)
Returns:
byte[]—byteLengthbytes of data;nullfor invalid parameters,nullon read failure
writeEeprom(int byteOffset, byte[] data)
public boolean writeEeprom(int byteOffset, byte[] data)
Write a byte range to the slave SII EEPROM. Both byteOffset and data.length must be even.
Parameters:
byteOffset(int) — start byte offset (must be even)data(byte[]) — bytes to write (length must be even)
Returns:
boolean—truewhen all words were written successfully
Example:
Slave slave = master.getSlave(1);
// Read vendor_id (EEPROM byte offset 0x10, length 4)
byte[] data = slave.readEeprom(0x10, 4);
if (data != null && data.length == 4) {
int vendorId = (data[0] & 0xFF) | ((data[1] & 0xFF) << 8)
| ((data[2] & 0xFF) << 16) | ((data[3] & 0xFF) << 24);
System.out.printf("VendorID = 0x%08X%n", vendorId);
}
// Read the 16-byte header (includes PDIControl/StationAlias, etc.)
byte[] header = slave.readEeprom(0, 16);
// Write the alias address (EEPROM byte offset 0x08)
// The slave must be in Init/PreOp state!
if (slave.state() == EcState.INIT) {
slave.writeEeprom(0x08, new byte[]{0x01, 0x00}); // alias = 1
}
- First choice:
readEeprom / writeEeprom(byte-based, automatic word alignment) - Second choice: already-wrapped properties such as
slave.vendorId() / productId() / serialNumber()
sii() — SII Category tri-state reads
public Sii sii()
Returns a Sii instance (lazily created, the same style as coe() / cia401()) that performs live SII reads and separates "success / really absent from the chain / cannot read".
| Category | Property | Type | Read/write | Description |
|---|---|---|---|---|
| SII tri-state | sii().tryFindCategory(catType, byteOffset, byteSize) | SiiReadStatus | read-only | Locate a Category's byte offset and length |
| sii().tryReadCategory(catType, data, maxBytes) | SiiReadStatus | read-only | Read the whole Category data (a legitimate 0-length segment returns OK) | |
| sii().tryGetGeneralInfo(info) | SiiReadStatus | read-only | Read the General Category (type=30) structured info | |
| sii().tryReadIdentity(SiiIdentity[] out) | SiiReadStatus | read-only | Read the four identity words (V/P/R/Serial, word 0x0008..0x000F); OK = complete identity, READ_FAILED = some word did not come back (no partial delivery) | |
| sii().tryReadSerialNumber(int[] out) | SiiReadStatus | read-only | Read the Serial word of the identity area (word 0x000E..0x000F); OK = real value (may be 0), READ_FAILED = cannot be read |
SiiReadStatus has three states: OK / NOT_FOUND / READ_FAILED. READ_FAILED must not be treated as "absent".
Attribution rules (same order as C#, item by item):
tryFindCategory: the locate call succeeded →OK; on locate failure the category chain is enumerated — enumeration failed (< 0, the SII context is unavailable) →READ_FAILED; the chain does contain the category but the locate/length word failed →READ_FAILED; the chain is readable and does not contain the category →NOT_FOUNDtryReadCategory: locate first as above and return directly when notOK; length 0 →OK+ empty array;SIIReadCategoryread failure →READ_FAILEDtryGetGeneralInfo: on a failed read, iftryFindCategory(30)returnsNOT_FOUND→NOT_FOUND, otherwiseREAD_FAILED(the GENERAL category exists but its data was not fully read = read failure)- Residual boundary: if the chain walk itself stops before reaching the target category (zero-length segment / hop limit), the target is reported as
NOT_FOUND; the SDK cannot obtain the information that would distinguish it
Difference from ProtocolCodes.siiFindCategory(byte[], int): the latter is pure parsing over a caller-supplied SII byte array (it does not read the slave and produces no SiiReadStatus; not found returns byteOffset = -1). The sii() try* entry points read the live SII, which is what separates "absent" from "cannot read".
Out-parameter convention: out-parameters are arrays (length at least 1, written by the method); invalid arguments throw IllegalArgumentException.
Example:
Sii sii = slave.sii();
int[] off = new int[1];
int[] size = new int[1];
SiiReadStatus st = sii.tryFindCategory(30, off, size); // 30 = General
if (st == SiiReadStatus.OK) {
System.out.printf("General: offset=%d size=%d%n", off[0], size[0]);
} else if (st == SiiReadStatus.NOT_FOUND) {
/* the chain really has no General category */
} else {
/* READ_FAILED: cannot read, must not be treated as "absent" */
}
SiiGeneralInfo[] info = new SiiGeneralInfo[1];
if (sii.tryGetGeneralInfo(info) == SiiReadStatus.OK) {
System.out.println("CoE SDO=" + info[0].supportsSdo()
+ " FoE=" + info[0].supportsFoE()
+ " EoE=" + info[0].supportsEoE()
+ " SoE=" + info[0].supportsSoE());
}
byte[][] data = new byte[1][];
if (sii.tryReadCategory(10, data, 4096) == SiiReadStatus.OK) { // 10 = Strings
System.out.println("Strings 字节数=" + data[0].length); // Strings byte count=
}
SiiGeneralInfo fields: groupIdx / imageIdx / orderIdx / nameIdx / coeDetails / foeDetails / eoeDetails / soeDetails / flags / ebusCurrentMa / physicalPort, plus supportsSdo() / supportsSdoInfo() / supportsPdoAssign() / supportsPdoConfig() / uploadAtStartup() / supportsCompleteAccess() / supportsFoE() / supportsEoE() / supportsSoE().
SII identity area (V/P/R/Serial, word 0x0008..0x000F)
The identity area is a fixed ESC area and does not go through the category chain, so tryReadIdentity / tryReadSerialNumber only ever produce OK / READ_FAILED and never NOT_FOUND.
| word | Field | Description |
|---|---|---|
| 0x0008 / 0x0009 | vendorId | V (Vendor ID) |
| 0x000A / 0x000B | productCode | P (Product Code) |
| 0x000C / 0x000D | revisionNo | R (Revision No) |
| 0x000E / 0x000F | serialNo | Serial (serial number) |
SiiIdentity is an immutable out-parameter object whose four fields are long (carrying the unsigned 32-bit value 0..4294967295, so Java int cannot read 0x80000000 as a negative number). Each item is assembled into 32 bits with the low word first (low | high << 16), matching the EEPROM direct-read convention.
Sii sii = slave.sii();
SiiIdentity[] ident = new SiiIdentity[1];
if (sii.tryReadIdentity(ident) == SiiReadStatus.OK) {
SiiIdentity i = ident[0];
System.out.printf("V=0x%08X P=0x%08X R=0x%08X Serial=%d%n",
i.vendorId, i.productCode, i.revisionNo, i.serialNo);
}
int[] serial = new int[1];
if (sii.tryReadSerialNumber(serial) == SiiReadStatus.OK) {
// int carries the uint32 bit pattern, the same convention as serialNumber()
System.out.println("序列号 = " + Integer.toUnsignedString(serial[0])); // Serial number =
}
A failed read is never folded to 0: if any of the 8 identity words does not come back, the whole read is READ_FAILED (the out-parameter is set to null / 0) — an incomplete identity area means no partial identity is delivered, and it is not passed off as "the device wrote no identity". READ_FAILED and "the real value is 0" are two different things and callers must handle them separately.
Difference from serialNumber(): serialNumber() is a native runtime identity snapshot whose 0 has three meanings (「not read / real value 0 / read failed」); to tell them apart use tryGetSerialNumber(int[]) or read the SII identity area directly.
DL Port control
The ESC DL Port Control register (0x0101) is used for port fault injection testing and manual diagnostics of redundant/ring topologies. The Java SDK provides dedicated writeDLPort / readDLPort methods to access 0x0101 directly (the generic writeRegister / readRegister also work).
writeDLPort(byte value) / readDLPort()
public boolean writeDLPort(byte value)
public byte readDLPort()
writeDLPort(value)— write the DL Port Control register (0x0101), returnstrueon successreadDLPort()— read the current DLPORT value, returns0on read failure
Parameters:
value(byte) — DLPORT value (0x00=Auto,0x03=P0 off,0x0C=P1 off,0x30=P2 off,0xC0=P3 off)
No call is needed during normal operation. Most users should diagnose port state by subscribing to the addSlavePortLinkChangedListener event and reading the port error counters. Use this only when you need to actively simulate a port fault (testing redundancy switching) or troubleshoot a specific port problem.
The ESC has 4 physical ports P0 / P1 / P2 / P3. The DL Port Control register bit definitions are:
0x00— Auto, all ports managed automatically by the ESC (default)0x03— Turn off P00x0C— Turn off P10x30— Turn off P20xC0— Turn off P3
When both the primary and secondary ports are unavailable, writeRegister / readRegister automatically fall back to broadcast writes, so recovery is still possible even after P0 is turned off.
Example:
// Simulate a P1 port fault (testing redundancy switching) — dedicated method
boolean ok = slave.writeDLPort((byte) 0x0C);
System.out.println("关闭 P1: " + (ok ? "成功" : "失败")); // Close P1: success / failure
// Read back to confirm
byte dlport = slave.readDLPort();
System.out.printf("当前 DLPORT = 0x%02X%n", dlport & 0xFF); // Current DLPORT = 0x%02X%n
// Restore after fault recovery
slave.writeDLPort((byte) 0x00); // restore Auto
After turning off a port, observe addSlavePortLinkChangedListener and master.diagnostics().getAllBreakPoints() to verify that redundancy switching took effect.
Recovery evidence and status
Automatic startup and real OP verification need per-station evidence from the "same sample": the caller packs each station's raw values into SlaveRealOpEvidence, then hands them to master.diagnostics().evaluateRealOp(evidence, wkcActual, wkcExpected) for the conclusion. The evidence fields are for assembly and display; whether each station is true or false is decided uniformly on the master side; a field that cannot be read must stay "unknown" — never pass 0 / false off as a measurement.
| Category | Method | Type/return | Read/write | Description |
|---|---|---|---|---|
| Recovery evidence | setSlaveIndex(int) | SlaveRealOpEvidence | call | Set the slave index (1-based); returns this for chained assembly |
| setRequired(boolean) | SlaveRealOpEvidence | call | Mark a required station (not optional and has process data) | |
| setAlive(boolean) | SlaveRealOpEvidence | call | Set the liveness conclusion (not judged offline) | |
| setProbeAlive(int) | SlaveRealOpEvidence | call | Set the probe tri-state: 0 = lost / 1 = measured response / 2 = unknown | |
| setNoProcessData(boolean) | SlaveRealOpEvidence | call | Set the master-level "no process data" truth value for the same sample | |
| setAlStatusCode(int) | SlaveRealOpEvidence | call | Set the measured AL Status Code (0xFFFF = not read) | |
| Recovery status | isActive() | boolean | call | Whether the recovery ladder is advancing (not Idle / Done / unknown) |
setSlaveIndex(int value)
public SlaveRealOpEvidence setSlaveIndex(int value)
Set the slave index this evidence entry corresponds to.
Parameters:
value(int) — slave index, 1-based
Returns:
SlaveRealOpEvidence— the current object (this), for chained assembly
setRequired(boolean value)
public SlaveRealOpEvidence setRequired(boolean value)
Set the "required station" marker. A required station = not optional and has process data of its own (it participates in the working counter). When the process data cannot be read, treat it as a required station: not being able to read it must not exclude a station from the conclusion.
Parameters:
value(boolean) —true= required station
Returns:
SlaveRealOpEvidence— the current object (this)
setAlive(boolean value)
public SlaveRealOpEvidence setAlive(boolean value)
Set the liveness conclusion. When the read fails it stays true ("not confirmed offline"); offline is never fabricated.
Parameters:
value(boolean) —true= not judged offline
Returns:
SlaveRealOpEvidence— the current object (this)
setProbeAlive(int value)
public SlaveRealOpEvidence setProbeAlive(int value)
Set the measured tri-state of the probe; the encoding matches the master probe. A failed read is treated as unknown.
Parameters:
value(int) — tri-state code:SlaveRealOpEvidence.PROBE_ALIVE_NO(0) = lost;PROBE_ALIVE_YES(1) = measured response;PROBE_ALIVE_UNKNOWN(2) = unknown
Returns:
SlaveRealOpEvidence— the current object (this)
setNoProcessData(boolean value)
public SlaveRealOpEvidence setNoProcessData(boolean value)
Set the measured master-level "no process data / false OP" truth value, shared by every station within the same sample. It corroborates a per-slave contribution bit that reads 0: with static inputs or a redundancy split even a healthy station can read 0 permanently, and without master-level corroboration it must not be convicted on its own.
Parameters:
value(boolean) —true= the master-level check for this sample confirms there is no process data
Returns:
SlaveRealOpEvidence— the current object (this)
setAlStatusCode(int value)
public SlaveRealOpEvidence setAlStatusCode(int value)
Set the measured AL Status Code. When it was not read, fill in SlaveRealOpEvidence.AL_STATUS_CODE_UNKNOWN (0xFFFF), not 0 — 0 is the real "no error" code and the two must not be mixed up.
Parameters:
value(int) — the measured AL Status Code, orAL_STATUS_CODE_UNKNOWN
Returns:
SlaveRealOpEvidence— the current object (this)
isActive()
public boolean isActive()
Whether the recovery ladder is advancing: the observation is available, and the current level is neither Idle nor Done, nor unknown. It is defined on MasterDiagnosticsInfo.SlaveRecoveryStatus and obtained via master.diagnostics().slaveRecovery(slaveIndex). When the observation is unavailable (older version / no instance / slave index out of range / master unavailable) it is always false; the other fields are meaningless then and must not be read as "there is no recovery".
Returns:
boolean—true= the recovery ladder is advancing
Example:
MasterDiagnosticsInfo.SlaveRecoveryStatus st = master.diagnostics().slaveRecovery(1);
if (st.isActive()) {
System.out.printf("从站 1 恢复中: %s/%s, 当前步已耗时 %d ms%n", // Slave 1 recovering: %s/%s, current step has taken %d ms%n
st.level, st.step, st.stepElapsedMs);
}
Per-station evidence assembly example:
SlaveRealOpEvidence ev = new SlaveRealOpEvidence()
.setSlaveIndex(1)
.setRequired(true)
.setAlive(true)
.setProbeAlive(SlaveRealOpEvidence.PROBE_ALIVE_YES)
.setNoProcessData(false)
.setAlStatusCode(0);
java.util.List<SlaveRealOpEvidence> evidence = java.util.Collections.singletonList(ev);
master.diagnostics().evaluateRealOp(evidence, wkcActual, wkcExpected);
Protocol support and ports
| Category | Method | Type/return | Read/write | Description |
|---|---|---|---|---|
| Protocol support | protocolSupportState(EtherCATTypes.MailboxProtocol) | Boolean | call | Capability bit tri-state: TRUE = the bit is set; null = not proven; never produces FALSE |
| Port topology | p1FoldbackOnly() | int | call | Foldback window reachability: 1 = reachable only through the foldback window; 0 = not; -1 = invalid parameter |
protocolSupportState(EtherCATTypes.MailboxProtocol bit)
public Boolean protocolSupportState(EtherCATTypes.MailboxProtocol bit)
Tri-state query of a mailbox protocol capability bit (the SII mbx_proto bit). TRUE = the bit is set, positive evidence from the device; null = not proven (the bit is not set or the read failed). This entry never produces FALSE — a negative conclusion can only come from a real read of SII General plus complete, valid mailbox geometry plus an explicit 0; see each protocol object's supportState().
Parameters:
bit(EtherCATTypes.MailboxProtocol) — capability bit, for exampleEtherCATTypes.MailboxProtocol.COE; passingnullthrowsIllegalArgumentException
Returns:
Boolean—TRUEornull, neverFALSE
Example:
Boolean coe = slave.protocolSupportState(EtherCATTypes.MailboxProtocol.COE);
if (Boolean.TRUE.equals(coe)) {
System.out.println("设备明确声明支持 CoE"); // Device explicitly declares CoE support
}
// coe == null means unproven, do not treat it as "not supported"
p1FoldbackOnly()
public int p1FoldbackOnly()
Whether this slave is reachable only through the foldback window (P1 dual-port ring + branch topology). This is a topology position judgement: frames outside the foldback window cannot reach it, so it must not be laid out like an ordinary linear station. It is not the same quantity as linkCount() (the measured connection count for the current sample) or topologyType() (the configuration-time structure classification).
Returns:
int—1= reachable only through the foldback window;0= not;-1= invalid parameter (master / station number unavailable)
Example:
if (slave.p1FoldbackOnly() == 1) {
System.out.println("从站 " + slave.SlaveNum + " 只能经折返窗口可达"); // Slave N is reachable only through the reflection window
}
Event injection and assertion entries
The trigger* methods on slave.events() are local delivery entries: they write directly to the listeners that are already registered, do not read the bus and do not send frames. Real events are still routed in by the master event system when it delivers them, so each channel fires on its own. Self-tests and assertions can use them to verify callback logic without real hardware.
| Category | Method | Type/return | Read/write | Description |
|---|---|---|---|---|
| Event injection | triggerStateChanged(EcState, EcState) | void | call | Deliver one state change locally |
| triggerEmergency(short, short, byte, short, short) | void | call | Deliver one CoE Emergency payload locally |
triggerStateChanged(EcState oldState, EcState newState)
public void triggerStateChanged(EcState oldState, EcState newState)
Deliver one state change to the SlaveEvents.StateChangedListener registered on this slave. An exception thrown by a single subscriber is isolated and does not affect the other subscribers.
Parameters:
oldState(EcState) — previous statenewState(EcState) — new state
Returns:
- None (
void)
Example:
slave.events().addStateChangedListener((oldState, newState) ->
System.out.printf("从站 %d: %s -> %s%n", slave.SlaveNum, oldState, newState)); // Slave %d: %s -> %s%n
slave.events().triggerStateChanged(EcState.SAFE_OP, EcState.OP);
triggerEmergency(short errorCode, short errorReg, byte b1, short w1, short w2)
public void triggerEmergency(short errorCode, short errorReg, byte b1, short w1, short w2)
Deliver one CoE Emergency payload to the SlaveEvents.EmergencyListener registered on this slave.
Parameters:
errorCode(short) — CANopen Emergency error codeerrorReg(short) — error register (object 0x1001)b1(byte) — manufacturer-specific data (byte 3)w1(short) — manufacturer-specific data (bytes 4-5)w2(short) — manufacturer-specific data (bytes 6-7)
Returns:
- None (
void)
Example:
slave.events().addEmergencyListener((ec, er, b, w1, w2) ->
System.out.printf("从站 %d 紧急消息 0x%04X%n", slave.SlaveNum, ec)); // Slave %d emergency message 0x%04X%n
slave.events().triggerEmergency((short) 0x2310, (short) 0x0000, (byte) 0x01, (short) 0, (short) 0);
Listener contracts
onSlaveIdentityMismatch(SlaveIdentityMismatchEventArgs args)
void onSlaveIdentityMismatch(SlaveIdentityMismatchEventArgs args)
Interface MasterEvents.SlaveIdentityMismatchListener (a functional interface). Register with master.events().addSlaveIdentityMismatchListener(listener) and unregister with removeSlaveIdentityMismatchListener(listener).
Trigger point: after a power-cycle replug or a slave replacement, the actual identity read does not match the configuration. The Revision does not participate in the rejection: MasterConfig.scanRevisionMatch() is always IGNORE_REVISION, so a match on Vendor + Product is enough to treat the device as the same one. EXACT and COMPATIBLE_HIGHER are declared values of MasterConfig.RevisionMatch but currently have no sendable entry, and setting them throws UnsupportedOperationException. The slave then enters IDENT_REJECTED and only recovers after master.acknowledgeSlaveReplacement(slaveIndex) is called. Entering that state fires once per round; only a re-probe after acknowledgement can fire it again.
Parameters:
args(SlaveIdentityMismatchEventArgs) — read-only payload:masterIndex(int) /slaveIndex(int) — master index / slave index (1-based)expectedVendor/expectedProduct/expectedRevision(long) — vendor ID / product code / revision expected by the configuration (the revision is reference only and does not participate in the identity check; 32-bit unsigned values are carried inlong, so negative values cannot occur)actualVendor/actualProduct/actualRevision(long) — the measured vendor ID / product code / revision number
Returns:
- None (
void)
Example:
master.events().addSlaveIdentityMismatchListener(args -> {
System.out.printf("从站 %d 身份不符: 期望 0x%08X/0x%08X, 实测 0x%08X/0x%08X%n", // Slave %d identity mismatch: expected 0x%08X/0x%08X, measured 0x%08X/0x%08X%n
args.slaveIndex, args.expectedVendor, args.expectedProduct,
args.actualVendor, args.actualProduct);
master.acknowledgeSlaveReplacement(args.slaveIndex);
});
onSlavePortLinkChanged(short masterIndex, short slaveIndex, byte port, boolean isUp)
void onSlavePortLinkChanged(short masterIndex, short slaveIndex, byte port, boolean isUp)
Interface MasterEvents.SlavePortLinkChangedListener (a functional interface). Register with master.events().addSlavePortLinkChangedListener(listener) and unregister with removeSlavePortLinkChangedListener(listener). It is delivered when the link state of one of the slave's physical ports changes, for disconnection detection and for observing redundancy switching.
Parameters:
masterIndex(short) — master indexslaveIndex(short) — slave indexport(byte) — port number 0-3, corresponding to P0 / P1 / P2 / P3isUp(boolean) —true= restored,false= disconnected
Returns:
- None (
void)
Example:
master.events().addSlavePortLinkChangedListener((mi, si, port, isUp) ->
System.out.printf("从站 %d 端口 P%d %s%n", si, port, isUp ? "恢复" : "断开")); // Slave %d port P%d %s%n (restored / disconnected)
Full example
Slave slave = master.getSlave(1);
// Basic information
System.out.println("名称: " + slave.name()); // Name:
System.out.println("厂商: 0x" + Integer.toHexString(slave.vendorId())); // Vendor: 0x
System.out.println("状态: " + slave.state()); // State:
// Sub-objects
CoE coe = slave.coe();
CiA402 drv = slave.cia402();
PDO pdo = slave.PDO();
// Read/write properties
slave.group((byte) 1); // assign to group 1
slave.isOptional(true); // mark as an optional slave