Skip to main content

CoE (CANopen over EtherCAT)

CoE provides CANopen-based SDO (Service Data Object) access for reading and writing the object dictionary parameters of a slave.

CoE availability check

To determine whether a slave supports CoE, use the tri-state query ec_slave_get_proto_support_state(master, slave, MBXPROT_COE) (returns EC_PROTO_SUPPORT_YES / EC_PROTO_SUPPORT_NO / EC_PROTO_SUPPORT_UNKNOWN). Only YES confirms availability; UNKNOWN means the value could not be read, which is not the same as "not supported".

uint8_t GetSlaveCoEDetails(uint16_t master, uint16_t slave) returns the CoE details byte from the SII cache. It can also be 0 before the SII has been read, so it cannot be used on its own to conclude "not supported".

Function naming

For SDO mailbox reads and writes, prefer the typed public interfaces sdo_read_* / sdo_write_*; when you need the failure reason and the Abort Code, use sdo_read_typed_ex / sdo_write_typed_ex.

Feature overview​

CategoryCapabilityDescription
SDOTyped read/writeReads and writes a single object by type; on failure it reports only an aggregate result
SDORead/write with failure reasonDistinguishes a slave rejection from a communication failure and returns the raw abort code
SDOComplete AccessWhole-object read/write through the CA parameter of dx_sdo_read / dx_sdo_write
SDOBatch readec_coe_read_multiple reports success or failure per entry
SDOAsynchronous read/writeQueued on the master's serial gate and cancellable
ODFull table loadod_load / od_load_basic pull the object dictionary tree
ODMain-index skeletonGetSlaveSDOListBasic fetches the main index table (low level, no subentries)
ODSingle-object querycoe_get_object_description / coe_get_entry_description
ODDirect ESI readBuilds the OD tree from an ESI file with 0 mailbox traffic
ODDiagnostic history 0x10F3Typed polling / reading / acknowledgement through ec_coe_diag_*
EMCYHistory and single recordRing buffer per slave with up to 256 records; queryable and clearable
Fault isolationAbort code and cacheec_coe_sdo_error_str, NotPresent negative cache, request statistics

SDO read and write​

Three groups by purpose: typed read/write (day-to-day), read/write with a failure reason (when you need the Abort Code), and Complete Access (whole object).

CategoryInterfaceTypeRead/writeDescription
Typed readsdo_read_u8 / u16 / u32 / u64uint8_t* etc.Read-onlyUnsigned integers
Typed readsdo_read_i8 / i16 / i32 / i64int8_t* etc.Read-onlySigned integers
Typed readsdo_read_f32 / f64float* / double*Read-onlyFloating point
Typed readsdo_read_stringchar* + buf_sizeRead-onlyDecodes to UTF-8 according to the OD type of the object and returns the number of bytes written (including the terminator)
Typed writesdo_write_u8 / u16 / u32 / u64uint8_t etc.Write-onlyUnsigned integers
Typed writesdo_write_i8 / i16 / i32 / i64int8_t etc.Write-onlySigned integers
Typed writesdo_write_f32 / f64float / doubleWrite-onlyFloating point
Failure reasonsdo_read_typed_ex / sdo_write_typed_exintRead/writeReturns the raw abort / wkc / actual length
Whole objectdx_sdo_read / dx_sdo_writechar* / uint8_tRead/writeCA = TRUE performs a Complete Access transfer

The return status of sdo_read_typed_ex / sdo_write_typed_ex (ec_sdo_typed_status_t):

CategoryReturn valueRead/writeDescription
SuccessEC_SDO_TYPED_OK (0)—Output parameters are written
ParameterEC_SDO_TYPED_ERR_INVALID (-1)—out == NULL / size <= 0
LengthEC_SDO_TYPED_ERR_LENGTH (-2)—Read-back length is short; out_actual_size holds the actual byte count
Slave rejectionEC_SDO_TYPED_ERR_ABORT (-3)—out_abort holds the raw abort code from the device
CommunicationEC_SDO_TYPED_ERR_TRANSPORT (-4)—No response / mailbox failure (no abort)
Not readyEC_SDO_TYPED_ERR_UNAVAILABLE (-5)—SDK is not ready

Typed reads and writes​

All types share the same shape; only the pointer or value type changes (declarations are in ethercat_advanced.h):

int sdo_read_u8 (uint16_t master, uint16_t slave, uint16_t index, uint8_t sub, uint8_t*  out);
int sdo_read_u16(uint16_t master, uint16_t slave, uint16_t index, uint8_t sub, uint16_t* out);
int sdo_read_u32(uint16_t master, uint16_t slave, uint16_t index, uint8_t sub, uint32_t* out);
int sdo_read_u64(uint16_t master, uint16_t slave, uint16_t index, uint8_t sub, uint64_t* out);
int sdo_read_i8 (uint16_t master, uint16_t slave, uint16_t index, uint8_t sub, int8_t* out);
int sdo_read_i16(uint16_t master, uint16_t slave, uint16_t index, uint8_t sub, int16_t* out);
int sdo_read_i32(uint16_t master, uint16_t slave, uint16_t index, uint8_t sub, int32_t* out);
int sdo_read_i64(uint16_t master, uint16_t slave, uint16_t index, uint8_t sub, int64_t* out);
int sdo_read_f32(uint16_t master, uint16_t slave, uint16_t index, uint8_t sub, float* out);
int sdo_read_f64(uint16_t master, uint16_t slave, uint16_t index, uint8_t sub, double* out);
int sdo_read_string(uint16_t master, uint16_t slave, uint16_t index, uint8_t sub,
char* buf, int buf_size);

int sdo_write_u8 (uint16_t master, uint16_t slave, uint16_t index, uint8_t sub, uint8_t val);
int sdo_write_u16(uint16_t master, uint16_t slave, uint16_t index, uint8_t sub, uint16_t val);
int sdo_write_u32(uint16_t master, uint16_t slave, uint16_t index, uint8_t sub, uint32_t val);
int sdo_write_u64(uint16_t master, uint16_t slave, uint16_t index, uint8_t sub, uint64_t val);
int sdo_write_i8 (uint16_t master, uint16_t slave, uint16_t index, uint8_t sub, int8_t val);
int sdo_write_i16(uint16_t master, uint16_t slave, uint16_t index, uint8_t sub, int16_t val);
int sdo_write_i32(uint16_t master, uint16_t slave, uint16_t index, uint8_t sub, int32_t val);
int sdo_write_i64(uint16_t master, uint16_t slave, uint16_t index, uint8_t sub, int64_t val);
int sdo_write_f32(uint16_t master, uint16_t slave, uint16_t index, uint8_t sub, float val);
int sdo_write_f64(uint16_t master, uint16_t slave, uint16_t index, uint8_t sub, double val);

Parameters:

  • master / slave (uint16_t) — master index / slave index (1-based)
  • index / sub (uint16_t / uint8_t) — object index / subindex
  • out — pointer to an output variable of the target type
  • buf / buf_size — output buffer and capacity in bytes for sdo_read_string
  • val — value passed as the target type

Returns:

  • A successful read returns 0; a failure returns -1 and does not write the output parameter (it never silently writes 0). Passing NULL for out is also treated as a failure
  • A successful write returns 0; a failure returns -1
  • sdo_read_string returns the number of bytes written to buf (including the terminator); on failure it returns -1

Example:

#include "ethercat_advanced.h"

uint16_t sw;
if (sdo_read_u16(master, 1, 0x6041, 0, &sw) != 0)
printf("SDO 读取失败 (超时 / 通信失败,不是对象不存在)\n"); /* SDO read failed (timeout / communication failure, not a missing object) */
else
printf("StatusWord: 0x%04X\n", sw);

if (sdo_write_u16(master, 1, 0x6040, 0, 0x0006) != 0) /* ControlWord */
printf("ControlWord 写入失败\n"); /* ControlWord write failed */

char name[64];
if (sdo_read_string(master, 1, 0x1008, 0, name, sizeof(name)) >= 0)
printf("设备名称: %s\n", name); /* Device name: %s */

Reads and writes with a failure reason​

-1 is an aggregate failure: it cannot distinguish "bad parameter / slave rejection / no bus response / SDK not ready". When you need to branch on the cause, use:

typedef enum {
EC_SDO_TYPED_OK = 0, /* success, output parameter written */
EC_SDO_TYPED_ERR_INVALID = -1, /* invalid parameter (out == NULL / size <= 0) */
EC_SDO_TYPED_ERR_LENGTH = -2, /* read-back length is short, *out_actual_size is the actual byte count */
EC_SDO_TYPED_ERR_ABORT = -3, /* slave returned an SDO Abort, *out_abort is the raw abort code */
EC_SDO_TYPED_ERR_TRANSPORT = -4, /* no response / mailbox failure (wkc <= 0 and no abort) */
EC_SDO_TYPED_ERR_UNAVAILABLE = -5 /* SDK not ready */
} ec_sdo_typed_status_t;

int sdo_read_typed_ex(uint16_t master, uint16_t slave, uint16_t index, uint8_t sub,
void* out, int expected_size,
uint32_t* out_abort, int* out_wkc, int* out_actual_size);
int sdo_write_typed_ex(uint16_t master, uint16_t slave, uint16_t index, uint8_t sub,
const void* val, int size,
uint32_t* out_abort, int* out_wkc);

Parameters:

  • master / slave (uint16_t) — master index / slave index (1-based)
  • index / sub (uint16_t / uint8_t) — object index / subindex
  • out / expected_size (void* / int) — read buffer and expected byte count (expected_size <= 0 returns EC_SDO_TYPED_ERR_INVALID)
  • val / size (const void* / int) — data to write and its length
  • out_abort (uint32_t*) — the raw SDO abort code from the device (0 on success); not normalized, not replaced, not swallowed
  • out_wkc (int*) — the underlying WKC (working counter)
  • out_actual_size (int*) — actual byte count on the read path

