Skip to main content

Slave properties and methods

All slave functions use 1-based indexes (slave_index starts at 1).

Function signature convention

In every C API function the first parameter is master_index and the second is slave_index. The table below omits these two parameters from the signatures; a full call looks like GetSlaveName(master, slave, buf, size).

Properties​

CategoryFunctionReturn typeRead/writeDescription
Basic identificationGetSlaveName(buf, size)intread-onlySlave name (read from EEPROM); returns the actual length
GetSlaveDeviceName(buf, size)intread-onlyDrive/device name (read from SDO 0x1008)
Device informationGetSlaveVendorId()uint32_tread-onlyVendor ID (read from SII EEPROM)
GetSlaveProductCode()uint32_tread-onlyProduct code
GetSlaveRevision()uint32_tread-onlyRevision number
GetSlaveSerialNumber()uint32_tread-onlySerial number (runtime identity snapshot, not a direct EEPROM read): for slaves that matched an ESI the snapshot stays 0, so 0 means neither "the real value is 0" nor a read failure; use TryGetSlaveSerialNumber() for the EEPROM real value
GetSlaveVendorName(buf, size)BOOLread-onlyVendor name (read from the ESI file); returns TRUE on success
GetSlaveHasMDP()BOOLread-onlyWhether modular device profiles are supported (ETG.5001)
GetSlaveBlockLRW()BOOLread-onlyLRW logical read/write blocking flag
AddressGetSlaveConfigAddr()uint16_tread-onlyPhysical configuration address
GetSlaveAliasAddr()uint16_tread-onlyAlias address
StateGetSlaveState()uint8_tread-onlyCurrent EtherCAT state of the slave (cached read; returns EC_STATE_* enum semantics)
GetSlaveStateLiveRead()ec_live_read_tread-onlyLive state read (really sends one frame, bypassing the cache) 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 validity == EC_LIVE_READ_VALID
GetSlaveALStatusCode()uint16_tread-onlyAL 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 AL mirror's high byte. To force an on-the-spot re-read use GetSlaveALStatusCodeLiveRead() (with four-state trust); the raw lower-level entry point is DarraEcat_GetSlaveALStatusCodeLive())
GetSlaveALStatusCodeLiveRead()ec_live_read_tread-onlyLive AL Status Code (lossless 16-bit) plus four-state trust. When the slave is lost / not responding the lower layer returns 0; this entry point files it as EC_LIVE_READ_STALE and never reports it as "no error"
GetSlaveIsLost()BOOLread-onlyWhether the slave is lost (disconnected)
GetSlaveLiveness()ec_slave_liveness_tread-onlyLiveness three-state: EC_SLAVE_LIVENESS_ALIVE = confirmed alive / EC_SLAVE_LIVENESS_LOST = confirmed offline / EC_SLAVE_LIVENESS_UNKNOWN = insufficient evidence. GetSlaveIsLost() only answers "is it confirmed lost"; use this entry point to tell "insufficient evidence"
GetSlaveOfflineReason()ec_slave_offline_reason_tread-onlyOffline reason classification: EC_SLV_OFFLINE_REASON_REAL_OFFLINE = truly offline / EC_SLV_OFFLINE_REASON_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) / EC_SLV_OFFLINE_REASON_UNKNOWN = insufficient evidence
GetSlaveHasEnteredOperational()intread-onlyWhether it has ever successfully entered OP during this run: 1 = it has / 0 = no / -1 = invalid parameter (event-latched; compared lazily)
GetSlaveDroppedFromOperational()intread-onlyWhether it "entered OP but is not in OP now": 1 = yes / 0 = no / -1 = invalid parameter
GetSlaveOutOfOpDurationMs()int64_tread-onlyMonotonic duration the slave has continuously been out of OP (ms); -1 = unknown (in OP / never entered OP / no edge observed yet). System clock changes do not affect this value
GetSlaveOutOfOpSinceUnixMs()int64_tread-onlyStart of the out-of-OP period (Unix milliseconds, derived from "current wall clock - monotonic duration"); -1 = unknown
Diagnostics mirrorGetSlaveWcState()uint8_tread-onlyThis slave's contribution to the working counter (WKC) in the current cycle (1=contributed / 0=not contributed / 0xFF=unknown, direct real-time read)
GetSlaveInputValidity()ec_pdo_input_validity_tread-onlyFour-state validity of the input process data: EC_PDO_INPUT_VALID = this cycle's data is valid; EC_PDO_INPUT_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); EC_PDO_INPUT_STALE = cannot be used as the current value; EC_PDO_INPUT_UNKNOWN = no evidence. Use this entry point to decide "can this frame of data be used"; use GetSlaveIsLost() to decide "has the slave been confirmed offline"
GetSlaveAlStatusMirror()uint16_tread-only16-bit AL status mirror (low byte = AL State including the Error bit; high byte = the low 8 bits of the AL Status Code, valid only when the Error bit is set and the code is anything other than 0 — codes ≥ 0x0100 are truncated); a cache sampled while the master is in OP, not the live truth at read time
GetSlaveMailboxHealth()uint8_tread-onlyMailbox health of this slave (0=Unknown, 1=Healthy, 2=Degraded; direct real-time read)
GetSlaveFreeRunDemoted()uint8_tread-onlyWhether this slave was forced to fall back from DC to FreeRun (a value other than 0 = demoted; direct real-time read)
GetSlaveHealthDegradedCount()uint32_tread-onlyConsecutive cumulative count of mailbox half-failures on this slave (roughly seconds; 0 = healthy)
RecoverSlaveMailboxHealth()BOOLwrite-onlyManually trigger mailbox half-failure recovery for this slave (usually automatic)
TopologyGetSlaveTopologyType()uint8_tread-only`` Configuration-time topology classification snapshot: 0=NoLink / 1=EndPoint / 2=Line / 3=Fork / 4=Cross; 0xFF=unavailable (invalid handle / no master context); 0 is the valid verdict "no link", and the two must not be conflated; answers "how many ports does this device have", unchanged when a cable is pulled; not a per-cycle measurement
GetSlaveLinkCount()int32_tread-onlyPer-cycle measured link count (periodically refreshed from the slave port states): 1..4 = measured connections, -1 = unknown (all down or no sample yet) or invalid parameters; unknown is not "0 connections" and does not mean the slave dropped
GetSlaveParentStation()uint16_tread-onlyParent slave index (1-based; 0 = the parent is the master; a legacy name, the value is an index rather than a station address)
GetSlaveParentPort()int32_tread-onlyParent port number: 0..3 = parent port, -1 = unknown or invalid parameters; 0 is a valid P0, unknown does not mean P0
GetSlaveEntryPort()uint8_tread-onlyEntry port number
GetSlaveConsumedPorts()uint8_tread-onlyBitmask of consumed ports
GetSlavePhysicalType()uint8_tread-onlyPhysical port type
PDO dataGetSlaveInputBits() / GetSlaveOutputBits()uint16_tread-onlyInput/output data size in bits
GetSlaveInputBytes() / GetSlaveOutputBytes()uint32_tread-onlyInput/output data size in bytes
GetSlaveInputOffset() / GetSlaveOutputOffset()uint32_tread-onlyInput/output data offset
GetSlaveInputStartBit() / GetSlaveOutputStartBit()uint8_tread-onlyInput/output start bit
EEPROMGetSlaveEep8Byte()uint8_tread-onlyEEPROM addressing mode (1 = 8-byte, 0 = 4-byte)
GetSlaveEepPDI()uint8_tread-onlyPhysical device interface (PDI) type
GetSlaveEbusCurrent()int16_tread-onlyE-bus current consumption (mA)
ESI/configGetSlaveHasEsi(mi, si)BOOLread-onlyWhether a VendorId was read from SII (identity readable); it does not mean an ESI Device is bound. To confirm binding use esi_dll_bind_to_slave() / esi_dll_auto_match_all() (utils/esi_ext.h)
GetSlaveEsiVersion(mi, si, buf, size)BOOLread-onlyESI version (written to buf); returns TRUE on success
MailboxGetSlaveMailboxProto()uint16_tread-onlySupported mailbox protocol types (bitmask, cached value); use the tri-state query to judge capability
GetSlaveMailboxWriteLength()uint16_tread-onlyMailbox send buffer size
GetSlaveMailboxReadLength()uint16_tread-onlyMailbox receive buffer size
GetSlaveMailboxReadOffset() / GetSlaveMailboxWriteOffset()uint16_tread-onlyMailbox read/write offset
GetSlaveMbxCount()uint8_tread-onlyMailbox protocol counter
Protocol detailsGetSlaveCoEDetails()uint8_tread-onlyCoE protocol capability flags
GetSlaveEoEDetails()uint8_tread-onlyEoE protocol capability flags
GetSlaveFoEDetails()uint8_tread-onlyFoE protocol details
GetSlaveSoEDetails()uint8_tread-onlySoE protocol details
FMMUGetSlaveFMMU0Function()uint8_tread-onlyFMMU0 function type (bit 0 = output, bit 1 = input)
GetSlaveFMMU1Function()uint8_tread-onlyFMMU1 function type
GetSlaveFMMU2Function()uint8_tread-onlyFMMU2 function type
GetSlaveFMMU3Function()uint8_tread-onlyFMMU3 function type
DCGetSlaveHasDC()BOOLread-onlyWhether DC is supported
GetSlaveDCActive()uint16_tread-onlyRaw DC AssignActivate value (0 = inactive; 0x0100 = SYNC0 bit only, 0x0300 = SYNC0, 0x0700 = SYNC0+SYNC1). These are only common settings, not the criterion: the sole authority for "armed" is dc_sync0_armed(); for "in sync" check applicable and in_sync from dc_get_sync_window_info(); DCActive / DCCycle0 cannot be used to infer that sync is established
GetSlaveDCCycle0() / GetSlaveDCCycle1()int32_tread-onlySYNC0/SYNC1 cycle (ns)
GetSlaveDCShift()int32_tread-onlyPhase shift (ns)
GetSlavePDelay()int32_tread-onlyPropagation delay of a frame from the master to this slave (ns)
GetSlaveDCNext() / GetSlaveDCPrevious()uint16_tread-onlyDC next/previous slave index
GetSlaveDCParentPort()int32_tread-onlyCompatibility entry point for GetSlaveParentPort; 0..3 = parent port, -1 = unknown; it is not a separate DC-specific field
GetSlaveDCReceiveTimeA/B/C/D()int32_tread-onlyReceive time of ports A/B/C/D (ns)
ConfigurationGetSlaveGroup() / SetSlaveGroup(group)uint8_tread/writeSlave group number (0-7)
GetSlaveOptional() / SetSlaveOptional(opt)BOOLread/writeOptional-slave flag
GetSlaveSupportsFrameRepeat() / SetSlaveSupportsFrameRepeat(val)BOOLread/writeFrame repetition support (ETG.1500 5.4.3)
RedundancyGetSlaveRedundancyActivated(mi, si)BOOLread-onlyRedundancy protection is running = the master-level criterion GetRingMode(mi) >= 1 (Dual / Degraded); always FALSE in linear / end-return topologies and not a per-slave independent verdict
GetSlavePrimaryLinkBroken(mi, si)BOOLread-onlyWhether the primary link is broken
GetSlaveSecondaryLinkBroken(mi, si)BOOLread-onlyWhether the secondary link is broken
FlagsGetSlaveOpOnlyFlag()BOOLread-onlyLegacy misnomer: it actually reads SII General Flags bit1 = NotLRW (LRW not supported), not the OpOnly bit. The real OpOnly (Flags bit0) is read from the flags of the SII General category. A FALSE return can also mean the slave was not found or the master is not initialized
GetSlaveDeviceEmulationFlag()BOOLread-onlyDevice emulation flag
SetSlaveErrorAck(set_ack)BOOLwrite-onlyAcknowledge a slave error (clears the AL Status Code)
Topology extensionsGetSlaveActivePorts(mi, si)uint8_tread-onlyActive-port bitmask
GetSlaveParent(mi, si)uint16_tread-onlyParent slave index
Structural snapshot and per-cycle measurement are not interchangeable

GetSlaveTopologyType() is a configuration-time structural snapshot, GetSlaveLinkCount() is a per-cycle measurement. The former answers "how many ports does this device have" and does not change when a cable is pulled; the latter answers "how many ports are actually connected right now" and changes within 200 ms of a cable pull. Structural criteria (topology audit / parent port / redundancy expectations) read GetSlaveTopologyType(); runtime display and live diagnostics read GetSlaveLinkCount(). The two must never be swapped.

On the C side the topology classification is a uint8_t, and failure and "no link" are separate buckets: invalid parameters / not calibrated return 0xFF = unavailable; 0 is the valid verdict NoLink, not a failure value. Callers must first test > 4 (or == 0xFF) for unavailable, then interpret 0..4 — doing it the other way round treats 0xFF as a port bitmap and reads it as "all four ports connected". The -1 from GetSlaveLinkCount() only means "the per-cycle measured link count is unknown", not that the structural classification is unknown; the two cannot stand in for each other.

C-specific sugar

C code can use the short inline names ec_vendor / ec_product / ec_state in place of the long forms GetSlaveVendorId / GetSlaveProductCode / GetSlaveState (zero cost, fully inlined at compile time).

WKC contribution state (GetSlaveWcState)​

GetSlaveWcState(mi, si) returns this slave's contribution state for the working counter (WKC) in the current cycle (direct real-time read of the per-slave mirror maintained by the runtime):

  • 0 NotContributed — the slave is not contributing to the WKC at this moment (likely a slave drop / hot-plug recovery in progress). This is not a master fault; once the slave recovers the mirror returns to 1 by itself.
  • 1 Contributed — the slave contributes to the WKC normally, i.e. when the aggregate WKC is complete (actual == expected, equivalently the deficit GetWcDeficit(mi) == 0) every slave compares as "full" byte for byte.
  • 0xFF Unknown — the mirror is not populated (the contract is not ready); this is exposed honestly and never fabricated as "contributed".
Reliability convention

This interface only "reports bus reality as it is" and takes part in no WKC tampering or accommodation logic. The per-slave contribution bit decomposes the aggregate WKC deficit (GetWcDeficit = expected - actual) per slave; a deficit greater than 0 means some slave is not contributing at this moment and calls for an alarm plus diagnostics — never lower expected, never stop OP. Companion master-level direct reads: GetWcDeficit(mi) / GetWkcActualMirror(mi) / GetWkcExpectedMirror(mi).

Input data validity (GetSlaveInputValidity)​

GetSlaveInputValidity(mi, si) 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" (GetSlaveIsLost()).

ValueWhat you seeRecommended use
EC_PDO_INPUT_VALIDThis cycle's PDO exchange was complete; the input image is the current valueUse normally
EC_PDO_INPUT_DEGRADEDThis 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 valueDo not treat this as "the data is definitely trustworthy": either wait for recovery, or cross-check GetSlaveIsLost() / GetSlaveOfflineReason() / GetSlaveInputValidity() to see which slaves are untrustworthy. It turns EC_PDO_INPUT_STALE only after N full cycles without recovery (N is computed from the group cycle and the slave watchdog)
EC_PDO_INPUT_STALEThe 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
EC_PDO_INPUT_UNKNOWNNo 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 EC_PDO_INPUT_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.

GetStaleInputCount(mi) counts only slaves confirmed EC_PDO_INPUT_STALE; it does not count while EC_PDO_INPUT_DEGRADED applies.

Mailbox protocol types (GetSlaveMailboxProto)​

GetSlaveMailboxProto(mi, si) returns the SII mbx_proto capability bitmap (ECT_MBXPROT_*), one bit per protocol, which can be tested directly with a bitwise AND against ECT_MBXPROT_*:

  • 0x0001 AoE — ADS over EtherCAT
  • 0x0002 EoE — Ethernet over EtherCAT
  • 0x0004 CoE — CANopen over EtherCAT
  • 0x0008 FoE — File over EtherCAT
  • 0x0010 SoE — Servo over EtherCAT
  • 0x0020 VoE — Vendor over EtherCAT

Protocol capability tri-state​

The bitmap from GetSlaveMailboxProto(mi, si) is a cached value: on the ESI fast path, when SII word 0x001C has not been read, it is written as MBXPROT_COE (0x04) and every other protocol bit stays 0. Reading a 0 bit as "not supported" pins a wrong device capability permanently; mbx_is_protocol_supported() is a boolean view that also returns 0 when "the protocol is not registered / the capability cannot be read", which looks exactly like "genuinely not supported".

When you need to distinguish supported / not supported / unknown, use the tri-state query:

typedef enum {
EC_PROTO_SUPPORT_UNKNOWN = -1, /* query failed / no data: unknown, not the same as not supported */
EC_PROTO_SUPPORT_NO = 0, /* authoritative evidence read: the device does not declare this protocol */
EC_PROTO_SUPPORT_YES = 1 /* the device declares support (SII bit or capability bit) */
} ec_proto_support_state_t;

ec_proto_support_state_t ec_slave_get_proto_support_state(uint16_t master_idx,
uint16_t slave_idx,
uint8_t protocol_type);
const char* ec_proto_support_state_text(ec_proto_support_state_t state);

protocol_type takes a MBXPROT_* value: 0x01 AoE / 0x02 EoE / 0x03 CoE / 0x04 FoE / 0x05 SoE / 0x0F VoE / 0x10 FSoE / 0x11 PDO.

Decision chain (same authoritative rule as the FoE tri-state implementation):

  1. Invalid slave index / SDK not ready → UNKNOWN;
  2. The SII mailbox capability bit (GetSlaveMailboxProto) hits → YES (positive evidence);
  3. The SII General category was really read (SIIGetGeneralInfo == 1): for CoE check coe_details != 0; for EoE / FoE / SoE check bit0 of the respective *_details; a hit gives YES, otherwise NO;
  4. AoE / VoE have no dedicated details field in SII General, so a 0 bit with a successful SII read still yields UNKNOWN (there is no authoritative negative evidence);
  5. Everything else → UNKNOWN.

FSoE is carried over CoE and PDO goes through the CoE proxy, so both are judged by the CoE bit.

ec_proto_support_state_text() returns a static string (no allocation) that can be logged directly.

Related structures / convenience wrapper:

/* inline wrapper (same calling style as GetSlaveMailboxProto) */
static inline ec_proto_support_state_t
GetSlaveProtoSupportState(uint16_t master, uint16_t slave, uint8_t protocol_type);
#include "ethercat.h"

ec_proto_support_state_t st = GetSlaveProtoSupportState(master, 1, MBXPROT_COE);
printf("CoE 能力: %s\n", ec_proto_support_state_text(st)); /* CoE capability: %s */
if (st == EC_PROTO_SUPPORT_UNKNOWN) {
/* query failed: do not cache it as "not supported" forever, retry later */
}
Do not collapse UNKNOWN into NO

EC_PROTO_SUPPORT_UNKNOWN means "cannot be determined", not "the device does not support it". If a higher layer caches it as NO, then once the SII reads succeed later the device capability stays permanently wrong. The boolean mbx_is_protocol_supported() is only suitable on paths where the capability bits are already known to be trustworthy.

CoE protocol capability flags (CoEDetails)​

  • 0x01 — SDO supported
  • 0x02 — SDO Info supported
  • 0x04 — PDO Assign supported
  • 0x08 — PDO Config supported
  • 0x10 — Startup supported
  • 0x20 — Complete Access supported

EoE protocol capability flags (EoEDetails)​

  • 0x01 — sending frames supported
  • 0x02 — receiving frames supported
  • 0x04 — setting IP parameters supported
  • 0x08 — reading IP parameters supported

State transitions​

BOOL SetSlaveStateWithTimeout(uint16_t master_index, uint16_t slave_index,
int state, uint32_t timeout_ms);

Sets the EtherCAT state of a slave (with timeout). Use it to recover a single slave manually or to move a slave to a given state. The transition follows the standard EtherCAT state machine flow; intermediate states are handled automatically by the protocol layer.

Parameters:

  • master_index (uint16_t) — master index
  • slave_index (uint16_t) — slave index (1-based)
  • state (int) — target state (EC_STATE_INIT / EC_STATE_PRE_OP / EC_STATE_SAFE_OP / EC_STATE_OPERATIONAL)
  • timeout_ms (uint32_t) — timeout in milliseconds

Example:

/* manually recover a single slave to OP */
if (GetSlaveState(master, 1) != EC_STATE_OPERATIONAL) {
SetSlaveStateWithTimeout(master, 1, EC_STATE_OPERATIONAL, 5000);
}

Slave I/O area properties​

Position and size of the PDO input/output areas in the process data image, used for zero-copy pointer offset arithmetic and for locating PDO fields.

Parameters (shared by this group of GetSlaveInput* / GetSlaveOutput*):

  • master / slave (uint16_t) — master index / slave index (1-based)

Return values:

  • GetSlaveInputBits / GetSlaveOutputBits — uint16_t bit count
  • GetSlaveInputBytes / GetSlaveOutputBytes — uint32_t byte count (bits / 8, with a partial byte counted as a full byte)
  • GetSlaveInputOffset / GetSlaveOutputOffset — uint32_t start byte offset in IOmap
  • GetSlaveInputStartBit / GetSlaveOutputStartBit — uint8_t start bit within the containing byte (0-7)

GetSlaveInputBits() / GetSlaveOutputBits()​

uint16_t GetSlaveInputBits (uint16_t master, uint16_t slave);
uint16_t GetSlaveOutputBits(uint16_t master, uint16_t slave);