Returns:

  • Both return the ec_sdo_typed_status_t values from the table above
  • All three output parameters accept NULL; on failure the out data buffer is not written, while out_abort / out_wkc / out_actual_size are still filled in from the actual result
  • The -1 returned by the older sdo_read_* / sdo_write_* is an aggregate failure, equivalent to "not EC_SDO_TYPED_OK"
Check the return value first, do not treat a communication failure as "object does not exist"

These failures fall into two groups. Master side: 0x0D000001 request not sent, 0x0D000002 frame transmitted but not counted by the device, 0x0D000003 mailbox layer error, 0x0D000004 transport-layer failure — see Master-side codes. Device side: 0x08000021 / 0x08000022 are abort codes the device reports itself (local control / present device state does not allow the transfer); 0x05040000 (SDOProtocolTimeout) means the device sent no abort code; 0x08000000 (GeneralError) only means the device really returned that code. None of these means "object does not exist", and none of them is written to the NotPresent negative cache. Only deterministic aborts (0x06010000 access not supported / 0x06010001 / 0x06010002 / 0x06020000 object does not exist / 0x06090011 / 0x06090012 subindex does not exist) enter the negative cache; test for them with sdo_abort_is_deterministic(code).

Example:

uint32_t vendor_id = 0;
if (sdo_read_u32(master, 1, 0x1018, 0x01, &vendor_id) != 0) {
printf("SDO 读取失败 (超时 / 通信失败,不是对象不存在)\n"); /* SDO read failed (timeout / communication failure, not a missing object) */
} else {
printf("Vendor ID: 0x%08X\n", vendor_id);
}

uint16_t cw = 0x0006;
if (sdo_write_u16(master, 1, 0x6040, 0x00, cw) != 0) {
printf("SDO 写入失败\n"); /* SDO write failed */
}

uint16_t status_word = 0;
uint32_t abort = 0;
int wkc = 0, actual = 0;
int rc = sdo_read_typed_ex(master, 1, 0x6041, 0x00,
&status_word, sizeof(status_word),
&abort, &wkc, &actual);
if (rc == EC_SDO_TYPED_OK) {
printf("StatusWord: 0x%04X\n", status_word);
} else {
printf("SDO 读取失败, AbortCode=0x%08X\n", abort); /* SDO read failed, AbortCode=0x%08X */
}

Example (branch handling):

uint16_t sw = 0;
uint32_t abort = 0;
int wkc = 0, actual = 0;

int rc = sdo_read_typed_ex(master, 1, 0x6041, 0x00, &sw, (int)sizeof(sw),
&abort, &wkc, &actual);
switch (rc) {
case EC_SDO_TYPED_OK:
printf("StatusWord: 0x%04X\n", sw);
break;
case EC_SDO_TYPED_ERR_ABORT:
printf("从站拒绝: 0x%08X\n", abort); /* raw code from the device */
break;
case EC_SDO_TYPED_ERR_LENGTH:
printf("长度不足: 实际 %d 字节\n", actual); /* Length too short: actual %d bytes */
break;
case EC_SDO_TYPED_ERR_TRANSPORT:
printf("无应答 / 邮箱失败 (wkc=%d)\n", wkc); /* No response / mailbox failure (wkc=%d) */
break;
case EC_SDO_TYPED_ERR_UNAVAILABLE:
printf("SDK 未就绪\n"); /* SDK not ready */
break;
default:
break;
}
When to use the failure-reason variants
  • You need to distinguish a "communication failure" from a "slave rejection" (for example, a value out of range versus a broken bus link)
  • You are bringing up a new drive and want the abort code in the log for later review
  • The application does not need the abort code: the typed interfaces are simpler

To run SDO transfers in the background, use darra_sdo_read_async(gate, mi, si, index, sub, ...) / darra_sdo_write_async(...). They are queued on that master's serial gate and run strictly in sequence with Build, state changes and other SDO traffic on the same master, so the mailbox is never hit concurrently. The result and the abort code arrive through the completion callback; cancel with darra_async_token_cancel(token).

Complete Access​

For a whole-object transfer in one call, use the CA parameter of dx_sdo_read / dx_sdo_write. subindex may only be 0 or 1 (ETG.1000.6 Table 34); any other value fails immediately without sending a request:

char*   dx_sdo_read(uint16_t master, uint16_t slave, uint16_t index,
uint8_t subindex, BOOL CA, int* out_byte_size);
uint8_t dx_sdo_write(uint16_t master, uint16_t slave, uint16_t index,
uint8_t subindex, BOOL CA, uint8_t* bytes, int length);

Parameters:

  • CA (BOOL) — TRUE = Complete Access whole-object transfer; FALSE = a normal single-entry transfer
  • out_byte_size (int*) — actual byte count on the read path (*out_byte_size == 0 means an empty object was read, which is not a failure)
  • bytes / length — data to write and its length (bytes is a borrowed buffer owned by the caller)

Returns:

  • dx_sdo_read returns a buffer allocated by the runtime library on success; release it with FreeMemory(). On failure it returns NULL
  • dx_sdo_write returns 1 on success / 0 on failure. Test for == 1 only: when the runtime library is not ready or the entry point is missing it returns 255, so testing != 0 would treat "not sent" as success

Example:

int size = 0;
char* raw = dx_sdo_read(master, 1, 0x1C13, 0, TRUE, &size); /* read the whole TxPDO mapping */
if (raw && size > 0) {
/* split it yourself per ETG.1000.6 §5.6.2: SubIndex 0 is always 2 bytes, the rest follow the entry bit lengths */
FreeMemory(raw);
}

uint8_t cfg[16] = {0};
if (!dx_sdo_write(master, 1, 0x1C13, 0, TRUE, cfg, sizeof(cfg)))
printf("Complete Access 写入失败\n"); /* Complete Access write failed */

Splitting by layout: use ec_coe_parse_complete_access() (it prefers the ESI layout; when the ESI does not contain the object or the type information is insufficient, it falls back to the type table supplied by the caller), then use ec_coe_ca_extract() to get the bytes of each subindex:

#define EC_COE_CA_MAX_ENTRIES 288
ec_ca_subindex_t layout[EC_COE_CA_MAX_ENTRIES];
ec_coe_ca_layout_t fallback[3] = {
{ 0x00, 0x0005, 8 }, /* SI0: effectively always 16 bit */
{ 0x01, 0x0006, 16 }, /* UINT16 */
{ 0x02, 0x0006, 16 },
};
uint32_t total = 0;
int used_fallback = 0;
int n = ec_coe_parse_complete_access(master, 1, 0x1C13, 0,
(const uint8_t*)raw, (uint32_t)size,
fallback, 3, layout, EC_COE_CA_MAX_ENTRIES,
&total, &used_fallback);
for (int i = 0; i < n; i++) {
uint8_t bytes[8];
int len = ec_coe_ca_extract((const uint8_t*)raw, (uint32_t)size,
&layout[i], bytes, sizeof(bytes));
if (len > 0)
printf("[%02X] %d 字节\n", layout[i].sub_index, len); /* [%02X] %d bytes */
}
  • A return value n >= 0 is the number of entries written to layout (not an error code). Negative values are failure codes: -1 invalid parameter / -2 invalid slave context / -3 no matching ESI or the object is not ARRAY|RECORD / -4 type or bit length missing / -5 blob shorter than the ESI declares / -8 subindex count above the limit;
  • used_fallback = 1 means the ESI layout was unavailable and the caller's type table was used instead (the fallback only supports start_subindex = 0);
  • Bit types (BOOLEAN / BIT1..BIT8) are extracted bit by bit and right-aligned by ec_coe_ca_extract() (bit0 = first bit), matching C# / Rust / Python. ESI gap entries produce no subindex.

Access permission checks​

int ec_coe_access_state_allows(uint16_t obj_access, ec_state_t state, int is_read);
int ec_coe_can_read(uint16_t obj_access, ec_state_t state);
int ec_coe_can_write(uint16_t obj_access, ec_state_t state);

All three are purely local checks: they look only at the access bitmask passed in and the current AL state, never touch the bus and never send an SDO, so they cannot see the abort code returned by the device. Whether the device actually refused is answered by Access denied.

ec_coe_access_state_allows() is the single implementation of “does the current state allow it”; ec_coe_can_read() / ec_coe_can_write() layer the permission-bit test on top of it.

Parameters:

  • obj_access (uint16_t) — access-permission bitmask of ec_coe_object_access_t (same value as od_entry_t.obj_access):
typedef enum {
EC_COE_ACCESS_NONE = 0x00,
EC_COE_ACCESS_READ_PREOP = 0x01,
EC_COE_ACCESS_READ_SAFEOP = 0x02,
EC_COE_ACCESS_READ_OP = 0x04,
EC_COE_ACCESS_WRITE_PREOP = 0x08,
EC_COE_ACCESS_WRITE_SAFEOP = 0x10,
EC_COE_ACCESS_WRITE_OP = 0x20,
EC_COE_ACCESS_READ_ANY = EC_COE_ACCESS_READ_PREOP | EC_COE_ACCESS_READ_SAFEOP | EC_COE_ACCESS_READ_OP,
EC_COE_ACCESS_WRITE_ANY = EC_COE_ACCESS_WRITE_PREOP | EC_COE_ACCESS_WRITE_SAFEOP | EC_COE_ACCESS_WRITE_OP,
EC_COE_ACCESS_READ_WRITE_ALL = EC_COE_ACCESS_READ_ANY | EC_COE_ACCESS_WRITE_ANY
} ec_coe_object_access_t;
  • state (ec_state_t) — current AL state of the slave; EC_STATE_NONE means unknown
  • is_read (int) — used only by ec_coe_access_state_allows: 1 = judge by the read rules, 0 = judge by the write rules

Read: cumulative rules

ETG read-access bits are a cumulative set — “also valid starting from this state” — not one bit per state in mutual exclusion:

CategoryCurrent AL stateRead/writeAllowed when
State unknownEC_STATE_NONE (including values carrying only the 0x10 Error/ACK bits)read-onlyAllowed — an unknown state is not evidence of “not accessible”
State allowsInitread-onlyobj_access contains READ_PREOP or READ_SAFEOP
State allowsPreOpread-onlyobj_access contains READ_PREOP
State allowsSafeOpread-onlyobj_access contains READ_PREOP or READ_SAFEOP (cumulative; a separate READ_SAFEOP is not required)
State allowsOPread-onlyobj_access contains any bit of READ_ANY
State refusesBoot / any other known stateread-onlyNever allowed

Write: exact match

Write permission does not accumulate and does not carry upwards — each state is paired with exactly one bit:

CategoryCurrent AL stateRead/writeAllowed when
State unknownEC_STATE_NONEwrite-onlyAllowed
State allowsPreOpwrite-onlyobj_access contains WRITE_PREOP
State allowsSafeOpwrite-onlyobj_access contains WRITE_SAFEOP
State allowsOPwrite-onlyobj_access contains WRITE_OP
State refusesInit / Boot / any other known statewrite-onlyNever allowed

obj_access == 0 is handled differently per direction:

CategoryInterfaceRead/writeWhen obj_access == 0
Permission bits missingec_coe_can_readread-onlyReturns 0 — the read side has no exemption for ObjAccess == 0 (meaning accessibility is unknown); a bitmask of 0 simply carries no read bit
Accessibility unknownec_coe_can_writewrite-onlyReturns 1 — the descriptor gives no accessibility, so let it through and let the device SDO Abort be the source of truth

Returns:

  • ec_coe_access_state_allows — 1 = the current state allows it; 0 = it does not
  • ec_coe_can_read — 1 = readable in the current state; 0 = not readable (including known states such as Boot, and when obj_access carries no read bit)
  • ec_coe_can_write — 1 = writable in the current state; 0 = not writable in the current state. 0 has two sources: the descriptor explicitly carries no write bit (access denied), or the permission bits are complete but the current state does not match (not access denied — a state change is needed, for example an object that becomes writable only in OP). Use ec_coe_classify_access_denied() from Access denied to tell them apart: it never decides “denied” on a state mismatch, EC_COE_ACCESS_REASON_STATE appears only on the read path, and the abort_code handed to it for ec_coe_can_write is always 0, so the only refusal it can detect for writes is missing permission bits (FLAGS)

Strings and data types​

The two string types of CoE objects have different byte semantics: VISIBLE_STRING is single-byte ISO-8859-1 terminated by 0x00, OCTET_STRING is a raw single-byte sequence, and UNICODE_STRING is a UTF-16LE code-unit sequence terminated by 0x0000, with surrogate pairs for non-BMP code points. If the same UnicodeString object is decoded as "single-byte plus truncation at the first 0x00", "AB" (41 00 42 00) is decoded as "A".

sdo_read_string() first reads the Entry Description of the object (CoE SDO Information) to get the OD data type, then decodes to UTF-8 according to VISIBLE_STRING / OCTET_STRING (single-byte) or UNICODE_STRING (UTF-16LE). If the type is unavailable, the object is not a string type, or decoding fails, it keeps the raw byte semantics (copy as-is, strip trailing 0x00) and records a diagnostic log entry; it never guesses an encoding. It returns the number of bytes written to buf (including the terminator); on failure it returns -1.

CategoryFunctionReturn typeRead/writeDescription
Type informationEcPdoCodec_DataTypeName(dt)const char*Read-onlyReturns the canonical upper-case name such as INT8 / UINT16 / REAL32 / VISIBLE_STRING / BIT1 / UNKNOWN; an unknown name returns "UNKNOWN"
Type informationEcPdoCodec_DataTypeBitSize(dt)intRead-onlyReturns the bit width; variable-length types return -1 and unknown names return 0

Example:

const char* name = EcPdoCodec_DataTypeName(EC_DT_REAL32);   /* "REAL32" */
int bits = EcPdoCodec_DataTypeBitSize(EC_DT_REAL32); /* 32 */

char dev[128];
int n = sdo_read_string(master, 1, 0x1008, 0x00, dev, sizeof(dev));
if (n >= 0)
printf("设备名: %s (%d 字节 UTF-8)\n", dev, n); /* Device name: %s (%d bytes UTF-8) */

SDO negative cache (deterministic abort)​

A deterministic abort is one the slave explicitly rejects and that will not succeed on retry (0x06010000 access not supported / 0x06010001 / 0x06010002 / the object-and-subindex-missing family 0x06020000 / 0x06090011; 0x06090012 is also treated as deterministic, but it is a variant code with no matching member in ec_sdo_error_t). Read entry points such as sdo_read_u8…sdo_read_string record it in the NotPresent negative cache keyed by (index, subindex); later reads of the same object then short-circuit to failure without touching the mailbox. Write paths neither consult nor update the negative cache, and Complete Access reads bypass it as well.

sdo_abort_is_deterministic()​

int sdo_abort_is_deterministic(uint32_t abort_code);

Tests whether an abort is a deterministic rejection (a code the slave explicitly rejects and that will not succeed on retry).

Parameters:

  • abort_code (uint32_t) — SDO abort code

Returns:

  • 1 = deterministic abort; 0 = not deterministic (an SDK that is not ready also returns 0). The deterministic set is 0x06010000 / 0x06010001 / 0x06010002 / 0x06020000 / 0x06090011 / 0x06090012; timeout 0x05040000, Toggle 0x05030000, the generic error 0x08000000 and the 0x0607001x width family are not deterministic — they may recover, so never short-circuit or cache on them

sdo_not_present_cache_lookup()​

int sdo_not_present_cache_lookup(uint16_t master, uint16_t slave,
uint16_t index, uint8_t sub, uint32_t* out_abort);

Looks up the negative cache of the slave. On a hit it fills in the same raw device abort code that the original call returned.

Returns:

  • 1 = hit, and out_abort is filled in; 0 = miss (an SDK that is not ready is also reported as a miss, so a readable object is never mistaken for NotPresent). Only == 1 counts as a hit

sdo_not_present_cache_store()​

void sdo_not_present_cache_store(uint16_t master, uint16_t slave,
uint16_t index, uint8_t sub, uint32_t abort_code);

Records a deterministic abort in the NotPresent negative cache of the slave (the read entry points call this automatically, so manual use is rarely needed). Only deterministic aborts are cached; for the same (index, subindex) the first write wins. Returns nothing.

sdo_not_present_cache_reset()​

void sdo_not_present_cache_reset(uint16_t master, uint16_t slave);

Clears all negative-cache entries of the slave. Call it before a hot-plug, a firmware update, a topology change, a downgrade to PreOp or a PDO rescan. Returns nothing; when the SDK is not ready it does nothing.

Batch SDO reads​

ec_coe_read_multiple() reads several (index, subindex) pairs in one call, with independent success per entry; it has the same semantics as the ReadMultiple family in C++/C#/Java/Python/Rust.

int ec_coe_read_multiple(uint16_t master_index, uint16_t slave_index,
const ec_sdo_entry_t* entries, int count,
ec_sdo_read_result_t* results,
uint32_t* out_abort_codes); /* may be NULL */

typedef struct {
uint16_t index; /* object index */
uint8_t subindex; /* subindex */
} ec_sdo_entry_t;

typedef struct {
uint16_t index; /* object index */
uint8_t subindex; /* subindex */
uint8_t* data; /* data pointer (NULL means failure; release with FreeMemory) */
int data_size; /* data size (bytes) */
} ec_sdo_read_result_t;

Parameters:

  • master_index / slave_index (uint16_t) — master index / slave index (1-based)
  • entries / count — array of requested entries and the number of entries
  • results — result array; entries are written to results[0..count-1] in the order of entries, and the function fills in index / subindex
  • out_abort_codes (uint32_t*) — may be NULL; when not NULL it is filled per entry with the Abort Code (0 = success or no abort)

Returns:

  • int — number of successful entries (0..count); -1 = invalid parameter (entries / results is NULL or count <= 0)
  • A failed entry does not affect the others: that entry gets data = NULL and data_size = 0; see out_abort_codes[i] for the reason
  • The data of a successful entry is allocated by the runtime library; release every entry with FreeMemory()
  • Every read refreshes ec_coe_get_last_sdo_error() (see "SDO status record")

Example:

ec_sdo_entry_t req[3] = {
{ 0x6041, 0x00 }, /* StatusWord */
{ 0x6064, 0x00 }, /* ActualPosition */
{ 0x6077, 0x00 }, /* ActualTorque */
};
ec_sdo_read_result_t res[3];
uint32_t aborts[3];
int ok = ec_coe_read_multiple(master, 1, req, 3, res, aborts);
for (int i = 0; i < 3; i++) {
if (res[i].data) {
printf("0x%04X:%02X -> %d 字节\n", /* 0x%04X:%02X -> %d bytes */
res[i].index, res[i].subindex, res[i].data_size);
FreeMemory(res[i].data); /* release each entry */
} else {
printf("0x%04X:%02X 读失败 abort=0x%08X\n", /* 0x%04X:%02X read failed abort=0x%08X */
res[i].index, res[i].subindex, aborts[i]);
}
}
printf("成功 %d/3\n", ok); /* %d/3 succeeded */

Object dictionary access​

od_load() / od_load_basic() / od_free()​

od_list_t* od_load(uint16_t master, uint16_t slave, BOOL load_entries);
od_list_t* od_load_basic(uint16_t master, uint16_t slave);
void od_free(od_list_t* list);

od_load() loads the full OD tree (with subentries when load_entries = TRUE); od_load_basic() fetches only the main indexes (equivalent to od_load(master, slave, FALSE)). The returned pointer must be released with od_free() exactly once.