Total size of the input / output PDO areas in bits.

GetSlaveInputBytes() / GetSlaveOutputBytes()​

uint32_t GetSlaveInputBytes (uint16_t master, uint16_t slave);
uint32_t GetSlaveOutputBytes(uint16_t master, uint16_t slave);

Size of the input / output PDO areas in bytes (bits / 8, with a partial byte counted as a full byte).

GetSlaveInputOffset() / GetSlaveOutputOffset()​

uint32_t GetSlaveInputOffset (uint16_t master, uint16_t slave);
uint32_t GetSlaveOutputOffset(uint16_t master, uint16_t slave);

Byte offset of the input / output PDO area within the master IOmap. PDOs of multiple slaves are laid out in order; this value is used to locate them across slaves.

GetSlaveInputStartBit() / GetSlaveOutputStartBit()​

uint8_t GetSlaveInputStartBit (uint16_t master, uint16_t slave);
uint8_t GetSlaveOutputStartBit(uint16_t master, uint16_t slave);

Start bit (0-7) of the input / output PDO area within its containing byte. Only meaningful for bit-aligned PDOs; byte-aligned PDOs always return 0.

Example:

uint16_t in_bits  = GetSlaveInputBits(master, 1);
uint32_t in_bytes = GetSlaveInputBytes(master, 1);
uint32_t in_off = GetSlaveInputOffset(master, 1);
uint8_t in_sbit = GetSlaveInputStartBit(master, 1);
printf("从站1 输入 PDO: %u bit, %u byte, IOmap 偏移=%u, 起始位=%u\n", /* Slave 1 input PDO: %u bit, %u byte, IOmap offset=%u, start bit=%u */
in_bits, in_bytes, in_off, in_sbit);

Slave SII properties​

Device identity and configuration information provided by the EEPROM (SII). The SDK already reads it during config_init and caches it in the slave structure.

CategoryFunctionTypeRead/writeDescription
Device identityGetSlaveVendorId(mi, si)uint32_tread-onlyVendor ID (assigned by ETG)
GetSlaveProductCode(mi, si)uint32_tread-onlyProduct code (assigned by the vendor)
GetSlaveRevision(mi, si)uint32_tread-onlyRevision number
GetSlaveSerialNumber(mi, si)uint32_tread-onlySerial number (runtime identity snapshot, not a direct EEPROM read): stays 0 for slaves that matched an ESI; use TryGetSlaveSerialNumber() from the next section for the EEPROM real value
GetSlaveEep8Byte(mi, si)uint8_tread-onlyEEPROM addressing mode (1 = 8-byte, 0 = 4-byte)
GetSlaveEepPDI(mi, si)uint8_tread-onlyPhysical device interface (PDI) type
GetSlaveEbusCurrent(mi, si)int16_tread-onlyE-bus current consumption (mA)
GetSlaveBlockLRW(mi, si)BOOLread-onlyLRW logical read/write blocking flag
GetSlavePhysicalType(mi, si)uint8_tread-onlyPhysical port type
GetSlaveCoEDetails(mi, si)uint8_tread-onlyCoE protocol capability flag bitmask
GetSlaveFoEDetails(mi, si)uint8_tread-onlyFoE protocol details bitmask
GetSlaveEoEDetails(mi, si)uint8_tread-onlyEoE protocol capability flag bitmask
GetSlaveSoEDetails(mi, si)uint8_tread-onlySoE protocol details bitmask
GetSlaveHasMDP(mi, si)BOOLread-onlyWhether MDP is supported (ETG.5001)
tip

The common fields need no manual EEPROM reads; the SDK exposes them as the properties above.

Serial number (GetSlaveSerialNumber / TryGetSlaveSerialNumber)​

uint32_t GetSlaveSerialNumber(uint16_t master, uint16_t slave);       /* slave/core.h */
int TryGetSlaveSerialNumber(uint16_t master, uint16_t slave,
uint32_t* out_serial); /* slave/sii.h */

GetSlaveSerialNumber() returns the SER field of the runtime identity snapshot: cold configuration reads the SER word only for slaves that did not match an ESI (a performance trade-off), so slaves that matched an ESI stay at 0. Its 0 is therefore neither 「the device serial number really is 0」 nor 「a read failure」 — the raw outlet cannot tell the three cases apart.

Use TryGetSlaveSerialNumber() when you need the EEPROM real value with those two cases distinguished:

Return value*out_serialMeaning
1the real value (may be 0 — the device declares serial number 0)The serial number was obtained: ① a snapshot other than 0 is returned directly without touching the EEPROM; ② a snapshot of 0 triggers a live read of SII word 0x000E / 0x000F
00 (unknown)The read failed (an SII word did not come back / the out parameter is NULL); this does not mean 「the device serial number is 0」

Parameters:

  • master / slave (uint16_t) — master / slave index, 1-based
  • out_serial (uint32_t*) — must not be NULL; set to 0 (unknown) when the call returns 0
Three different kinds of 0

GetSlaveSerialNumber() returning 0, TryGetSlaveSerialNumber() returning 0 (with value 0), and TryGetSlaveSerialNumber() returning 1 with a value of 0 are three different facts: the first only says the snapshot was not read (it may have been skipped by cold configuration, and it may really be 0), the second is a failed read (unknown), and only the third means "the device serial number really is 0". Never convert one into another.

note

When the snapshot is 0, every call really reads the EEPROM — cache it yourself if you need it frequently. To fetch Vendor / Product / Revision / Serial in one go, use SiiTryReadIdentity() in the next section.

Slave mailbox properties​

Mailbox (SyncManager 0/1) configuration and protocol support.

CategoryFunctionTypeRead/writeDescription
Mailbox configurationGetSlaveMailboxProto(mi, si)uint16_tread-onlySupported mailbox protocol bitmask (AoE/EoE/CoE/FoE/SoE/VoE)
GetSlaveMailboxWriteLength(mi, si)uint16_tread-onlyMailbox send buffer size (bytes)
GetSlaveMailboxWriteOffset(mi, si)uint16_tread-onlyOffset of the mailbox write SyncManager in ESC memory
GetSlaveMailboxReadLength(mi, si)uint16_tread-onlyMailbox receive buffer size (bytes)
GetSlaveMailboxReadOffset(mi, si)uint16_tread-onlyOffset of the mailbox read SyncManager in ESC memory
GetSlaveMbxCount(mi, si)uint8_tread-onlyMailbox protocol counter (next-counter, 3-bit wrap-around)

Example:

uint16_t proto = GetSlaveMailboxProto(master, 1);
if (proto & 0x04)
printf("从站1 支持 CoE\n"); /* Slave 1 supports CoE */

uint16_t wr_len = GetSlaveMailboxWriteLength(master, 1);
uint16_t rd_len = GetSlaveMailboxReadLength(master, 1);
printf("邮箱: 写 %u 字节 / 读 %u 字节\n", wr_len, rd_len); /* Mailbox: write %u bytes / read %u bytes */

Process data watchdog​

SetSlaveWatchdog()​

BOOL SetSlaveWatchdog(uint16_t master_index, uint16_t slave_index, uint32_t timeout_ms);

Sets the process data watchdog timeout of a slave. When the slave receives no process data frame within the timeout, a watchdog error is raised (ALStatusCode 0x001B).

Parameters:

  • master_index / slave_index (uint16_t) — master index / slave index (1-based)
  • timeout_ms (uint32_t) — timeout in milliseconds; 0 = disabled; maximum 6553 ms

Return value (tri-state, reported truthfully): the return value only answers "does what was written match the request". For the failure reason check Win32 GetLastError() — on the same thread, immediately after the call, because calling any other function a few lines later overwrites it:

  • TRUE — what was written matches the request and the register write succeeded.
  • FALSE + GetLastError()==87 (ERROR_INVALID_PARAMETER) — the request exceeds the 6553 ms register limit (0x0420 / 0x0410 = u16 × 0.1 ms); it is rejected and not a single byte is written; it is neither truncated nor silently clamped to 6553.
  • FALSE + GetLastError()==0x20000011 (application-defined code) — the value was raised to the safety floor and written with the raised value (required by the topology rules: 5000 ms for branch slaves / 400 ms for PDO slaves on a ring). The actual value then differs from the request; to get the actual milliseconds call GetSlaveWatchdogConfig() and read wd_time_pd / 10.
  • FALSE + GetLastError()==0 — the register write failed or the index is invalid; nothing was written.
  • When DarraEcat_ShellStatus() != 0 the function returns FALSE with last-error = 0, the same value as "write failed"; to tell them apart, take the return value of DarraEcat_ShellStatus() first.

FALSE does not mean "not set": 0x20000011 means "written but raised"; do not skip the follow-up handling as if it had failed.

note

Call this in the SafeOp or OP state.

SetSlavePdiWatchdog()​

BOOL SetSlavePdiWatchdog(uint16_t master_index, uint16_t slave_index, uint32_t timeout_ms);

Sets the PDI watchdog timeout of a slave. The PDI watchdog monitors whether the slave's local application (microcontroller firmware) is running.

Parameters:

  • master_index / slave_index (uint16_t) — master index / slave index (1-based)
  • timeout_ms (uint32_t) — timeout in milliseconds; 0 = disabled

Return value (tri-state, reported truthfully): same criteria as SetSlaveWatchdog (for the failure reason read GetLastError() on the same thread), but the PDI watchdog has no safety-floor raising branch, so 0x20000011 never appears; there are only three outcomes:

  • TRUE — what was written matches the request and the register write succeeded.
  • FALSE + GetLastError()==87 (ERROR_INVALID_PARAMETER) — the request exceeds the 6553 ms register limit; it is rejected and not a single byte is written.
  • FALSE + GetLastError()==0 — the register write failed or the index is invalid; nothing was written (the same value occurs when DarraEcat_ShellStatus() != 0, so take that return value first to tell them apart).

SetAllSlaveWatchdog() / SetAllSlavePdiWatchdog()​

int SetAllSlaveWatchdog(uint16_t master_index, uint32_t timeout_ms);
int SetAllSlavePdiWatchdog(uint16_t master_index, uint32_t timeout_ms);

Sets the watchdog timeout of all slaves in one call.

Parameters:

  • master_index (uint16_t) — master index
  • timeout_ms (uint32_t) — timeout in milliseconds; 0 = disabled

Return value (the number of slaves written, not a boolean): it must be read together with GetLastError() (same thread, taken immediately after the call):