Parameters:

  • master / slave (uint16_t) — master index / slave index (1-based)
  • load_entries (BOOL) — whether to load subentries (FALSE loads only the main indexes; in OP / SafeOp use FALSE to avoid mailbox pressure)

Returns:

  • od_list_t* — the OD tree (structure in "Related structures"); on failure it returns NULL. An empty dictionary is not a success (count == 0 is also treated as failure)
  • A single response is limited to 64 KB; anything larger fails the read and returns NULL, so read very large dictionaries in stages

GetSlaveSDOListBasic()​

void* GetSlaveSDOListBasic(uint16_t master_index, uint16_t slave_index);

A low-level entry point that fetches only the main-index skeleton of the OD (it does not expand subentries and does not read object descriptions). It is useful for first getting "which objects does this slave have" and then querying individual object descriptions on demand. Declared in slave/coe.h and forwarded to DarraEcat_GetSlaveSDOListBasic.

Parameters:

  • master_index (uint16_t) — master index
  • slave_index (uint16_t) — slave index (1-based)

Returns:

  • void* — the OD main index table allocated by the runtime library; on failure it returns NULL (the slave does not support CoE, the state has not reached PreOp, or the read failed)
  • An empty table is not a success: when no valid main index can be read it returns NULL rather than passing off a 0-entry table as success

When to call: after CoE is available on the slave and the state has reached PreOp. It shares the mailbox with SDO reads and writes, so do not call it from a high-rate PDO path.

Ownership (mandatory):

  • The returned table is allocated by the runtime library and exposed as void* by the public C header. It is not the public od_list_t tree returned by od_load() above, so do not read it through the count / objects fields of the public structure;
  • Release it with the dedicated coe_free_odlist (C export name DarraEcat_coe_free_odlist), exactly once;
  • Do not substitute FreeMemory — releasing across runtime libraries is not safe;
  • Each call returns a separate block; never release the same pointer twice, and never use it after release.

Relationship to od_load_basic():

CategoryEntry pointReturnsRead/writeDescription
High-level loadod_load() / od_load_basic()public od_list_t*Read-onlyNormal OD browsing: object names, subentries and od_find() lookups; release with od_free()
Low-level skeletonGetSlaveSDOListBasic()void* (main index table on the runtime-library side)Read-onlyFetch the index skeleton first, or reuse the table as a borrowed handle; release with DarraEcat_coe_free_odlist()

The two are entry points at different levels and are independent: od_load_basic() is equivalent to od_load(master, slave, FALSE) (it tries the ESI first and falls back to SDO Information), and it never calls GetSlaveSDOListBasic(). Use od_load_basic() for normal OD browsing; use GetSlaveSDOListBasic() only when you need to reuse the raw main index table as a borrowed handle (for example, passing it to GetSlavePointer_SDO_WithODList() while looping over subentries, so the main index table is not re-read for every lookup — the OE_index of that entry point is a position within the table starting at 0, not an object index).

Example:

void* od_basic = GetSlaveSDOListBasic(master, 1);
if (od_basic == NULL) {
printf("OD 主索引读取失败(从站不支持 CoE / 状态未到 PreOp / 读失败)\n"); /* OD master index read failed (slave does not support CoE / state not yet PreOp / read failed) */
} else {
/* the main index table is only a skeleton; use od_load_basic() when you need object names and subentries */
DarraEcat_coe_free_odlist(od_basic); /* exactly once; do not use FreeMemory */
}

od_find() / od_find_entry()​

od_object_t* od_find(od_list_t* list, uint16_t index);
od_entry_t* od_find_entry(od_object_t* obj, uint8_t subindex);

Looks up objects and subentries in a loaded OD tree.

Returns:

  • od_object_t* / od_entry_t* — pointer to the matching object / entry; NULL when not found (od_find_entry also returns NULL when obj->entries == NULL)

Single-object / single-entry description (CoE-H2 SDO Information)​

A full table load suits OD-browser initialisation. When you need only one object description (for example 0x6041 StatusWord), use the three entry points below instead of pulling the whole table for a single query:

od_list_t* od_load_via_coe_h2(uint16_t master, uint16_t slave,
uint16_t* out_abort, uint16_t* out_wkc);
int coe_get_object_description(uint16_t master, uint16_t slave,
uint16_t index, od_object_t* out_obj,
uint16_t* out_abort, uint16_t* out_wkc);
int coe_get_entry_description(uint16_t master, uint16_t slave,
uint16_t index, uint8_t subindex,
od_entry_t* out_entry,
uint16_t* out_abort, uint16_t* out_wkc);
  • coe_get_object_description — fetches only the object description of a main index (Object Code / DataType / MaxSubIndex / Name) and does not expand subentries (out_obj->entries is always NULL). Useful for deciding "does the object exist" or "is it a RECORD or a VARIABLE".
  • coe_get_entry_description — fetches the entry description of a single (index, subindex) (BitLength / Access / Name). Combine it with sdo_read_typed_ex to parse adaptively from the description when the field length is unknown.
  • Both write the result into a caller-owned stack structure, allocate no heap memory and need no release; they return 1 on success / 0 on failure.
  • od_load_via_coe_h2 does not use the GetSlaveSDOList cache path; it pulls live from the slave every time and builds the whole OD tree, including the entry description of every subindex. On failure or an empty dictionary it returns NULL; release the return value with od_free().

Diagnostic output parameters (shared by the three entry points):

  • out_abort (uint16_t*) — the 16-bit ErrorCode inside the device's SDO Info Error frame. 0 = no Info Error was received; out_abort == 0 only means the device returned no abort code (timeout / protocol failure) and does not mean success. A transport failure never fabricates an abort code; the return value plus out_wkc express it.
  • out_wkc (uint16_t*) — result of the innermost mailbox transaction (1 success / 0 failure or not executed). For a multi-transaction entry point (od_load_via_coe_h2), any single failure sets out_wkc to 0 and keeps the first non-zero abort code; a later success never masks an earlier failure.
  • Either one may be NULL, and you may pass only one of them; the function clears them on entry, so the caller does not need to preset them.

Example:

od_object_t obj;
if (coe_get_object_description(master, 1, 0x6040, &obj, NULL, NULL))
printf("0x6040 = %s, ObjectCode=0x%02X, MaxSub=%u\n",
obj.name, obj.object_code, obj.max_sub);

od_entry_t entry;
if (coe_get_entry_description(master, 1, 0x6041, 0x00, &entry, NULL, NULL))
printf("0x6041:00 = %s, BitLen=%u\n", entry.name, entry.bit_length);

uint16_t abort = 0, wkc = 0;
od_list_t* od = od_load_via_coe_h2(master, 1, &abort, &wkc);
if (od == NULL)
printf("OD 直读失败: wkc=%u, InfoError=0x%04X\n", wkc, abort); /* OD direct read failed: wkc=%u, InfoError=0x%04X */
else
od_free(od);

The full-table GetSlaveSDOList / od_load_via_coe_h2 calls suit OD-browser initialisation and then stay in memory. Control loops and online parameter tuning should query only the indexes they need through coe_get_object_description / coe_get_entry_description. These interfaces share the mailbox with SDO reads and writes, so do not call them from a high-rate PDO path.

Direct ESI reads (0 mailbox traffic)​

Besides enumerating through the mailbox, you can build the OD tree directly from an ESI file with 0 mailbox traffic:

BOOL  ec_coe_set_esi_search_dir(const char* dir);
void* ec_coe_load_od(uint16_t master, uint16_t slave,
int load_entries, int prefer_esi);
void* ec_coe_load_od_from_esi_file(const char* esi_path,
uint32_t vendor_id, uint32_t product_code,
int load_entries);
void* ec_coe_load_od_from_esi_file_ex(const char* esi_path,
uint32_t vendor_id, uint32_t product_code,
uint32_t revision_no, int revision_strategy,
int load_entries,
char* diag, int diag_cap);

Parameters:

  • dir (const char*) — when preferring the ESI, the directory scanned for .xml / .ESI files matched by Vendor / Product; NULL or an empty string clears it
  • load_entries (int) — a value other than 0 also fills in subindexes (DataType/SubItem for the ESI path, OEList for the SDO path)
  • prefer_esi (int) — a value other than 0 reads a loaded ESI first and falls back to SDO Information on a miss; 0 goes straight to SDO Information
  • esi_path — path to a specific ESI file (read directly from that file only, no mailbox traffic)
  • vendor_id / product_code — used to match the Device in a multi-Device file
  • revision_no / revision_strategy — select the Device precisely by revision (ETG.2000): 0 = ESI_MATCH_EXACT (default) / 1 = ESI_MATCH_MAJOR / 2 = ESI_MATCH_IGNORE; revision_no = 0 means no revision constraint
  • diag / diag_cap — diagnostic string (may be NULL); on failure it receives the expected identity plus the list of candidate Devices

Returns:

  • ec_coe_set_esi_search_dir — TRUE = applied (including an empty dir, which clears the directory); FALSE = the path was too long and rejected, leaving the previous directory unchanged
  • The three load functions return od_list_t* (typed void* in the signature); release with od_free() exactly once. On failure they return NULL
  • ec_coe_load_od_from_esi_file — returns NULL when there is no Dictionary or no Device matches. It does not constrain RevisionNo: when several revision variants share a ProductCode, it matches the first Device in the file with that ProductCode
  • ec_coe_load_od_from_esi_file_ex — the file's <Vendor>/<Id> must equal vendor_id (0 = no check); Device.Type/@ProductCode must equal product_code; if the file declares Device.Type/@RevisionNo it is compared according to revision_strategy, and only when it is absent is the Device accepted without a revision check. NULL = not opened / no match / matched but no Dictionary; use diag to tell these apart

Example:

ec_coe_set_esi_search_dir("ESI");                     /* set before entering OP */
od_list_t* od = (od_list_t*)ec_coe_load_od(master, 1, 1, 1);
if (od) od_free(od);

char diag[256];
od_list_t* od2 = (od_list_t*)ec_coe_load_od_from_esi_file_ex(
"ESI/vendor.xml", 0x00001164, 0x00000001, 0x00010000, 0, 1, diag, sizeof(diag));
if (od2) od_free(od2);
else printf("ESI 直读失败: %s\n", diag); /* ESI direct read failed: %s */
typedef struct {
int count; /* number of objects */
od_object_t* objects; /* array of objects */
} od_list_t;
typedef struct {
uint16_t index; /* OD index */
char name[42]; /* name */
uint16_t datatype; /* data type */
uint8_t object_code; /* object type (0x07=VARIABLE, 0x09=RECORD) */
uint8_t max_sub; /* maximum subindex count */
int entry_count; /* actual entry count */
od_entry_t* entries; /* array of entries */
} od_object_t;

typedef struct {
uint8_t subindex; /* subindex */
char name[42]; /* name */
uint16_t datatype; /* data type (ec_datatype_t) */
uint16_t bit_length; /* bit length */
uint16_t obj_access; /* access permission (ec_obj_access_t bitmask) */
} od_entry_t;

Example:

#include "ethercat_advanced.h"

/* load the full OD tree. An empty dictionary is not success. In OP / SafeOp use od_load(..., FALSE) to load only the main indexes */
od_list_t* od = od_load(master, 1, TRUE);
if (od == NULL || od->count == 0) {
printf("对象字典加载失败\n"); /* Object dictionary load failed */
} else {
printf("对象数量: %d\n", od->count); /* Object count: %d */

/* iterate over all objects */
for (int i = 0; i < od->count; i++) {
od_object_t* obj = &od->objects[i];
printf("0x%04X: %s (%d 子条目)\n", obj->index, obj->name, obj->entry_count); /* 0x%04X: %s (%d subentries) */
for (int j = 0; j < obj->entry_count; j++) {
od_entry_t* entry = &obj->entries[j];
printf(" [%d] %s (类型=0x%04X, %d 位)\n", /* [%d] %s (type=0x%04X, %d bits) */
entry->subindex, entry->name, entry->datatype, entry->bit_length);
}
}

/* look up a specific object */
od_object_t* cw = od_find(od, 0x6040);
if (cw) printf("找到 ControlWord: %s\n", cw->name); /* ControlWord found: %s */

od_free(od);
}

EMCY emergency messages​

The SDK keeps a ring-buffer history for each slave, retaining up to 256 records and overwriting the oldest once full.

EmcyGetCount()​

int EmcyGetCount(uint16_t master, uint16_t slave);

Gets the current number of history records for the slave.

Parameters:

  • master (uint16_t) — master index
  • slave (uint16_t) — slave index

Returns:

  • int — current number of history records

EmcyGetHistory()​

int EmcyGetHistory(uint16_t master, uint16_t slave, ec_emcy_record_t* out, int max);

Copies the most recent max records from the ring in time order (oldest → newest) and returns the actual count.

Parameters:

  • out (ec_emcy_record_t*) — output buffer supplied by the caller
  • max (int) — maximum number of records to read (buffer capacity)

Returns:

  • int — actual number of records read; when max <= 0 it does not write out and returns 0
  • A return of 0 can mean either "no records" or "invalid output parameter"; use EmcyGetLastEx to tell them apart

EmcyGetLastEx()​

int EmcyGetLastEx(uint16_t master, uint16_t slave, ec_emcy_record_t* out, int32_t* status);

Fetches the most recent record and reports "invalid parameter / no records / success" separately.

Parameters:

  • out (ec_emcy_record_t*) — output parameter; the most recent record is written only when the return value is 0, and never for any other return value
  • status (int32_t*) — may be NULL; receives the same status code as the return value

Returns:

  • 0 = success, *out holds the most recent record
  • -1 = the slave has no EMCY records
  • -2 = invalid parameter (out == NULL / slave out of range)

EmcyClearHistory()​

void EmcyClearHistory(uint16_t master, uint16_t slave);

Clears the history of the slave. Returns nothing.

Related structures:

typedef struct {
uint16_t error_code; /* error code (high byte is the error category) */
uint8_t error_register; /* error register */
uint8_t data[5]; /* vendor-specific bytes */
uint16_t slave_index; /* slave index */
uint32_t timestamp_ms; /* capture timestamp (milliseconds) */
} ec_emcy_record_t;

The high byte of error_code is the error category: 0x00 reset / no error, 0x10 generic, 0x20 current, 0x30 voltage, 0x40 temperature, 0x50 device hardware, 0x60 device software, 0x70 additional modules, 0x80 monitoring, 0x90 external, 0xF0 additional functions, 0xFF device specific.

Example:

int count = EmcyGetCount(master, 1);
if (count > 0) {
ec_emcy_record_t records[16];
int n = EmcyGetHistory(master, 1, records, 16);
for (int i = 0; i < n; i++)
printf("EMCY: 0x%04X, 寄存器=0x%02X, 时间=%ums\n", /* EMCY: 0x%04X, register=0x%02X, time=%ums */
records[i].error_code, records[i].error_register, records[i].timestamp_ms);
EmcyClearHistory(master, 1); /* clear after handling */
}

/* only the most recent record, and tell "no records" apart */
ec_emcy_record_t last;
int32_t status = 0;
if (EmcyGetLastEx(master, 1, &last, &status) == 0)
printf("最新 EMCY: 0x%04X\n", last.error_code); /* Latest EMCY: 0x%04X */
else if (status == -1)
printf("该从站没有 EMCY 记录\n"); /* This slave has no EMCY record */

CoE diagnostic history (0x10F3)​

0x10F3 is the structured diagnostic message buffer in the slave's object dictionary (ETG.1020 §16). The C SDK provides a typed wrapper with the same capability set as C# ReadDiagnosticMessages / DiagMeta; you can also read and write it through the manual SDO route. The difference from EMCY: EMCY is an 8-byte error code pushed asynchronously by the drive and captured by the SDK-side history buffer, whereas the diagnostic history is a ring buffer inside the slave that you must read actively.

Both share the mailbox; do not poll them from a high-rate PDO thread. A background thread polling about once per second is recommended.

ec_coe_diag_read_meta() / ec_coe_diag_poll_new()​

int ec_coe_diag_read_meta(uint16_t master, uint16_t slave,
ec_coe_diag_meta_t* out, uint32_t* out_abort_code);
int ec_coe_diag_poll_new(uint16_t master, uint16_t slave, uint32_t* out_abort_code);

ec_coe_diag_read_meta reads the metadata (0x10F3:01/:02/:03/:05); ec_coe_diag_poll_new polls 0x10F3:04 to determine whether new messages exist.

Parameters:

  • out (ec_coe_diag_meta_t*) — metadata output parameter (required)
  • out_abort_code (uint32_t*) — may be NULL; on failure it receives the SDO abort (0x06020000 = the slave has no such object)

Returns:

  • ec_coe_diag_read_meta: 1 success / 0 failure (including a slave that does not support 0x10F3)
  • ec_coe_diag_poll_new: 1 new messages exist / 0 none (including 0x10F3 not supported) / -1 communication failure (timeout / WKC = 0)

ec_coe_diag_read_message_raw() / ec_coe_diag_read_parsed()​

int ec_coe_diag_read_message_raw(uint16_t master, uint16_t slave,
uint8_t sub_index, uint8_t* buf, int buf_cap,
int* out_len, uint32_t* out_abort_code);
int ec_coe_diag_read_parsed(uint16_t master, uint16_t slave,
uint8_t sub_index, ec_coe_diag_message_t* out,
uint32_t* out_abort_code);

Reads one message: _raw returns the raw bytes without parsing; _parsed parses them into ec_coe_diag_message_t.

Parameters:

  • sub_index (uint8_t) — message subindex; must be >= 6
  • buf / buf_cap / out_len — caller-supplied raw byte buffer, its capacity and the actual length
  • out (ec_coe_diag_message_t*) — parsed-result output parameter

Returns:

  • 1 success / 0 failure; when the payload is shorter than 8 bytes, ec_coe_diag_read_parsed() reports failure rather than guessing fields

ec_coe_diag_read_messages() / ec_coe_diag_acknowledge()​

int ec_coe_diag_read_messages(uint16_t master, uint16_t slave,
ec_coe_diag_message_t* out, int max_messages,
uint32_t* out_abort_code);
int ec_coe_diag_acknowledge(uint16_t master, uint16_t slave,
uint8_t ack_sub_index, uint32_t* out_abort_code);

Parameters:

  • max_messages (int) — capacity of the out array, supplied by the caller
  • ack_sub_index (uint8_t) — AckMode acknowledgement number: 0 clears all / 6..255 acknowledges up to that record (written to 0x10F3:03)

Returns:

  • ec_coe_diag_read_messages: fetches and parses everything from 6..NewestMessage and returns the number of successful records (a message that fails midway is skipped without interrupting the rest, and the failure reason is written to out_abort_code)
  • ec_coe_diag_acknowledge: 1 success / 0 failure

Related structures:

typedef struct {
uint8_t max_messages; /* 0x10F3:01 buffer capacity */
uint8_t newest_message; /* 0x10F3:02 newest message subindex; 0 = no messages */
uint8_t newest_acknowledged; /* 0x10F3:03 newest acknowledged subindex (stays 0 by spec in Overwrite mode) */
uint16_t flags; /* 0x10F3:05 Flags; bit4 = 0 Overwrite / 1 Acknowledge, bit5 = Overrun */
} ec_coe_diag_meta_t;

typedef struct {
uint8_t sub_index; /* subindex holding the message (6..255) */
uint32_t diag_code; /* ETG.1020 DiagCode */
uint16_t flags; /* message-level Flags */
uint16_t text_index; /* TextID */
uint64_t timestamp; /* slave timestamp (payload off8..15, LE) */
int raw_size; /* total bytes of the raw message */
int data_size; /* actual bytes of data (raw_size - 16, truncated to 32) */
uint8_t data[32]; /* variable-parameter area (off16..) */
} ec_coe_diag_message_t;
Meaning of the Flags bits