Return valueGetLastError()Meaning
>00All written as requested
>00x20000011In this batch some slaves were raised to the safety floor (5000 ms for branch slaves / 400 ms for PDO slaves on a ring); the actual values differ from the request, so this does not mean "all written as requested"; per slave, use GetSlaveWatchdogConfig() to read wd_time_pd / 10 for the actual milliseconds
087The whole batch exceeds the 6553 ms limit; the whole batch is rejected and nothing is written
00Invalid master index / no slaves / write failure (an invalid index falls into the 0 bucket, not 87)
  • 0 + 0x20000011 never occurs (0 means nothing was written, so "written after raising" cannot happen).
  • Slaves that were raised and then written with the actual value still count as successful; do not count successes with the per-slave SetSlaveWatchdog() return value (for "written after raising" it truthfully returns FALSE, which would be miscounted as not set).
  • When the SDK is not ready (runtime not loaded, DarraEcat_ShellStatus() != 0, no lower-layer call made) the function returns -1 with last-error pinned to 0; -1 is not a value the lower layer can return (it only returns 0 or the number of slaves written), so it cannot be confused with the 0 / >0 cases.
  • PDI batch (SetAllSlavePdiWatchdog): when >0, last-error is always 0; 0x20000011 never occurs (the PDI watchdog has no safety-floor raising branch).

GetSlaveWatchdogConfig()​

BOOL GetSlaveWatchdogConfig(uint16_t master_index, uint16_t slave_index, ec_watchdog_config_t* config);

Reads the current watchdog configuration of a slave.

Parameters:

  • master_index / slave_index (uint16_t) — master index / slave index (1-based)
  • config (ec_watchdog_config_t*) — [out] current configuration

Return value:

  • BOOL — TRUE on success

Related structure:

typedef struct {
uint16_t wd_divider; /* watchdog divider */
uint16_t wd_time_pdi; /* PDI watchdog timeout value (in divider units) */
uint16_t wd_time_pd; /* process data watchdog timeout value (in divider units) */
} ec_watchdog_config_t;

GetSlaveWatchdogStatus()​

BOOL GetSlaveWatchdogStatus(uint16_t master_index, uint16_t slave_index, ec_watchdog_status_t* status);

Reads the runtime watchdog status of a slave.

wd_status comes from bit0 of ESC register 0x0440: 0 = the watchdog has overflowed / expired, 1 = the watchdog is healthy or not enabled; bits above bit0 are reserved. If the read fails the field is the 0xFF sentinel, meaning unknown (neither healthy nor expired), and the function also returns FALSE. 0x0442 / 0x0443 are watchdog overflow counters (writing 0 resets them, reading does not clear them) and are not the same thing as the status bit in 0x0440.