Per ETG.1020 v1.5.0 Table 49, flags (0x10F3:05) is defined as:

  • bit4 = diagnostic buffer mode: 0 = Overwrite / 1 = Acknowledge
  • bit5 = 1 means Overrun occurred (the ring buffer has overwritten unread messages)

How to read it: in Overwrite mode the slave keeps newest_acknowledged = 0 by specification; that 0 is a normal value and must not be read as "there are unacknowledged messages", nor may it be inferred from newest_message != newest_acknowledged. In that mode, whether an unread message exists can only be answered by 0x10F3:04 NewAvailable (ec_coe_diag_poll_new()). Only in Acknowledge mode does newest_message != newest_acknowledged indicate unacknowledged messages.

Accessor: the C ec_coe_diag_meta_t only carries the flags field and has no isAcknowledgeMode()-style accessor: test (meta.flags & 0x0010) != 0 (0 = Overwrite, 1 = Acknowledge) and use (meta.flags & 0x0020) != 0 for bit5 (Overrun).

Message payload format (ETG.1020 Table 50): DiagCode(u32) | Flags(u16) | TextID(u16) | Timestamp(u64) | 可变参数. ec_coe_diag_message_t parses it accordingly: data[] is the variable-parameter area (up to 32 bytes, with data_size giving the actual length).

Example (typed interface):

ec_coe_diag_meta_t meta;
uint32_t abort = 0;
if (ec_coe_diag_read_meta(master, 1, &meta, &abort) == 1 && meta.newest_message >= 6) {
ec_coe_diag_message_t msgs[16];
int n = ec_coe_diag_read_messages(master, 1, msgs, 16, &abort);
for (int i = 0; i < n; i++)
printf("Diag[%u] code=0x%08X flags=0x%04X text=0x%04X\n",
msgs[i].sub_index, msgs[i].diag_code,
msgs[i].flags, msgs[i].text_index);
if (ec_coe_diag_poll_new(master, 1, &abort) == 1)
ec_coe_diag_acknowledge(master, 1, meta.newest_message, &abort); /* AckMode */
}

0x10F3 subindex layout​

The diagnostic history object defines its subindexes per ETG.1020 §16, and all of them are read and written through the standard SDO channel:

  • 0x10F3:01 (MaxMessages) — buffer capacity (maximum number of records retained)
  • 0x10F3:02 (NewestMessage) — number of the newest message
  • 0x10F3:03 (NewestAcknowledged) — newest acknowledged number (writing it marks the record as read)
  • 0x10F3:04 (NewMessageAvailable) — whether a new message is available (boolean flag)
  • 0x10F3:05 (Flags) — bit4 selects the mode (0 = Overwrite, 1 = AckMode)
  • 0x10F3:06..FF (Diagnosis Message) — the individual diagnostic messages (DiagCode + Flags + TextID + Timestamp + parameters; see ETG.1020 Table 49)

The usual read flow: read 0x10F3:04 to see whether new messages exist → read 0x10F3:02 to get the newest number → read 0x10F3:05 to determine whether AckMode is used → read the corresponding 0x10F3:06..FF message subindex → on an AckMode slave, write the number to 0x10F3:03 to mark it read, otherwise the buffer is not released.

Example (manual SDO):

uint8_t avail = 0;
uint8_t newest = 0;
uint32_t abort = 0;
int wkc = 0, actual = 0;

/* read 0x10F3:04 to see whether new messages exist */
if (sdo_read_u8(master, 1, 0x10F3, 0x04, &avail) == 0 && avail != 0) {
/* read the newest message number from 0x10F3:02 */
if (sdo_read_u8(master, 1, 0x10F3, 0x02, &newest) != 0)
newest = 0;

/* read the diagnostic message subindex for that number (located by number starting at 0x06) */
uint8_t msg[64];
int rc = sdo_read_typed_ex(master, 1, 0x10F3, newest,
msg, sizeof(msg), &abort, &wkc, &actual);
if (rc == EC_SDO_TYPED_OK && actual >= 4) {
uint32_t diag_code = (uint32_t)msg[0] | ((uint32_t)msg[1] << 8)
| ((uint32_t)msg[2] << 16) | ((uint32_t)msg[3] << 24);
printf("诊断消息 #%u: DiagCode=0x%08X, %d 字节\n", newest, diag_code, actual); /* Diagnostic message #%u: DiagCode=0x%08X, %d bytes */
}

/* AckMode slave: write the number to 0x10F3:03 to mark it read, otherwise the buffer is not released */
sdo_write_u8(master, 1, 0x10F3, 0x03, newest);
}
Thread safety
  • The diagnostic history uses the standard SDO channel and shares the mailbox with other SDO traffic; do not call it from a high-rate PDO thread
  • Poll the 0x10F3:04 flag from a background thread about once every 1 second

SDO request statistics​

CategoryFunctionReturn typeRead/writeDescription
Statisticsec_coe_get_sdo_stats(mi, si, out_requests, out_retries, out_timeouts)intRead-onlyReturns the cumulative SDO request / retry / timeout counts for the slave; 0 = success, negative = failure
#include "ethercat.h"   /* ec_coe_get_sdo_stats is declared in slave/coe.h and pulled in by the umbrella header */

uint32_t requests = 0, retries = 0, timeouts = 0;
int rc = ec_coe_get_sdo_stats(master_index, slave_index,
&requests, &retries, &timeouts);

Parameters:

  • mi / master_index (uint16_t) — master index
  • si / slave_index (uint16_t) — slave index (1-based)
  • out_requests (uint32_t*) — number of newly initiated logical SDO requests (a timeout retransmission does not add 1)
  • out_retries (uint32_t*) — number of retransmissions caused by a timeout / no response
  • out_timeouts (uint32_t*) — cumulative timeout count
  • All three output parameters accept NULL, meaning that value is not needed

Return value / failure semantics:

  • 0 = success, output parameters written
  • A negative value = failure (master does not exist / slave out of range or offline / runtime library unavailable); the output parameters are left unchanged
  • Counts are accounted per (主站, 从站) and reset when the context is initialized or closed; they do not accumulate across sessions

Typical use — proving "sent only once":

uint32_t r0, t0, q0, r1, t1, q1;
ec_coe_get_sdo_stats(mi, si, &r0, &t0, &q0);
/* ... perform one asynchronous / synchronous SDO call ... */
ec_coe_get_sdo_stats(mi, si, &r1, &t1, &q1);
int sent_once = ((r1 - r0) == 1u) && ((t1 - t0) == 0u);

Comparing only the number of completion callbacks cannot distinguish a silent retransmission after a timeout; the requests increment is the test for "really sent only once".

SDO abort codes and failure actions​

CANopen standard SDO abort codes (CiA 301 / ETG.1020), in one-to-one correspondence with the ec_sdo_error_t enum. sdo_read_typed_ex() / sdo_write_typed_ex() can fill out_abort; get the descriptive text with ec_coe_sdo_error_str(code).

Handling for common codes:

CategoryAbort codeRead/writeHandling
No error0x00000000—Normal
Communication / device0x05040000 / 0x08000000—0x05040000 = timeout or no mailbox reply (the device sent no abort code), retryable; 0x08000000 = the device returned a “general error” without a reason, which needs investigating. Neither of them means the object does not exist
Device side0x08000021 / 0x08000022—Abort codes reported by the device: 0x08000021 = the device is in local control, 0x08000022 = the present device state does not allow this transfer. Handle them on the device side and retry after switching to an allowed state; do not treat them as communication failures
Master side0x0D000001 ~ 0x0D000004—The request did not complete and the device returned no abort frame. See Master-side codes for the meaning and handling of each
Access direction0x06010001 / 0x06010002—Wrong direction (reading a write-only object / writing a read-only object): change the call direction
Object does not exist0x06020000—Check the ESI / OD to confirm the index; this is a deterministic failure, so stop retrying
Subindex does not exist0x06090011—Same as above, checked at the subindex level (0x06090012 is a variant code with no matching member in ec_sdo_error_t; print the raw code as unknown)
Access not supported0x06010000—The state or the object does not allow this access: change the state or use PDO instead
Invalid value0x06090030 / 0x06090031 / 0x06090032—Value out of range: correct it to the limits in the OD
Type mismatch0x06070010 / 0x06070012 / 0x06070013—Wrong width: pick the matching sdo_read_* / sdo_write_* for the object type
Already mapped0x06010006 / 0x06040041 / 0x06040042—The object is already used by a PDO or cannot be mapped: release it in the PDO mapping first
Unknown0xFFFFFFFF—Print the raw code and log it

Full abort code table (all ec_sdo_error_t members):

Abort codeMeaning
0x00000000No error
0x05030000Toggle bit not changed
0x05040000SDO protocol timeout
0x05040001Invalid command specifier
0x05040002Invalid block size
0x05040003Invalid sequence number
0x05040004CRC error
0x05040005Out of memory
0x06010000Unsupported access
0x06010001Attempt to read a write-only object
0x06010002Attempt to write a read-only object
0x06010003Subindex cannot be written
0x06010004Complete access not supported
0x06010005Object length exceeded
0x06010006Object already mapped to RxPDO
0x06020000Object does not exist
0x06040041Cannot be mapped to a PDO
0x06040042Exceeds the PDO length
0x06040043Parameter incompatible
0x06040047Internal incompatibility
0x06060000Hardware access error
0x06070010Data type does not match
0x06070012Data type length too large
0x06070013Data type length too small
0x06090011Subindex does not exist
0x06090030Value out of range
0x06090031Value too large
0x06090032Value too small
0x06090033Module list does not match
0x06090036Maximum value less than minimum value
0x060A0023Resource not available
0x05040000SDO protocol timeout (the device sent no abort code; retryable, not a missing object, does not enter NotPresent)
0x08000000General error (the device really returned this code; not a missing object, so it does not enter NotPresent)
0x08000020Data cannot be transferred or stored to the application (reported by the device)
0x08000021Data cannot be transferred or stored to the application because of local control (reported by the device)
0x08000022Data cannot be transferred or stored to the application because of the present device state (reported by the device)
0x08000023Dictionary error
0xFFFFFFFFUnknown error