Per-field trustworthiness is given by valid_mask: each field has a corresponding valid bit; set = the register was really read this time and the field value is trustworthy; clear = the register read failed and the field is fixed at 0 (this is not the device's real value, do not read it as "the value is 0").

Parameters:

  • master_index / slave_index (uint16_t) — master index / slave index (1-based)
  • status (ec_watchdog_status_t*) — [out] current runtime status

Return value:

  • BOOL — TRUE on success

Related structure:

typedef struct {
uint8_t wd_status; /* SM watchdog status, 0x0440 bit0 (0 = overflowed/expired, 1 = healthy or not enabled; 0xFF = read failed/unknown) */
uint8_t wd_counter; /* SM watchdog counter, 0x0442 */
uint16_t wd_divider; /* current divider value, 0x0400 */
uint16_t wd_time_pd; /* current process data watchdog value, 0x0420 */
uint8_t wd_counter_pdi; /* PDI watchdog overflow counter, 0x0443 (0 when the read fails, see valid_mask) */
uint16_t valid_mask; /* EC_WD_STATUS_VALID_* bit set: set = the field was really read successfully */
} ec_watchdog_status_t;

Valid-bit macros (valid_mask):

#define EC_WD_STATUS_VALID_STATUS       0x0001u  /* wd_status      <- 0x0440 */
#define EC_WD_STATUS_VALID_COUNTER 0x0002u /* wd_counter <- 0x0442 */
#define EC_WD_STATUS_VALID_DIVIDER 0x0004u /* wd_divider <- 0x0400 */
#define EC_WD_STATUS_VALID_TIME_PD 0x0008u /* wd_time_pd <- 0x0420 */
#define EC_WD_STATUS_VALID_COUNTER_PDI 0x0010u /* wd_counter_pdi <- 0x0443 */

The structure is not packed and uses natural alignment: sizeof == 10, align == 2; wd_counter_pdi is at offset 6 and valid_mask at offset 8. The header pins the layout with DARRA_EC_LAYOUT_ASSERT, so any drift on either side fails the build immediately.

Example:

/* set a 100 ms timeout — tri-state, reported truthfully; for the failure reason see GetLastError (same thread, taken right after the call) */
if (SetSlaveWatchdog(master, 1, 100)) {
/* what was written matches the request */
} else {
DWORD err = GetLastError();
if (err == 87) /* above the 6553 ms limit, rejected and not written */
;
else if (err == 0x20000011) /* raised to the safety floor and written, actual value != request */
; /* for the actual milliseconds read `wd_time_pd / 10` with GetSlaveWatchdogConfig below */
else /* write failed / invalid index */
;
}

/* read the configuration */
ec_watchdog_config_t config;
if (GetSlaveWatchdogConfig(master, 1, &config)) {
printf("PD超时: %u x %.2f us\n", config.wd_time_pd, config.wd_divider * 0.04); /* PD timeout: %u x %.2f us */
}

/* check the status — read valid_mask first, then the fields */
ec_watchdog_status_t status;
if (GetSlaveWatchdogStatus(master, 1, &status)) {
if (status.valid_mask & EC_WD_STATUS_VALID_STATUS) {
if ((status.wd_status & 0x01) == 0)
printf("看门狗过期! SM 计数: %d\n", status.wd_counter); /* Watchdog expired! SM count: %d */
} else {
printf("0x0440 读失败,wd_status 不可信\n"); /* 0x0440 read failed, wd_status cannot be trusted */
}

/* the PDI watchdog counter is only meaningful when its valid bit is set */
if (status.valid_mask & EC_WD_STATUS_VALID_COUNTER_PDI)
printf("PDI 溢出计数: %u\n", status.wd_counter_pdi); /* PDI overflow count: %u */
}

/* disable the watchdog */
SetSlaveWatchdog(master, 1, 0);

Slave verification​

BOOL GetSlaveIdentity(uint16_t master_index, uint16_t slave_index, ec_slave_identity_t* identity);
BOOL VerifySlaveIdentity(uint16_t master_index, uint16_t slave_index,
ec_slave_identity_t* expected, BOOL check_rev, BOOL check_serial);
BOOL VerifyAllSlaveIdentities(uint16_t master_index, ec_slave_identity_t* expected_identities,
uint32_t slave_count, BOOL check_revision, BOOL check_serial,
uint64_t* mismatch_mask);
BOOL SetSlaveOptional(uint16_t master_index, uint16_t slave_index, BOOL is_optional);
BOOL GetSlaveOptional(uint16_t master_index, uint16_t slave_index);
typedef struct {
uint32_t VendorId;
uint32_t ProductCode;
uint32_t RevisionNo;
uint32_t SerialNo;
} ec_slave_identity_t;

Hot-plug reconfiguration​

BOOL GetSlaveNeedsStartupReconfig(uint16_t master_index, uint16_t slave_index);
void ClearSlaveNeedsStartupReconfig(uint16_t master_index, uint16_t slave_index);

ESM timeouts (ETG.1020)​

BOOL GetSlaveEsmTimeouts(uint16_t master_index, uint16_t slave_index, ec_esm_timeouts_t* timeouts);
BOOL SetSlaveEsmTimeouts(uint16_t master_index, uint16_t slave_index, ec_esm_timeouts_t* timeouts);
typedef struct {
uint32_t IP, PS, SO, OS, SP, PI, BI, IB;
} ec_esm_timeouts_t;

EsmProbeSlaveWaitFlags()​

int EsmProbeSlaveWaitFlags(uint16_t master_index, uint16_t slave_index);

Read-only verdict of the single-slave ESM wait policy: it tells the caller whether this slave is still "worth waiting for" at this moment. It does not change state, does not change WKC and does not mask faults.

Return value:

  • 1 (bit0) — demote-grace candidate: the AL Status Code is 0x001F, or the slave reached SAFE_OP cleanly with no Error, so it is worth waiting a while longer
  • 2 (bit1) — hard error: slave drop / no response, or the Error bit is set with an AL code other than 0 / 0x001F; fail truthfully right away instead of waiting out the full grace period
  • 0 — normal
  • -1 — SDK not ready (an out-of-domain value, distinguishable from 0/1/2/3)

The authoritative decision lives in the runtime; the SDK passes it through unchanged and does not fold it a second time.

Example:

int flags = EsmProbeSlaveWaitFlags(master, 1);
if (flags & 0x2)
printf("从站1 硬错误, 立即失败\n"); /* Slave 1 hard error, failing immediately */
else if (flags & 0x1)
printf("从站1 是 demote-grace 候选, 可继续等待\n"); /* Slave 1 is a demote-grace candidate, waiting can continue */
BOOL GetSlaveHasEsi(uint16_t master, uint16_t slave);
BOOL SetSlaveEsiFile(uint16_t master, uint16_t slave, const char* name);
BOOL GetSlaveEsiVersion(uint16_t master, uint16_t slave, char* buf, int buf_size);
BOOL GetSlaveHasMDP(uint16_t master, uint16_t slave);
BOOL GetSlaveVendorName(uint16_t master, uint16_t slave, char* buf, int buf_size);
The criterion for GetSlaveHasEsi

The criterion is that a VendorId was read from SII (the identity is readable), not that "an ESI Device is bound". To confirm the ESI binding or whether the identity is usable, call esi_dll_bind_to_slave() / esi_dll_auto_match_all() (utils/esi_ext.h) and query the binding result; relying on GetSlaveHasEsi() alone mistakes "never bound to an ESI" for "there is ESI truth to compare against".

Startup parameters​

int AddStartupParameter(uint16_t master_index, uint16_t slave_index,
const ec_startup_param_t* param);
int AddStartupParameterBatch(uint16_t master_index, uint16_t slave_index,
const ec_startup_param_t* params, int count);
int ClearStartupParameters(uint16_t master_index, uint16_t slave_index);
int GetStartupParameterCount(uint16_t master_index, uint16_t slave_index);
int ApplyStartupParameters(uint16_t master_index, uint16_t slave_index,
uint8_t transition, uint8_t timing);
int ApplyStartupParametersAll(uint16_t master_index, uint8_t transition, uint8_t timing);
typedef struct {
uint16_t index; /* SDO index */
uint8_t sub_index; /* SDO subindex */
uint8_t data[EC_STARTUP_PARAM_MAX_DATA]; /* parameter data */
uint16_t data_len; /* data length (bytes) */
uint8_t transition; /* transition identifier (EC_TRANS_*) */
uint8_t timing; /* execution timing (EC_TIMING_*) */
uint16_t priority; /* execution priority (smaller number runs first) */
uint8_t complete_access; /* complete access flag (CA=1 writes the whole index) */
uint8_t is_register_write; /* 1=register write, 0=SDO write */
} ec_startup_param_t;

State transition identifiers:

ConstantValueDescription
EC_TRANS_IP0Init → PreOp
EC_TRANS_PS1PreOp → SafeOp
EC_TRANS_SO2SafeOp → OP
EC_TRANS_OS3OP → SafeOp
EC_TRANS_SP4SafeOp → PreOp
EC_TRANS_PI5PreOp → Init

Execution timing:

ConstantValueDescription
EC_TIMING_BEFORE0Executed before the transition
EC_TIMING_AFTER1Executed after the transition

Configuration source declaration (SetConfigSource / GetConfigSource / IsAutoStartupExecuted)​

typedef enum ec_config_source_t {
EC_CONFIG_SOURCE_UNKNOWN = 0, /* not declared (the default; cannot be written explicitly) */
EC_CONFIG_SOURCE_ENI = 1, /* configuration came from an ENI (standard ETG.2100 network configuration XML) */
EC_CONFIG_SOURCE_DENI = 2 /* configuration came from a DENI (Darra extended network configuration, a superset of ENI) */
} ec_config_source_t;

int SetConfigSource(uint16_t master_index, uint16_t slave_index,
ec_config_source_t source);
ec_config_source_t GetConfigSource(uint16_t master_index, uint16_t slave_index);
int IsAutoStartupExecuted(uint16_t master_index, uint16_t slave_index);

Declares which network configuration file this slave's startup parameters / PDO configuration came from. Declaration only: it loads no file, reads or writes no slave and issues no bus operation — actually loading the configuration still goes through SetENI + Build.

CategoryFunctionReturn typeRead/writeDescription
Configuration sourceSetConfigSource(mi, si, source)intwrite-only1 = registered; 0 = invalid argument (UNKNOWN / out-of-range value / index out of range), not registered
GetConfigSource(mi, si)ec_config_source_tread-onlyThe most recently declared value; never declared / index out of range = EC_CONFIG_SOURCE_UNKNOWN
IsAutoStartupExecuted(mi, si)intread-only1 = automatic configuration already executed; 0 = not executed / index out of range

Parameters:

  • master_index (uint16_t) — master index, valid range 1..4
  • slave_index (uint16_t) — slave index, valid range 1..EC_MAXSLAVE-1
  • source (ec_config_source_t) — may only be declared as EC_CONFIG_SOURCE_ENI or EC_CONFIG_SOURCE_DENI

Semantics:

  • A later write overwrites an earlier one — it may be called repeatedly and supports switching ENI ↔ DENI; GetConfigSource() always returns the most recent declaration.
  • UNKNOWN cannot be written — "not declared" is the default, and writing it explicitly would fabricate a source, so it is rejected with 0.
  • A successful registration also sets "automatic configuration executed" — SetConfigSource sets that flag to 1 as it registers, so IsAutoStartupExecuted() reads 1 right away. The flag is the cross-language declaration state (declaring a source means this slave's configuration is in place). The C SDK has no AutoStartup executor today, so whether to skip automatic configuration is the caller's decision; this interface does not change any loading behavior.
The SDK does not record the ENI/DENI source per slave

This is SDK-side declaration state, not a value read back from the device. The SDK records only two things per slave: explicit_replace (explicit plan) and esi_installed (merged ESI defaults); there is no ENI/DENI source field — this group of functions reads back the SDK's own in-process registry, so do not use it to check the device's actual state.

Link requirement

This group is implemented in the advanced static library: using it requires linking darra-ethercat-advanced.lib (the same group as darra_ethercat.lib and mxml4.lib, see the link notes at the top of ethercat.h). The enum values 0/1/2 match the managed ConfigSource and the C++ ConfigSource value for value.

Example:

/* Declare that slave 1's configuration comes from a DENI */
if (!SetConfigSource(master, 1, EC_CONFIG_SOURCE_DENI))
printf("声明失败 —— 入参非法(UNKNOWN 是未声明的默认值,不能显式写入)\n"); /* Declaration failed — invalid argument (UNKNOWN is the undeclared default value and cannot be written explicitly) */

if (GetConfigSource(master, 1) == EC_CONFIG_SOURCE_DENI)
printf("从站 1 的配置来源 = DENI, 自动配置已执行 = %d\n", /* Slave 1 configuration source = DENI, automatic configuration executed = %d */
IsAutoStartupExecuted(master, 1));

Redundancy status​

BOOL GetSlaveRedundancyActivated(uint16_t master, uint16_t slave);
BOOL GetSlavePrimaryLinkBroken(uint16_t master, uint16_t slave);
BOOL GetSlaveSecondaryLinkBroken(uint16_t master, uint16_t slave);

Live-read values and the four trust states (ec_live_read_t)​

GetSlaveStateLiveRead() / GetSlaveALStatusCodeLiveRead() really send one frame (they do not read the diagnostics cache) and return ec_live_read_t: the raw value plus an evidence level. Only a value that passes EcLiveRead_IsValid(&read) (that is, validity == EC_LIVE_READ_VALID) may be used as the current value; the other three states must never be taken as "this is how it is right now".

typedef enum {
EC_LIVE_READ_UNKNOWN = 0, /* no usable read (value is meaningless) */
EC_LIVE_READ_VALID = 1, /* measured and usable as the current value */
EC_LIVE_READ_STALE = 2, /* a value exists, but it is confirmed not current */
EC_LIVE_READ_DEGRADED = 3 /* a value exists, but the evidence is incomplete */
} ec_live_read_validity_t;

typedef struct {
uint16_t value; /* lossless 16-bit raw value */
ec_live_read_validity_t validity; /* validity */
} ec_live_read_t;
ValueMeaningUsable as the current value
EC_LIVE_READ_UNKNOWN(0)No usable read (shim not loaded / entry point missing / invalid handle)No. Unknown != normal
EC_LIVE_READ_VALID(1)This measurement produced a result usable as the current valueYes
EC_LIVE_READ_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
EC_LIVE_READ_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.

Live AL code criteria:

VerdictTriggervalue
EC_LIVE_READ_UNKNOWNThe call failed, or it returned 0xFFFF (the unavailable sentinel)0xFFFF
EC_LIVE_READ_DEGRADEDThe liveness state / probe entry point is unavailableRaw code
EC_LIVE_READ_STALEGetSlaveIsLost() is true, or the probe confirms no responseRaw code (residual)
EC_LIVE_READ_DEGRADEDProbe evidence is insufficient (unknown)Raw code
EC_LIVE_READ_VALIDGetSlaveIsLost() is false and the probe confirms the slave is onlineRaw code
A lost slave is not "no error"

The lower layer DarraEcat_GetSlaveALStatusCodeLive() returns 0 for a lost / non-responding slave; that 0 is the "no data" placeholder, not "no error". Code that looks only at this return value reports a lost slave as healthy; GetSlaveALStatusCodeLiveRead() uses the liveness state and probe evidence to file it as EC_LIVE_READ_STALE. Never read 0 as "the device confirmed no fault".

Example:

ec_live_read_t st = GetSlaveStateLiveRead(0, 1);
if (EcLiveRead_IsValid(&st))
printf("从站 1 当前状态 0x%02X\n", st.value); /* Slave 1 current state 0x%02X */
else
printf("从站 1 状态不可信 (validity=%d)\n", st.validity); /* Slave 1 state cannot be trusted (validity=%d) */

ec_live_read_t al = GetSlaveALStatusCodeLiveRead(0, 1);
if (EcLiveRead_IsValid(&al))
printf("从站 1 当前 AL 码 0x%04X\n", al.value); /* Slave 1 current AL code 0x%04X */
else
printf("从站 1 AL 码不可信 (validity=%d)\n", al.validity); /* STALE is common after a slave drop; that is not "no error" */

The AL mirror (GetSlaveAlStatusMirror()) carries only the low 8 bits of the code, and codes >= 0x0100 are truncated; for the full 16-bit code always use GetSlaveALStatusCode() or the lossless entry points in this section.

Diagnostics mirrors (direct reads)​

The runtime maintains a per-slave diagnostics cache every cycle (immediately on WKC anomalies). The getters below read that cache directly: they send and receive no frames, so what they return is the bus reality at this instant and no refresh is needed. GetSlaveAlStatusMirror() is the exception. 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 a capability is not ready they return a fallback value (0xFF = Unknown / 0), exposed honestly and never fabricated.

/* per-slave direct reads */
uint8_t GetSlaveWcState(uint16_t master, uint16_t slave); /* 1 = contributed / 0 = not contributed / 0xFF = unknown */
uint16_t GetSlaveAlStatusMirror(uint16_t master, uint16_t slave); /* low byte = AL State (including the Error bit); high byte = low 8 bits of the AL Status Code (valid only with the Error bit; codes >= 0x0100 are truncated) */
uint8_t GetSlaveMailboxHealth(uint16_t master, uint16_t slave); /* 0=Unknown, 1=Healthy, 2=Degraded */
uint8_t GetSlaveFreeRunDemoted(uint16_t master, uint16_t slave); /* a value other than 0 = forced to fall back to FreeRun */
uint32_t GetSlaveHealthDegradedCount(uint16_t master, uint16_t slave);/* consecutive cumulative count of mailbox half-failures (roughly seconds) */
BOOL RecoverSlaveMailboxHealth(uint16_t master, uint16_t slave); /* manually trigger mailbox half-failure recovery */

/* master-level WKC mirror direct reads (aggregate view of the per-slave contribution bits) */
uint16_t GetWcDeficit(uint16_t master); /* expected - actual (read-only diagnostics, never change expected based on it) */
uint16_t GetWkcActualMirror(uint16_t master); /* measured WKC (the bus value at this instant) */
uint16_t GetWkcExpectedMirror(uint16_t master); /* expected WKC (fixed at configuration time, conceptually immutable) */

Example:

uint16_t s = 1;
if (GetSlaveWcState(master, s) == 0) { /* 0 = NotContributed */
uint16_t al = GetSlaveAlStatusMirror(master, s);
if ((al & EC_STATE_ERROR) != 0) { /* bit4 = Error bit (EC_STATE_ERROR); only then is the high byte the low 8 bits of the AL Code */
uint8_t code = (uint8_t)((al >> 8) & 0xFF);
if (code != 0)
printf("从站 %u 此刻未贡献 WKC(疑似掉站),AL Code=0x%02X\n", s, code); /* Slave %u contributes no WKC right now (suspected slave loss), AL Code=0x%02X */
else
printf("从站 %u 未贡献 WKC, Error 位已置位但镜像里没有有效 AL Code\n", s); /* Slave %u contributes no WKC, the Error bit is set but the mirror holds no valid AL Code */
} else {
printf("从站 %u 此刻未贡献 WKC(疑似掉站),AL State=0x%02X(无 Error 位, 无 AL Code)\n", /* Slave %u contributes no WKC right now (suspected slave loss), AL State=0x%02X (no Error bit, no AL Code) */
s, al & 0xFF);
}
}
if (GetSlaveMailboxHealth(master, s) == 2) /* 2 = Degraded */
printf("从站 %u 在 OP 但邮箱半失效, 已持续 %us\n", s, GetSlaveHealthDegradedCount(master, s)); /* Slave %u is in OP but the mailbox is partially failing, for %us */

Topology​

int      GetTopology(uint16_t master, ec_topology_node_t* out, int max);
int TopologyBuild(uint16_t master_index, ec_topology_node_t* out_nodes, int max_nodes);
int TopologyGetChildren(uint16_t master_index, uint16_t parent_index,
uint16_t* out_children, int max_children);
int TopologyGetRoots(uint16_t master_index, uint16_t* out_roots, int max_roots);
uint8_t GetSlaveActivePorts(uint16_t master, uint16_t slave);
uint16_t GetSlaveParent(uint16_t master, uint16_t slave);
typedef struct {
uint16_t slave_index;
uint16_t config_addr;
uint16_t parent_index;
uint8_t entry_port;
uint8_t active_ports;
uint8_t topology;
uint8_t port_type;
} ec_topology_node_t;

ESC register access (advanced)​

Read and write slave ESC (EtherCAT Slave Controller) registers directly, for fault diagnostics, custom ESC operations and low-level debugging. The protocol layer uses FPRD/FPWR datagrams with an automatic three-step fallback primary → secondary → APWR.

Advanced API

Nothing in normal SDK use needs these calls — the SDK already configures the registers for state transitions, PDO, mailbox and similar flows. This API is for in-depth diagnostics and special cases (for example reading error counters, forcing a port policy, or debugging an ESI flash that did not take effect).

Register definitions are in ETG.1000.4 §6 / ETG.1000.6 §5 (public standards), for example:

RegisterDescription
0x0000Type / Revision / Build (device type)
0x0030AL Control (the master issues a state request)
0x0130AL Status (current slave state)
0x0134AL Status Code (error code)
0x0300-0x030FPort 0-3 error counters
0x0400-0x043FWatchdog configuration/counters
0x0440-0x0443SM watchdog status / overflow counters: 0x0440 bit0 (0 = overflowed/expired, 1 = healthy or not enabled; 0xFF = read failed/unknown); writing 0 to 0x0442/0x0443 resets them, reading does not clear them

ReadSlaveRegister()​

BOOL ReadSlaveRegister(uint16_t master_index, uint16_t slave_index,
uint16_t reg_addr, uint8_t* data, uint32_t len);

Reads a slave ESC register (FPRD).

Parameters:

  • master_index (uint16_t) — master index
  • slave_index (uint16_t) — slave index (1-based)
  • reg_addr (uint16_t) — register address
  • data (uint8_t*) — [out] receive buffer (at least len bytes)
  • len (uint32_t) — number of bytes to read (1/2/4 etc.)

Return value:

  • BOOL — TRUE on success

WriteSlaveRegister()​

BOOL WriteSlaveRegister(uint16_t master_index, uint16_t slave_index,
uint16_t reg_addr, uint8_t* data, uint32_t len);

Writes a slave ESC register (FPWR).

Parameters:

  • master_index (uint16_t) — master index
  • slave_index (uint16_t) — slave index (1-based)
  • reg_addr (uint16_t) — register address
  • data (uint8_t*) — data to write
  • len (uint32_t) — number of bytes

Return value:

  • BOOL — TRUE on success

Example:

/* read AL Status (0x0130, 2 bytes) */
uint8_t al_status[2] = {0};
if (ReadSlaveRegister(master, 1, 0x0130, al_status, 2)) {
uint16_t state = al_status[0] | (al_status[1] << 8);
printf("AL Status = 0x%04X (state=%u, err=%s)\n",
state, state & 0x0F, (state & 0x10) ? "yes" : "no");
}

/* read AL Status Code (0x0134, error code) */
uint8_t al_code[2] = {0};
ReadSlaveRegister(master, 1, 0x0134, al_code, 2);
uint16_t code = al_code[0] | (al_code[1] << 8);
printf("AL Status Code = 0x%04X\n", code);

/* write AL Control = 0x04 (request SafeOp) */
uint8_t al_ctrl[2] = { 0x04, 0x00 };
WriteSlaveRegister(master, 1, 0x0030, al_ctrl, 2);

EEPROM (SII) access​

Read and write the slave SII EEPROM (Slave Information Interface). The EEPROM stores device identity information such as vendor_id/product_code/revision_no/serial_no. The SDK already reads it during config_init, so applications normally need no direct access.

Dangerous operation

Use EEPROM writes with care — a wrong write can corrupt the slave identity data and in the worst case brick the slave permanently, requiring vendor tools to recover. Use them only to flash an alias address, to repair factory data that was overwritten by mistake, or for vendor-authorized parameter programming. An EEPROM write requires the slave to be in Init/PreOp.

SIIReadWord()​

int SIIReadWord(uint16_t master_index, uint16_t slave_index,
uint16_t word_addr, uint16_t* out_value);

Reads a single EEPROM word (16-bit).

Parameters:

  • master_index / slave_index (uint16_t) — master index / slave index (1-based)
  • word_addr (uint16_t) — EEPROM word address
  • out_value (uint16_t*) — [out] the 16-bit value read

Return value:

  • int — 1 on success / 0 on failure

SIIWriteWord()​

int SIIWriteWord(uint16_t master_index, uint16_t slave_index,
uint16_t word_addr, uint16_t value);

Writes a single EEPROM word (16-bit).

Parameters:

  • master_index / slave_index (uint16_t) — master index / slave index (1-based)
  • word_addr (uint16_t) — EEPROM word address
  • value (uint16_t) — the 16-bit value to write

Return value:

  • int — 1 on success / 0 on failure

Example:

/* read vendor_id (EEPROM word 0x08, 0x09 — 32-bit) */
uint16_t vid_lo = 0, vid_hi = 0;
SIIReadWord(master, 1, 0x08, &vid_lo);
SIIReadWord(master, 1, 0x09, &vid_hi);
uint32_t vendor_id = ((uint32_t)vid_hi << 16) | vid_lo;
printf("VendorID = 0x%08X\n", vendor_id);

/* write the alias section (EEPROM word 0x04/0x05; Init/PreOp required; word-by-word writes are enough) */
SIIWriteWord(master, 1, 0x04, 0x0001);
SIIWriteWord(master, 1, 0x05, 0x0000);
Recommended approach

For the common identity fields use GetSlaveVendorId() / GetSlaveProductCode() / GetSlaveRevision() directly; the SDK already caches them from the EEPROM. For the serial number use TryGetSlaveSerialNumber() — GetSlaveSerialNumber() is a runtime snapshot, where 0 means neither a real 0 nor a read failure.

SiiTryFindCategory() / SiiTryReadCategory() / SiiTryGetGeneralInfo()​

typedef enum ec_sii_read_status_t {
EC_SII_READ_OK = 0, /* a real value was read */
EC_SII_READ_NOT_FOUND = 1, /* the chain is readable and the category truly does not exist (a normal result, not an error) */
EC_SII_READ_FAILED = 2 /* the SII cannot be read; must not be treated as "absent" */
} ec_sii_read_status_t;

ec_sii_read_status_t SiiTryFindCategory(uint16_t master, uint16_t slave, uint16_t cat_type,
uint32_t* out_byte_offset, uint32_t* out_byte_size);
ec_sii_read_status_t SiiTryReadCategory(uint16_t master, uint16_t slave, uint16_t cat_type,
uint8_t* buffer, uint32_t buffer_size,
uint32_t* out_actual);
ec_sii_read_status_t SiiTryGetGeneralInfo(uint16_t master, uint16_t slave,
ec_sii_general_info_t* out_info);

An SII read has three outcomes that must be kept clearly apart: a real value was read / the category truly does not exist on the chain (a normal result) / the read failed (which must not be treated as "absent"). The raw entry points DarraEcat_SIIFindCategory() / DarraEcat_SIIReadCategory() / DarraEcat_SIIGetGeneralInfo() only have a binary outlet (1 = success / 0 = failure), where on failure "absent" and "unreadable" look the same; these three SiiTry* functions are tri-state wrappers over the same underlying entry points: they add no exports and do not change the ABI.

Return value (tri-state, with fixed criteria):

Return valueMeaningWhat the caller should do
EC_SII_READ_OKA real value was readUse the out parameters; a length of 0 is a valid empty category
EC_SII_READ_NOT_FOUNDThe chain is readable and the category truly does not existA normal branch (for example the device does not provide the DC category), not an error
EC_SII_READ_FAILEDThe SII cannot be read / locating or reading the length word failedHandle it as a failure and report it; must not be treated as "absent"

Attribution rules for a failed locate (shared by all three entry points):

  1. DarraEcat_SIIEnumerateCategories() returns < 0 (not even the SII context can be obtained) → EC_SII_READ_FAILED;
  2. The category is present in the enumeration result, but locating it fails → EC_SII_READ_FAILED (on the chain it is not "absent");
  3. The enumeration succeeds (>= 0) and does not contain the category → EC_SII_READ_NOT_FOUND.
Residual boundary of the attribution

If the chain walk itself breaks before reaching the target category (zero-length section / hop limit), the target category lands on the "not enumerated" side and is reported as EC_SII_READ_NOT_FOUND. The SDK cannot obtain that information, so the two cases cannot be distinguished.

Parameters and out parameters:

  • master / slave (uint16_t) — master / slave index, 1-based
  • cat_type (uint16_t) — SII Category type number, see ec_sii_category_t (10 / 20 / 30 / 40 / 41 / 50 / 51 / 60 / 62)
  • out_byte_offset / out_byte_size (uint32_t*) — may be NULL; set to 0 when the result is not EC_SII_READ_OK
  • out_actual (uint32_t*) — may be NULL; on success the number of bytes actually read, set to 0 on failure
  • out_info (ec_sii_general_info_t*) — must not be NULL; passing NULL returns EC_SII_READ_FAILED directly (no read is issued), and the whole block is zeroed on failure

Semantics of each entry:

  • SiiTryFindCategory — locates only, does not read data; a length of 0 is a valid empty category.
  • SiiTryReadCategory — locates first by the rules above and returns that status directly when it is not OK (no data is read); locating succeeded and the length is 0 → OK with *out_actual = 0; otherwise it reads min(buffer_size, 分类长度) bytes, and a failed read → EC_SII_READ_FAILED. When buffer_size is smaller than the category length only the first buffer_size bytes are read (still OK, and *out_actual gives the actual byte count); when buffer_size = 0 and the category is not empty, not a single byte is read and it returns OK with *out_actual = 0 — supply a large enough buffer to get data, and use SiiTryFindCategory when you only want the length.
  • SiiTryGetGeneralInfo — parses the General Category (type 30). On a failed read, only "the chain truly has no GENERAL" is reported as EC_SII_READ_NOT_FOUND; everything else (unreadable / data not fully read) is always EC_SII_READ_FAILED.

Legacy binary outlets: DarraEcat_SIIFindCategory() / DarraEcat_SIIReadCategory() / DarraEcat_SIIGetGeneralInfo() keep their original behaviour, 1 on success / 0 on failure; on failure they cannot tell "the category does not exist" from "the read failed". Use SiiTry* when that distinction is needed.

Example:

uint32_t off = 0, size = 0;
ec_sii_read_status_t st = SiiTryFindCategory(m, 1, (uint16_t)EC_SII_CAT_GENERAL, &off, &size);

if (st == EC_SII_READ_OK)
printf("General 分类: 偏移 %u, 长度 %u 字节\n", off, size); /* General category: offset %u, length %u bytes */
else if (st == EC_SII_READ_NOT_FOUND)
printf("该从站没有 General 分类(SII 可读,正常结果)\n"); /* This slave has no General category (SII is readable, normal result) */
else
printf("SII 读不出来 —— 不能当成「没有 General 分类」\n"); /* SII cannot be read — this does not mean "no General category" */

SiiTryReadIdentity() / SiiTryReadSerialNumber()​

typedef struct ec_sii_identity_t {
uint32_t vendor_id; /* word 0x0008 low word / 0x0009 high word */
uint32_t product_code; /* word 0x000A low word / 0x000B high word */
uint32_t revision_no; /* word 0x000C low word / 0x000D high word */
uint32_t serial_no; /* word 0x000E low word / 0x000F high word */
} ec_sii_identity_t;

ec_sii_read_status_t SiiTryReadIdentity(uint16_t master, uint16_t slave,
ec_sii_identity_t* out_identity);
ec_sii_read_status_t SiiTryReadSerialNumber(uint16_t master, uint16_t slave,
uint32_t* out_serial);

Direct reads of the identity area (ETG.1000.6 word 0x0008..0x000F). Each entry occupies two consecutive words, and the 32-bit value is assembled with the low word first: value = (uint32_t)low | ((uint32_t)high << 16).

The identity area always exists in the EEPROM, so there are only two outcomes — success / read failure — and no EC_SII_READ_NOT_FOUND:

Return valueMeaning
EC_SII_READ_OKThe identity area is complete and the out parameters hold the EEPROM real values (any entry may be 0 — 0 can be a value the device declares)
EC_SII_READ_FAILEDA word did not come back (incomplete identity area) / the out parameter is NULL

Parameters and out parameters:

  • master / slave (uint16_t) — master / slave index, 1-based
  • out_identity (ec_sii_identity_t*) — must not be NULL; on success all four fields are filled, on failure the whole block is zeroed (no stale values from a previous call are left behind)
  • out_serial (uint32_t*) — must not be NULL; on EC_SII_READ_OK it is the device-declared real value (may be 0), on EC_SII_READ_FAILED it is set to 0 (unknown, not equal to 「the device serial number is 0」)

Semantics:

  • No half identity is handed out — if any word does not come back, SiiTryReadIdentity reports EC_SII_READ_FAILED as a whole and the out parameter is zeroed; "unreadable" is never folded into 0 (0 may be a value the device declares).
  • Reads the EEPROM directly — it is not affected by the cold-configuration trade-off that skips the SER word on slaves that matched an ESI; GetSlaveSerialNumber() reads the runtime snapshot, which stays 0 for those slaves.
  • Every call really touches the bus — SiiTryReadIdentity reads 8 words and SiiTryReadSerialNumber reads 2; cache the values yourself if you need them frequently.

Example:

ec_sii_identity_t id;
if (SiiTryReadIdentity(master, 1, &id) == EC_SII_READ_OK)
printf("V=0x%08X P=0x%08X R=0x%08X SN=%u\n",
id.vendor_id, id.product_code, id.revision_no, id.serial_no);
else
printf("身份区读不全 —— 不交付半份身份, 也不能当成序列号 0\n"); /* Identity area could not be read completely — a half identity is never delivered, and it must not be taken as serial number 0 */

uint32_t serial = 0;
if (SiiTryReadSerialNumber(master, 1, &serial) == EC_SII_READ_OK)
printf("序列号 = %u(0 也是合法真值)\n", serial); /* Serial number = %u (0 is also a valid true value) */

DL Port control​

Read and write the ESC DL Port Control register (0x0101) directly, for port fault injection tests and manual diagnostics of redundant / ring topologies.

Advanced API

Ordinary applications must not use this API — it force-disables a physical port and affects topological routing. Use it only for redundancy verification, cable-fault reproduction and diagnostic scripts.

The ESC has 4 physical ports P0 / P1 / P2 / P3. The values of the DL Port Control register are defined as follows:

DLPORT valueBehavior
0x00Auto — all ports managed automatically by the ESC (default)
0x03Disable P0 (inject a fault)
0x0CDisable P1
0x30Disable P2
0xC0Disable P3

The SDK automatically uses the three-step write fallback primary → secondary → APWR, so even after P0 is disabled the port can be restored through the secondary port / broadcast.

WriteSlaveDLPORT()​

BOOL WriteSlaveDLPORT(uint16_t master_index, uint16_t slave_index, uint8_t dlport_value);

Writes the slave DL Port Control register (0x0101).

Parameters:

  • master_index (uint16_t) — master index
  • slave_index (uint16_t) — slave index (1-based)
  • dlport_value (uint8_t) — DLPORT value (see the table above)

Return value:

  • BOOL — TRUE on success

ReadSlaveDLPORT()​

BOOL ReadSlaveDLPORT(uint16_t master_index, uint16_t slave_index, uint8_t* dlport_value);

Reads the current value of the slave DL Port Control register.

Parameters:

  • master_index (uint16_t) — master index
  • slave_index (uint16_t) — slave index (1-based)
  • dlport_value (uint8_t*) — [out] current DLPORT value

Return value:

  • BOOL — TRUE on success

Example:

/* simulate a P1 port fault (test redundancy switching) */
BOOL ok = WriteSlaveDLPORT(master, 1, 0x0C);
printf("关闭从站 1 的 P1: %s\n", ok ? "成功" : "失败"); /* Closing P1 of slave 1: %s (success / failure) */

/* read back to confirm */
uint8_t dlport = 0;
ReadSlaveDLPORT(master, 1, &dlport);
printf("当前 DLPORT = 0x%02X\n", dlport); /* Current DLPORT = 0x%02X */

/* restore after the fault is cleared */
WriteSlaveDLPORT(master, 1, 0x00); /* restore Auto */

SII categories / string parsing​

The EEPROM data read with SIIReadWord can be processed directly with the public parsing functions in protocol_codes.h for categories, strings and device metadata. This corresponds to ETG.1000.6 §6 + ETG.2010 SII Category. This section works on a whole byte image that has already been read; to locate / read a Category from the slave at run time, use SiiTryFindCategory / SiiTryReadCategory / SiiTryGetGeneralInfo from the previous section.

const char* EcSii_GetCategoryName(ec_sii_category_t cat);
int EcSii_FindCategory(const uint8_t* sii_data, int sii_size,
uint16_t cat_type, int* out_size_bytes);
int EcSii_EnumerateCategories(const uint8_t* sii_data, int sii_size,
uint16_t* cat_types, int capacity);
int EcSii_ParseGeneral(const uint8_t* cat_data, int cat_size,
ec_sii_general_t* out);
int EcSii_GetStringByIndex(const uint8_t* cat_data, int cat_size,
int idx, char* out_buf, int buf_size);
int EcSii_GetStringCount(const uint8_t* cat_data, int cat_size);
uint32_t EcSii_GetVendorId(const uint8_t* sii_data, int sii_size);
uint32_t EcSii_GetProductCode(const uint8_t* sii_data, int sii_size);

Category access — Category Type is the ec_sii_category_t enum (10=Strings / 20=DataTypes / 30=General / 40=FMMU / 41=SyncManager / 50=TxPDO / 51=RxPDO / 60=DC / 62=Cyclic / ≥0x1000=Vendor / 0xFFFF=End). EcSii_FindCategory() returns the start offset of the data, EcSii_EnumerateCategories() lists all category types, and EcSii_ParseGeneral() parses the device metadata of the General category.

String parsing — EcSii_GetStringByIndex() fetches the N-th entry (1-based) of the Strings category directly (matching the GroupName / Name / ImageName / OrderName indexes in General), and EcSii_GetStringCount() returns the total number of strings.

Example:

#define SII_BUFFER_SIZE 4096   /* adjust to the SII area size of the target slave */

/* read the EEPROM word by word with SIIReadWord and assemble a full byte image (1 word = 2 bytes,
* low byte first; word_addr is a word address). The parsing functions locate the category area in the
* full image (starting at byte offset 128); returns the bytes read, stopping when a word read fails,
* and never pretends the read was complete. */
static int read_sii_bytes(uint16_t master, uint16_t slave, uint8_t* out, int max_bytes)
{
int n = 0;
for (int w = 0; w < max_bytes / 2; w++) {
uint16_t v;
if (SIIReadWord(master, slave, (uint16_t)w, &v) != 1) break; /* SIIReadWord: 1 = success, 0 = failure */
out[n++] = (uint8_t)(v & 0xFF);
out[n++] = (uint8_t)(v >> 8);
}
return n;
}

uint8_t sii[SII_BUFFER_SIZE];
int sii_size = read_sii_bytes(master, 1, sii, sizeof(sii));

uint16_t cats[32];
int n = EcSii_EnumerateCategories(sii, sii_size, cats, 32);
for (int i = 0; i < n; i++) {
printf("Category %u (%s)\n", cats[i], EcSii_GetCategoryName(cats[i]));
}

int cat_size = 0;
int off = EcSii_FindCategory(sii, sii_size, 30 /* General */, &cat_size);
if (off >= 0) {
ec_sii_general_t info;
if (EcSii_ParseGeneral(sii + off, cat_size, &info)) {
printf("CoE 详情=0x%02X, FoE 详情=0x%02X\n", /* CoE detail=0x%02X, FoE detail=0x%02X */
info.coe_details, info.foe_details);
}
}
Writing categories

SIIWriteWord currently supports only single-word writes and does not provide whole-category writes. Writing a category requires re-linking the list and recomputing checksums, which easily damages the device; for whole-category changes use the vendor programming tool or reflash the ESI.

Slave substructure access (direct field reads)​

The C SDK splits each slave subdomain (topology / DC / mailbox / metadata / identity / runtime / SM-FMMU / capability / redundancy) into separate GetSlave* functions of the form GetSlaveTopologyType(master_index, slave_index) that return the corresponding slave field directly. This style makes flat bindings for other languages straightforward.

The table below maps fields grouped by slave subdomain. Every function has the full signature GetSlave*(uint16_t master_index, uint16_t slave_index); the return types are in the Properties table above.

Category (slave subdomain)C SDK direct-read functionsRead/write
TopologyGetSlaveTopologyType / GetSlaveActivePorts / GetSlaveConsumedPorts / GetSlaveEntryPort / GetSlaveParent / GetSlaveParentPort / GetSlaveParentStation / GetSlavePhysicalType (note: GetSlaveParentStation is really a 1-based slave index, not a station address; 0 means the parent is the master)read-only
DCGetSlaveHasDC / GetSlaveDCActive / GetSlaveDCCycle0 / GetSlaveDCCycle1 / GetSlaveDCShift / GetSlaveDCNext / GetSlaveDCPrevious / GetSlaveDCParentPort / GetSlaveDCReceiveTimeA/B/C/D / GetSlavePDelayread-only
MailboxGetSlaveMailboxProto / GetSlaveMailboxWriteLength / GetSlaveMailboxWriteOffset / GetSlaveMailboxReadLength / GetSlaveMailboxReadOffset / GetSlaveMbxCountread-only
Metadata (SII cache)GetSlaveBlockLRW / GetSlaveEep8Byte / GetSlaveEepPDI / GetSlaveEbusCurrent / GetSlaveCoEDetails / GetSlaveFoEDetails / GetSlaveEoEDetails / GetSlaveSoEDetails / GetSlaveHasMDP / GetSlaveHasEsi / GetSlaveEsiVersion / GetSlaveVendorNameread-only
IdentityGetSlaveVendorId / GetSlaveProductCode / GetSlaveRevision / GetSlaveSerialNumber / GetSlaveConfigAddr / GetSlaveAliasAddr / GetSlaveName / GetSlaveDeviceName / GetSlaveIdentity (struct output)read-only
RuntimeGetSlaveState / GetSlaveALStatusCode / GetSlaveIsLost / GetSlaveOpOnlyFlag / GetSlaveDeviceEmulationFlag / GetSlaveGroup / GetSlaveOptional / GetSlaveSupportsFrameRepeatread-only (Group / Optional / SupportsFrameRepeat also have Set writers)
SM-FMMUGetSlaveFMMU0Function / GetSlaveFMMU1Function / GetSlaveFMMU2Function / GetSlaveFMMU3Function (FMMU function bits)read-only
CapabilityDerived by combining GetSlaveCoEDetails / GetSlaveFoEDetails / GetSlaveEoEDetails / GetSlaveSoEDetails / GetSlaveHasDC / GetSlaveHasMDP / GetSlaveMailboxProtoread-only
RedundancyGetSlaveRedundancyActivated / GetSlavePrimaryLinkBroken / GetSlaveSecondaryLinkBrokenread-only
Diagnostics mirror (direct per-slave reads)GetSlaveWcState / GetSlaveAlStatusMirror / GetSlaveMailboxHealth / GetSlaveFreeRunDemoted / GetSlaveHealthDegradedCount / RecoverSlaveMailboxHealthread-only (RecoverSlaveMailboxHealth is write-only)
Advanced: taking the slave structure pointer directly

GetSlave(master_index, slave_index) returns an opaque pointer void* to the internal slave structure; after casting you can read all fields at once instead of calling field by field. This is intended for SDK developers only; the field layout may change between versions, so application code should use the named functions above.

Example:

/* get the runtime, topology and DC state of slave 1 in one go */
uint16_t s = 1;
printf("从站 %u: state=0x%02X, AL=0x%04X, IsLost=%d\n", /* Slave %u: state=0x%02X, AL=0x%04X, IsLost=%d */
s, GetSlaveState(master, s),
GetSlaveALStatusCode(master, s),
GetSlaveIsLost(master, s));

printf("拓扑: parent=%u port=%d, entry=%u, ports=0x%X\n", /* Topology: parent=%u port=%d, entry=%u, ports=0x%X */
GetSlaveParent(master, s),
GetSlaveParentPort(master, s),
GetSlaveEntryPort(master, s),
GetSlaveActivePorts(master, s));

if (GetSlaveHasDC(master, s)) {
printf("DC: Cycle0=%d ns, Shift=%d ns, PDelay=%d ns\n",
GetSlaveDCCycle0(master, s),
GetSlaveDCShift(master, s),
GetSlavePDelay(master, s));
}

ESI and ENI configuration​

The full capability description and examples are on ESI/ENI configuration capabilities.

CategoryFunctionReturn typeRead/writeDescription
Convenience queriesslave_has_esiboolread-onlyWhether the SII read a VendorId (the identity is readable); this does not mean an ESI Device is bound
slave_set_esi_fileboolwrite-onlySets the ESI file path for this slave
slave_get_esi_versionboolread-onlyFetches the ESI version string into a caller buffer
File deep readsEcEsi_MatchDeviceintread-only1 = match / 0 = no match / negative = parameter or file error; when strict is a value other than 0, RevisionNo is compared strictly against the policy string
EcEsi_MatchRevisionintread-only1 = match / 0 = no match; the policy string is case-insensitive, and it is always true when expected is 0 or NONE
EcEsi_GetDeviceEepromintread-onlyReads the device's EEPROM configuration data from the file
EcEsi_GetDeviceBootstrapintread-onlyReads the receive / send offsets and sizes of the Bootstrap mailbox
EcEsi_GetDeviceElectricalintread-onlyReads the EBus current (mA, may be negative for a supplying device)
EcEsi_GetDevicePortInfointread-onlyReads the type and label string of the given physical port
EcEsi_GetDevicePdoDetailintread-onlyReads the PDO index / name / Fixed·Mandatory / SM / entry table
EcEsi_GetDeviceCoEDetailsintread-onlyReads the CoE capability flags (SDO Info / PDO Assign / PDO Config / CompleteAccess / SegmentedSDO / DiagHistory / PdoUpload); out_pdo_upload is tri-state: 1 = the ESI declares SDO read-back of the PDO assignment / mapping, 0 = explicitly declared unsupported (the master must not treat an empty read-back as evidence that the configuration is missing), -1 = not declared (unknown, treated as readable for compatibility)
EcEsi_GetDeviceDcOpModeintread-onlyReads the DC operation mode (AssignActivate + Cycle / Shift and their factors)
EcEsi_GetBoundSlaveCoEDetailsintread-onlyReads the CoE capability flags for a bound slave — same shape as EcEsi_GetDeviceCoEDetails (same 7 out params, out_diag_history / out_pdo_upload tri-state); only the way the ESI Device is located differs: this entry uses the same binding the master used at configuration / startup. Returns 0 = success, -1 = bad parameters, -2 = the slave has no bound ESI Device, -3 = the bound Device has no <CoE>; any value other than 0 means unknown, and all 7 out params are then written as -1
EcEsi_GetDeviceSmDetailintread-onlyReads SyncManager details (name / address / size / control byte / Enable / Min·Max)
Startup and DCEcEsi_GetDeviceIdentityintread-onlyFetches Vendor / Product / Revision / name; non-negative on success (the value is the name byte count, 0 when there is no name), negative on failure
EcEsi_GetDeviceDcSyncModeintread-onlyDC synchronization grade: 3 = DC-Sync0+SYNC1 / 2 = DC-Sync0 / 1 = SM-Sync / 0 = FreeRun / -1 = no Dc node / -2 = not bound
EcEsi_GetDeviceDcCycleTime0int64_tread-onlySYNC0 cycle declared by the ESI (nanoseconds); 0 = not declared, -2 = not bound, -1 = runtime interface not ready
EcEsi_GetDevicePdoIndicesintread-onlyLists the Device's PDO indexes; -1 = no ESI bound / invalid parameter
EcEsi_GetDevicePdoSizeBitsintread-onlyTotal bit length of the given PDO (including padding); returns -1 when not found
EcEsi_GetDeviceSmInfointread-onlyFetches SyncManager information (sm_idx 0..3); 0 = success, a value other than 0 = failure
EcEsi_GetDeviceMailboxTimeoutintread-onlyMailbox Request / Response timeout (milliseconds); 0 = success
Registry and bindingesi_initintwrite-onlyInstalls the EcEsi_* interface into an esi_ctx_t; 1 = success, 0 = ctx is null
esi_dll_clearvoidwrite-onlyClears the ESI cache
esi_dll_get_loaded_countintread-onlyNumber of loaded files
esi_dll_register_startup_parametersintwrite-onlyRegisters the startup parameters from the ESI for the given slave; returns the number registered successfully, a negative value = failure
esi_dll_has_esi_dc_syncintread-only1 = the ESI declares DC synchronization, 0 = it does not
esi_dll_get_device_dc_sync_modeintread-onlyDC synchronization grade declared by the ESI (raw value); returns -2 for an invalid ctx

The slave_* and slave/startup.h EcEsi_* entry points are called by (master_index, slave_index); the file deep-read entry points in slave/esi.h take the ESI file path as their first argument, do not depend on a master / slave instance and send no bus traffic; device_ordinal starts at 0, and apart from MatchDevice / MatchRevision every entry returns 0 = success and a negative value = failure.

Tri-state semantics of the CoE capability flags (PdoUpload): out_pdo_upload of EcEsi_GetDeviceCoEDetails reports the declaration from the ESI <Mailbox><CoE PdoUpload="..."> attribute — 1 = explicitly declared true, meaning the device supports reading back the PDO assignment / mapping (0x1C12 / 0x1C13 / 0x1600 / 0x1A00) over SDO; 0 = explicitly declared false, meaning the device does not support read-back and the master must not treat an empty read-back as evidence that the configuration was cleared; -1 = the attribute is not declared by the ESI, so the result is unknown and is treated as readable for compatibility (most ESI files omit it, and an undeclared attribute must not be folded into "unsupported"). The other flags in the same group (SDO Info / PDO Assign / PDO Config / CompleteAccess / SegmentedSDO / DiagHistory) are two-state: 1 = declared supported, 0 = explicitly unsupported or not declared, with no distinction between the two.

Per-slave CoE capability flags (EcEsi_GetBoundSlaveCoEDetails): the same 7 flags, addressed differently — pass (master_index, slave_index) and the runtime locates the ESI Device by the bound slave (the same binding the master used at configuration / startup). Callers no longer have to reverse-look-up "identity → loaded device index → file + document ordinal" themselves. Returns 0 = success; -1 = bad parameters; -2 = the slave has no bound ESI Device; -3 = the bound Device has no <CoE>. Any return value other than 0 means unknown, and all 7 out params are then written as -1 — never treat "unknown" as "explicitly unsupported".