Master-side codes​

0x0D0000xx are not CiA 301 slave abort codes. They occupy an unassigned range and are only produced by the master side. Seeing one means this SDO failure has no abort frame from the device, so do not go looking in the object dictionary for a device rejection.

CodeMeaningWhat it tells youWhat to do
0x0D000001Request not sent (local reject)Invalid arguments, slave index out of range, the slave does not support CoE, the mailbox is not ready — no frame went on the busFix the arguments, or move the slave to PreOp first; resending as-is will not succeed
0x0D000002Frame transmitted, but no device counted itThe device did not acknowledge the frame and there is no abort frame on the busCheck whether that slave's mailbox is rejecting or full, and check the receive path
0x0D000003Mailbox layer errorThe peer returned a mailbox Error frame; the failure is in the mailbox transaction, not an SDO abortCheck the mailbox SM configuration and the request length
0x0D000004Transport layer failureCancelled, protocol type mismatch, local resource shortage, link down, or the peer is not consumingNo retry for a cancel / master shutdown; restore the link first when it is down; for a protocol mismatch check the mailbox type and SM configuration

The codes a device reports itself — 0x08000020 / 0x08000021 / 0x08000022 — keep their original meaning and differ in value from the four above: the device is saying "I cannot take this data", while a master-side code says "this request did not complete".

Access denied​

ec_coe_can_read / ec_coe_can_write only answer "do the local descriptor and the current state let this through" — they never see the device's reply. Whether one SDO on a real machine counts as rejected is expressed by the shared result struct ec_coe_access_denied_t; the only entry point for the decision is the pure function ec_coe_classify_access_denied().

ec_coe_access_denied_t / ec_coe_access_reason_t​

typedef enum {
EC_COE_ACCESS_REASON_NONE = 0, /* Not access denied*/
EC_COE_ACCESS_REASON_DEVICE = 1, /* The device explicitly refused with an SDO Abort (0x06010000/1/2)*/
EC_COE_ACCESS_REASON_FLAGS = 2, /* The descriptor ObjAccess carries no permission bit for that direction*/
EC_COE_ACCESS_REASON_STATE = 3 /* There is a permission bit but the current AL state does not allow it (read only)*/
} ec_coe_access_reason_t;

typedef struct {
int access_denied; /* 1 = access denied, 0 = passed*/
uint16_t index; /* Object index*/
uint8_t subindex; /* Subindex*/
uint8_t is_read; /* 1 = read refused, 0 = write refused*/
uint16_t obj_access; /* CoE object access bitmask (ec_coe_object_access_t)*/
uint32_t abort_code; /* Device abort code for this SDO (0 = the device sent no abort code)*/
uint32_t reason; /* ec_coe_access_reason_t */
char entry_name[64]; /* Object entry name (fixed buffer; empty string = unknown)*/
char message[192]; /* Error message (fixed buffer; empty string when not refused)*/
} ec_coe_access_denied_t;

entry_name / message are fixed arrays inside the struct and hold no heap pointers: the struct can be copied by value and stored alongside your application state, with nothing to free.

ec_coe_classify_access_denied()​

int ec_coe_classify_access_denied(
ec_coe_access_denied_t* out,
uint16_t obj_access, const char* entry_name, ec_state_t state,
uint32_t abort_code, int is_read,
uint16_t index, uint8_t subindex);

The single criterion for deciding "was this access denied", and a pure function: it touches no bus and calls no runtime library, so it can be unit-tested offline. It takes the first branch that matches, in this order:

CategoryCriterionRead / writeResult
Device abort code winsabort_code != 0read and writeThe device has already given a definite answer for this request; judge from the abort code alone, and do not overturn it with the descriptor
Device abort code wins0x06010000 unsupported object accessread and writeDenied, reason = DEVICE
Device abort code wins0x06010001 reading a write-only objectread onlyDenied, reason = DEVICE
Device abort code wins0x06010002 writing a read-only objectwrite onlyDenied, reason = DEVICE
Device abort code winsany other abort coderead and writenot access denied — object does not exist 0x06020000, subindex does not exist 0x06090011, timeout 0x05040000, generic error 0x08000000 etc. must never be misjudged
Descriptor permission bitsabort_code == 0 and entry_name != NULLread only(obj_access & READ_ANY) == 0 → denied, reason = FLAGS
Descriptor permission bitssame as abovewrite onlyentry_name is an empty string or obj_access == 0 → allow (accessibility is unknown, so the device abort code stays the source of truth)
Descriptor permission bitssame as abovewrite onlyotherwise (obj_access & WRITE_ANY) == 0 → denied, reason = FLAGS
Current AL statedescriptor known, read pathread onlyhand it to ec_coe_access_state_allows(obj_access, state, 1); not allowed → denied, reason = STATE
Current AL statedescriptor known, write pathwrite onlyno denial is decided here (reason below)
Descriptor unknownabort_code == 0 and entry_name == NULLread and writeallow — with no descriptor there is no evidence to deny on (the permission-bit test is skipped entirely)

"State mismatch" is not "access denied". If an object is writable only in OP while the current state is PreOp, the conclusion is "a state change is needed", not "the device or the descriptor refused this access". That is why the write branch of ec_coe_classify_access_denied() never decides STATE; EC_COE_ACCESS_REASON_STATE can only appear on the read path.

Parameters:

  • out (ec_coe_access_denied_t*) — may be NULL when you only want the verdict and not the details; it is zeroed on entry, and on a denial reason and message are filled from the branch that matched
  • obj_access (uint16_t) — the descriptor's ObjAccess bitmask; 0 = not supplied
  • entry_name (const char*) — entry name; NULL = descriptor unknown, empty string = name unknown but the descriptor is present
  • state (ec_state_t) — current AL state; EC_STATE_NONE = unknown
  • abort_code (uint32_t) — the device abort code of this SDO; 0 = the device returned no abort code
  • is_read (int) — 1 = read, 0 = write
  • index / subindex — the object index / subindex being accessed, written back into out unchanged

Returns:

  • 1 = access denied, out is filled (access_denied == 1)
  • 0 = not access denied, out is zeroed (access_denied == 0, reason == EC_COE_ACCESS_REASON_NONE)

ec_coe_get_last_access_denied()​

int ec_coe_get_last_access_denied(ec_coe_access_denied_t* out);

Tells whether the most recent SDO call counted as access denied: 1 = yes (out is filled) / 0 = no, or no SDO call has happened in this process yet.

It is derived from the process-wide "most recent SDO status" slot (the same data source as ec_coe_get_last_sdo_error()), so it adds no state of its own: refresh timing and thread-safety semantics are therefore identical. It is lock-free — concurrent SDO calls from several threads overwrite each other and only the last one survives.

When you need exact per-call attribution (several slaves in parallel, a failure pinned to one particular call), use the out_abort_code output parameter of dx_sdo_read_ex / dx_sdo_write_ex instead — it is independent per call and unaffected by other threads — then feed that abort code together with the descriptor into ec_coe_classify_access_denied().

Example (production path):

int size = 0;
char* data = dx_sdo_read(master, 1, 0x6041, 0x00, FALSE, &size);
if (data == NULL) {
ec_coe_access_denied_t ad;
if (ec_coe_get_last_access_denied(&ad)) {
/* Filled in: ad.reason / ad.index / ad.subindex / ad.is_read / ad.abort_code / ad.message*/
printf("访问被拒 (reason=%u): %s\n", ad.reason, ad.message); /* Access denied (reason=%u): %s */
} else {
printf("读取失败, 但不是访问被拒 (通信失败 / 对象不存在等)\n"); /* Read failed, but not access denied (communication failure / object does not exist, etc.) */
}
} else {
FreeMemory(data);
}

SDO status record (ec_coe_sdo_status_t)​

When the "most recent SDO result" must travel with your application state, record it with the status structure from slave/coe.h:

typedef struct {
ec_sdo_error_t code; /* SDO Abort Code (0 = success) */
uint16_t index; /* object index that caused the error */
uint8_t subindex; /* subindex that caused the error */
uint8_t is_read; /* 1 = read operation, 0 = write operation */
} ec_coe_sdo_status_t;

int ec_coe_sdo_is_ok(const ec_coe_sdo_status_t* s); /* 1 = success */
const char* ec_coe_sdo_error_str(ec_sdo_error_t code); /* converts an error code to readable text */
void ec_coe_sdo_status_set(ec_coe_sdo_status_t* s, ec_sdo_error_t code,
uint16_t index, uint8_t subindex, int is_read);
void ec_coe_sdo_status_reset(ec_coe_sdo_status_t* s);

Process-wide last status (same semantics as last_sdo_error in the other 5 languages):

int  ec_coe_get_last_sdo_error(ec_coe_sdo_status_t* out);  /* 1 = a record exists / 0 = no SDO call has been made yet */
void ec_coe_clear_last_sdo_error(void);

dx_sdo_read / dx_sdo_write (and ec_coe_read_multiple) refresh this slot automatically after every return. A failure without an Abort Code (a communication-level failure) is recorded as EC_SDO_PROTOCOL_TIMEOUT, so ec_coe_sdo_is_ok() can never mistake a failure for success. The slot is a single process-wide value: with concurrent threads it is overwritten by the last call, so for exact per-call attribution use the out_abort / out_wkc output parameters of sdo_read_typed_ex / sdo_write_typed_ex instead.

The same slot is also the data source for ec_coe_get_last_access_denied() — it derives "whether the most recent failure was an access denied" from it and keeps no separate state; for the structure, the criteria and the usage see Access denied.

Example:

ec_coe_sdo_status_t st;
ec_coe_sdo_status_reset(&st);

uint16_t sw = 0;
uint32_t abort = 0;
int wkc = 0, actual = 0;
int rc = sdo_read_typed_ex(master, 1, 0x6041, 0x00, &sw, sizeof(sw),
&abort, &wkc, &actual);
if (rc != EC_SDO_TYPED_OK) {
ec_coe_sdo_status_set(&st, (ec_sdo_error_t)abort, 0x6041, 0x00, 1);
printf("SDO 失败: %s (abort=0x%08X, wkc=%d)\n", /* SDO failure: %s (abort=0x%08X, wkc=%d) */
ec_coe_sdo_error_str(st.code), abort, wkc);
}

Full example​

#include "ethercat.h"
#include "ethercat_advanced.h"
#include <stdio.h>

int main(void)
{
uint16_t master = Initialize();
if (master == 0 || master == (uint16_t)-1) return 1; /* returns (uint16_t)-1 on failure */
uint16_t slaves_found = SetNetwork(master, "\\Device\\NPF_{...}", "");
if (slaves_found == 0 || slaves_found == (uint16_t)-1) return 1; /* >0 = number of slaves found by the scan */
if (!SetStateSequence(master, EC_STATE_OPERATIONAL, 10000)) return 1;
if (!Start(master)) return 1;

/* read StatusWord — always check the return value */
uint16_t sw;
if (sdo_read_u16(master, 1, 0x6041, 0, &sw) != 0)
printf("SDO 读取失败 (超时 / 通信失败,不是对象不存在)\n"); /* SDO read failed (timeout / communication failure, not a missing object) */
else
printf("StatusWord: 0x%04X\n", sw);

/* load the OD main indexes. An empty dictionary is not success */
od_list_t* od = od_load(master, 1, FALSE);
if (od == NULL || od->count == 0) {
printf("对象字典加载失败\n"); /* Object dictionary load failed */
} else {
for (int i = 0; i < od->count; i++)
printf("0x%04X: %s\n", od->objects[i].index, od->objects[i].name);
od_free(od);
}

printf("EMCY 消息数: %d\n", EmcyGetCount(master, 1)); /* EMCY message count: %d */

Stop(master);
Dispose(master);
return 0;
}

Object dictionary pointers and multi-slave batch reads​

This section covers the low-level pointer entry points and the multi-slave batch entry point that complement "Object dictionary access". The OD table / OE table are runtime-internal structures, returned to C as void* in the public header: do not interpret them through the count / objects fields of the public od_list_t, and do not free them yourself across the runtime boundary.

CategoryFunctionReturn typeRead/writeDescription
Single-slave OE tableGetSlavePointer_SDO(mi, si, OE_index)void* (a runtime-allocated oe_list_t)read-onlyReads the entry table of one object by position in the main index table; release with DarraEcat_coe_free_oelist
Single-slave OE tableGetSlavePointer_SDO_WithODList(mi, si, OE_index, odlist)void* (same)read-onlyReuses an existing caller OD main index table to avoid reading it twice; odlist is borrowed and not released
Single-object valueGetSlavePointer_SDO_Value(mi, si, OD_index, OE_index, out_byte_size)char*read-onlyReads the raw bytes of an object subindex; release with FreeMemory()
Single-object valueGetSlavePointer_SDO_IndexValue(mi, si, index, subidx, out_byte_size)char*read-onlySame, with index / subidx given directly; release with FreeMemory()
Multi-slave batchGetMultiSlaveSDOList(mi, slave_indices, count, results)intread-onlyReads OD lists from several slaves in a pipelined batch; returns the number of slaves that succeeded
Batch releaseFreeMultiSlaveSDOList(results, count)voidwrite-onlyReleases the per-slave OD lists allocated by the previous entry point; must always be paired with it

GetSlavePointer_SDO() / GetSlavePointer_SDO_WithODList()​

void* GetSlavePointer_SDO(uint16_t master_index, uint16_t slave_index,
uint16_t OE_index);
void* GetSlavePointer_SDO_WithODList(uint16_t master_index, uint16_t slave_index,
uint16_t OE_index, void* odlist);

Reads the sub-entry table (OE table) for one main index, used to list which subindexes an object has.

Parameters:

  • master_index / slave_index (uint16_t) — master / slave index (1-based)
  • OE_index (uint16_t) — position in the OD main index table (starting at 0), not the object index (such as 0x6041). The position corresponds one-to-one with the main index table returned by GetSlaveSDOListBasic() / GetSlaveSDOList()
  • odlist (void*) — used only by the _WithODList entry point; pass an existing main index table (for example the return value of GetSlaveSDOListBasic()). The table is borrowed and the function does not release it

Return value:

  • A runtime-allocated oe_list_t (written as void* in the C public header); NULL on failure (the slave does not support CoE, the state is not yet readable, OE_index is out of range, or the read failed)

Ownership and release:

  • The return value is allocated by the runtime and must be released exactly once with the dedicated DarraEcat_coe_free_oelist (referred to as coe_free_oelist in the header comment)
  • Do not substitute FreeMemory() / free() — releasing across the runtime boundary is unsafe
  • Each call returns an independent memory block; do not read it after release and do not release the same pointer twice
  • odlist in _WithODList is owned by the caller: the function only borrows it and does not release it. The caller must still release it under the rules of the original entry point (the return values of GetSlaveSDOListBasic() / GetSlaveSDOList() are released with DarraEcat_coe_free_odlist) and keep it valid for the duration of the call

Relationship: GetSlavePointer_SDO() reads its own copy of the main index table on every call, which suits looking up one object at a time; GetSlavePointer_SDO_WithODList() reuses an existing caller main index table, which suits expanding several objects of the same slave in a loop without re-reading the table for each lookup. The two return values are independent and are released separately.

GetSlavePointer_SDO_Value() / GetSlavePointer_SDO_IndexValue()​

char* GetSlavePointer_SDO_Value(uint16_t master_index, uint16_t slave_index,
uint16_t OD_index, uint8_t OE_index,
int* out_byte_size);
char* GetSlavePointer_SDO_IndexValue(uint16_t master_index, uint16_t slave_index,
uint16_t index, uint8_t subidx,
int* out_byte_size);

Reads the raw bytes of one object value. Both are low-level entry points: _Value uses OD_index + OE_index in its names, _IndexValue uses index + subidx.

Parameters:

  • master_index / slave_index (uint16_t) — master / slave index (1-based)
  • OD_index / index (uint16_t) — object main index, such as 0x6041
  • OE_index / subidx (uint8_t) — subindex under the target object (0..255). Note the difference from the previous section: the OE_index of GetSlavePointer_SDO() is a position in the main index table, while the OE_index here is a subindex
  • out_byte_size (int*) — required output parameter: on success it receives the actual byte count, on failure 0; passing NULL is treated as a failure

Return value:

  • char* — a runtime-allocated byte buffer; it must be released exactly once with FreeMemory()
  • NULL on failure, with *out_byte_size = 0 (a missing object, an SDO Abort and a communication failure all take this path)
  • Only raw bytes are returned; no type conversion or byte-order handling is done. To read by type, use typed entry points such as sdo_read_u16()
  • This entry point does not return an Abort Code / WKC; to distinguish a protocol-level Abort from a communication-level failure, use the SDO read/write entry points with _ex (see "Reads and writes with a failure reason")

GetMultiSlaveSDOList() / FreeMultiSlaveSDOList()​

int  GetMultiSlaveSDOList(uint16_t master_index, uint16_t* slave_indices,
int count, void** results);
void FreeMultiSlaveSDOList(void** results, int count);

Reads the object dictionary list (OD list) of several slaves in one call. The batch is pipelined in parallel, so the total time is close to reading one slave instead of growing linearly with the number of slaves.

Parameters:

  • slave_indices (uint16_t*) — array of slave indices, 1-based, at least count long
  • count (int) — number of slaves, allowed range 1..16; out of range returns 0 immediately
  • results (void**) — a pointer array prepared by the caller, at least count slots; the runtime writes each slave's result into results[i]

Return value:

  • int — the number of slaves actually read, not count; map back to slave_indices by position
  • results[i] == NULL means that slave was not read (CoE unsupported / state not satisfied / read failed)
  • Returns 0 for invalid arguments, an out-of-range count, or when nothing could be read

Ownership:

  • The results array container is prepared by the caller; the runtime only allocates the OD list memory block that each successful slot points to
  • Call FreeMultiSlaveSDOList(results, count) on the whole group when done; it releases each slave's memory block and sets the corresponding entry to NULL
  • Do not substitute FreeMemory() / free(), and do not release only some entries; do not read an entry after it has been released

Example:

/* Batch-read the OD lists of two stations*/
uint16_t slaves[2] = { 1, 2 };
void* od_lists[2] = { NULL, NULL };

int ok = GetMultiSlaveSDOList(master, slaves, 2, od_lists);
printf("成功读取 %d/%d 个从站\n", ok, 2); /* Successfully read %d/%d slaves */

for (int i = 0; i < 2; i++) {
if (od_lists[i] != NULL) {
/* od_lists[i] is that slave's internal OD list block; use it as an opaque handle*/
}
}

FreeMultiSlaveSDOList(od_lists, 2); /* Released in pairs; the fields are NULL after release*/

/* Read one object value from a single station*/
int bytes = 0;
char* raw = GetSlavePointer_SDO_Value(master, 1, 0x6041, 0x00, &bytes);
if (raw != NULL) {
printf("0x6041:00 = %d 字节\n", bytes); /* 0x6041:00 = %d bytes */
FreeMemory(raw); /* Exactly once; do not use coe_free_**/
}