SoE (Servo over EtherCAT)
Accessed through ethercat_advanced.h and slave/soe.h — a master index, a slave index and an axis number address one servo.
SoE carries SERCOS servo parameters in the EtherCAT mailbox and addresses them with 16-bit IDNs: parameter values can be read and written by type, and a parameter's name and unit can be fetched separately. Most servos use CoE + CiA 402; SoE applies only to SERCOS-compatible servo devices (such as the Bosch Rexroth IndraDrive series), and one slave cannot mix the two protocols. When parameter changes need to be tracked, enable notification monitoring for the IDNs of interest.
Most EtherCAT servo drives use the CoE + CiA 402 stack.
SoE is only for SERCOS-compatible drives (such as the Bosch Rexroth IndraDrive series).
The two cannot be mixed — which one a slave supports depends on the hardware. Check the return value of GetSlaveSoEDetails(master_index, slave) to tell whether a slave supports SoE (a value other than 0 means it does).
When you need to distinguish support / no support / unknown, use the tri-state query ec_slave_get_proto_support_state(master, slave, MBXPROT_SOE). For SoE, SII General soe_details bit0 can give a definitive negative answer (NO); when it cannot be read, the answer is UNKNOWN.
Function overview
| Category | Function | Type | Read/write | Description |
|---|---|---|---|---|
| Parameter read/write | soe_read_i32 / soe_write_i32 | int | read / write | Read and write 32-bit signed values by IDN; the same family also has 16/64-bit, unsigned and floating-point variants |
| Parameter read/write | soe_read_string | int | read | Read a string element; returns the number of bytes written, or -1 on failure |
| Raw read/write | dx_soe_read / dx_soe_write | BOOL | read / write | Read and write raw bytes by element flag; use SOE_ELEM_VALUE for the data value and combine other flags for name, unit, attributes and so on |
| IDN encoding | soe_idn_encode | int32_t | read | Encode a 16-bit IDN from (standard/vendor, parameter set, data block); returns -1 when a parameter is out of range |
| IDN decoding | soe_idn_decode | void | read | Split a 16-bit IDN into the standard/vendor flag, the parameter set and the data block |
| Parameter information | dx_soe_read_name / dx_soe_read_unit | BOOL | read | Read the IDN name / unit; free the returned string with FreeMemory |
| Parameter information | dx_soe_read_attributes | BOOL | read | Read the IDN data attribute bit field (data type / length / access rights) |
| Parameter information | dx_soe_read_min_max | BOOL | read | Read the IDN minimum and maximum bytes in one call; free both buffers with FreeMemory |
| Parameter information | dx_soe_read_idn_list | BOOL | read | Read the list of IDNs the slave supports, and their count |
| Notifications | soe_notifier_create / soe_notifier_destroy | soe_notifier_t* / void | write | Create / destroy a parameter change notifier |
| Notifications | soe_enable_notification / soe_disable_notification | int / void | write | Enable / disable change notification for an IDN; enable returns 1 for hardware notification, 0 for polling, -1 if not registered |
| Notifications | soe_poll_notifications | int | read | Poll the monitored IDNs and report changes through the callback; returns the number of changes |
| Notifications | soe_notification_free | void | write | Release the old and new value buffers of a callback event |
| Emergency message | DarraEcat_RegisterSoEEmergencyCallback / DarraEcat_UnregisterSoEEmergencyCallback | void | write | Legacy registration entry points kept for compatibility only; nothing triggers them today, and OpCode=6 traffic goes through the notification channel (see "Emergency message callback") |
| Error codes | EcSoEErrorCodeFromRaw | ec_soe_error_t | read | Convert a raw 16-bit code to the enum; values outside the table return EC_SOE_ERROR_UNKNOWN, and EcSoE_GetErrorDescription gives the text description |
The SERCOS IDN scheme
SoE addresses drive parameters through the IDN (Identification Number). Each IDN is a 16-bit number that identifies one parameter (position, diagnostics, control word and so on). The bit layout is fixed: bit15 = 0 for an S standard parameter, 1 for a P vendor parameter; bits14..12 are the parameter set (0..7); bits11..0 are the data block (0..0xFFF). For example the IDN of S-0-0051 is 0x0033 and the IDN of P-0-1000 is 0x83E8.
IDN naming rules:
| Prefix | Range | Description |
|---|---|---|
| S-x-xxxx | 0x0000 – 0x7FFF | SERCOS standard parameters (common to all vendors, standard bit = 0) |
| P-x-xxxx | 0x8000 – 0xFFFF | Product / vendor-specific parameters (standard bit = 1, is_standard = 0 for soe_idn_encode) |
Common standard IDNs (servo control related):
| IDN | SERCOS name | Description | Data type |
|---|---|---|---|
| S-0-0001 (0x0001) | Cycle Time | Communication cycle time | uint, µs |
| S-0-0011 (0x000B) | Class 1 Diagnostics | Class 1 diagnostic code | ushort |
| S-0-0012 (0x000C) | Class 2 Diagnostics | Class 2 diagnostic code | ushort |
| S-0-0047 (0x002F) | Position Command | Position command | int, inc |
| S-0-0051 (0x0033) | Position Feedback 1 | Position feedback 1 | int, inc |
S-0-0011 (0x000B) and S-0-0012 (0x000C) are the Class 1 / Class 2 diagnostic codes (UINT16), not position values; position feedback uses S-0-0051 (0x0033) and position command uses S-0-0047 (0x002F). Reading a diagnostic code as a 32-bit position gives a number with no physical meaning. For the meaning and data type of other IDNs, refer to the servo device manual.
Element flags — reading different "layers" of an IDN:
| Flag | Meaning |
|---|---|
| 0x01 | Data status |
| 0x02 | Parameter name (string) |
| 0x04 | Attributes (data type/length/access rights bit field) |
| 0x08 | Unit (string) |
| 0x10 | Minimum value |
| 0x20 | Maximum value |
| 0x40 | Data value (default, most common) |
| 0x80 | Default value |
Element flag constant macros
slave/soe.h defines the following macros, which describe different "layers" of an IDN (ETG.1000.6 §5.11, a 7-bit mask that can be OR-combined):
#define SOE_ELEM_NONE 0x00 /* none */
#define SOE_ELEM_DATA_STATUS 0x01 /* data status word (valid/invalid/busy) */
#define SOE_ELEM_NAME 0x02 /* IDN name string */
#define SOE_ELEM_ATTRIBUTE 0x04 /* data attributes (data type/length/access rights bit field) */
#define SOE_ELEM_UNIT 0x08 /* unit string */
#define SOE_ELEM_MIN 0x10 /* minimum value */
#define SOE_ELEM_MAX 0x20 /* maximum value */
#define SOE_ELEM_VALUE 0x40 /* operating data value (most common) */
#define SOE_ELEM_DEFAULT 0x80 /* default value */
Example:
/* use dx_soe_read_name for a parameter name; use a raw read with the flag for numeric elements such as the maximum */
char* name = NULL;
int len = 0;
dx_soe_read_name(master, 1, 0, 0x0033, &name, &len, 500);
if (name) FreeMemory(name);
char* max_raw = NULL;
int n = 0;
if (dx_soe_read(master, 1, 0, SOE_ELEM_MAX, 0x0033, &max_raw, &n, 500)) {
/* interpret max_raw[0..n-1] according to this IDN's data type */
FreeMemory(max_raw);
}
soe_idn_encode()
int32_t soe_idn_encode(int is_standard, uint8_t parameter_set, uint16_t data_block);
Packs the (standard/vendor, parameter set, data block) triple into a 16-bit IDN (pure bit arithmetic).
Parameters:
- is_standard (int) — a value other than 0 = S-x-xxxx (SERCOS standard IDN); 0 = P-x-xxxx (vendor IDN)
- parameter_set (uint8_t) — parameter set, 0..7
- data_block (uint16_t) — data block number, 0..0xFFF
Return value:
- int32_t — the 16-bit IDN on success; -1 (DARRA_READ_FAIL_INT) when a parameter is out of range, detected with DARRA_IS_READ_FAIL_INT; values are never silently truncated
Example:
#include "slave/soe.h"
/* S-0-0051 position feedback 1: standard IDN, Set=0, Block=51 */
int32_t idn = soe_idn_encode(1, 0, 51);
if (DARRA_IS_READ_FAIL_INT(idn)) {
printf("参数超范围\n"); /* Parameter out of range */
} else {
printf("IDN = 0x%04X\n", (uint16_t)idn); /* 0x0033 */
}
soe_idn_decode()
void soe_idn_decode(uint16_t idn,
int* is_standard, uint8_t* parameter_set, uint16_t* data_block);
Splits a 16-bit IDN into the standard/vendor flag, the parameter set and the data block. All three output pointers may be NULL.
Parameters:
- idn (uint16_t) — IDN to split
- is_standard (int*) — output: 1 = S standard, 0 = P vendor; may be NULL
- parameter_set (uint8_t*) — output: parameter set; may be NULL
- data_block (uint16_t*) — output: data block number; may be NULL
Return value: none
Example:
int is_std;
uint8_t set;
uint16_t block;
soe_idn_decode(0x83E8, &is_std, &set, &block);
printf("%c-%u-%04u\n", is_std ? 'S' : 'P', set, block); /* P-0-1000 */
Typed read and write (ethercat_advanced.h)
ethercat_advanced.h provides typed SoE read and write functions. They read and write the data value element (SOE_ELEM_VALUE) by IDN and handle type conversion automatically (ETG wire order, little-endian).
soe_read_i16() / soe_read_i32() / soe_read_u16() / soe_read_u32() / soe_read_i64() / soe_read_u64() / soe_read_f32() / soe_read_f64()
int soe_read_i16(uint16_t master, uint16_t slave, uint8_t drive, uint16_t idn, int16_t* out);
int soe_read_i32(uint16_t master, uint16_t slave, uint8_t drive, uint16_t idn, int32_t* out);
int soe_read_u16(uint16_t master, uint16_t slave, uint8_t drive, uint16_t idn, uint16_t* out);
int soe_read_u32(uint16_t master, uint16_t slave, uint8_t drive, uint16_t idn, uint32_t* out);
int soe_read_i64(uint16_t master, uint16_t slave, uint8_t drive, uint16_t idn, int64_t* out);
int soe_read_u64(uint16_t master, uint16_t slave, uint8_t drive, uint16_t idn, uint64_t* out);
int soe_read_f32(uint16_t master, uint16_t slave, uint8_t drive, uint16_t idn, float* out);
int soe_read_f64(uint16_t master, uint16_t slave, uint8_t drive, uint16_t idn, double* out);
Reads the data value by IDN and decodes it into the corresponding type. All types share one shape; only the output pointer type differs.
Parameters:
- master (uint16_t) — master index
- slave (uint16_t) — slave index
- drive (uint8_t) — drive number (0 for a single-axis servo)
- idn (uint16_t) — IDN number
- out (pointer to the corresponding type) — output: the value read back
Return value:
- 0 — success, out has been written
- -1 — failure (out is NULL, the IDN is not implemented, write protection, state not allowed, mailbox timeout, or the read-back length is insufficient); the exact cause is not distinguished, and out is not guaranteed to be written on failure
Example:
/* read position feedback S-0-0051 (IDN 0x0033) */
int32_t position = 0;
if (soe_read_i32(master, 1, 0, 0x0033, &position) != 0) {
printf("读取 IDN 0x0033 失败\n"); /* Failed to read IDN 0x0033 */
} else {
printf("位置反馈: %d\n", position); /* Position feedback: %d */
}
soe_read_string()
int soe_read_string(uint16_t master, uint16_t slave, uint8_t drive, uint16_t idn,
char* buf, int buf_size);
Reads the string content of the data value element by IDN, appends the terminating NUL automatically and truncates over-long values. For string elements such as parameter name / unit, use dx_soe_read_name / dx_soe_read_unit.
Parameters:
- master (uint16_t) — master index
- slave (uint16_t) — slave index
- drive (uint8_t) — drive number
- idn (uint16_t) — IDN number
- buf (char*) — output buffer
- buf_size (int) — buffer capacity (including room for the terminating NUL)
Return value:
- int — on success, the number of bytes written to buf (excluding the terminating NUL); -1 on failure
Example:
char text[64] = {0};
if (soe_read_string(master, 1, 0, 0x0033, text, sizeof(text)) >= 0)
printf("值: %s\n", text); /* Value: %s */
soe_write_i16() / soe_write_i32() / soe_write_u16() / soe_write_u32() / soe_write_f32() / soe_write_f64()
int soe_write_i16(uint16_t master, uint16_t slave, uint8_t drive, uint16_t idn, int16_t val);
int soe_write_i32(uint16_t master, uint16_t slave, uint8_t drive, uint16_t idn, int32_t val);
int soe_write_u16(uint16_t master, uint16_t slave, uint8_t drive, uint16_t idn, uint16_t val);
int soe_write_u32(uint16_t master, uint16_t slave, uint8_t drive, uint16_t idn, uint32_t val);
int soe_write_f32(uint16_t master, uint16_t slave, uint8_t drive, uint16_t idn, float val);
int soe_write_f64(uint16_t master, uint16_t slave, uint8_t drive, uint16_t idn, double val);
Writes the data value by IDN and encodes it into the corresponding type. All types share one shape; only the value type differs.
Parameters:
- master (uint16_t) — master index
- slave (uint16_t) — slave index
- drive (uint8_t) — drive number (0 for a single-axis servo)
- idn (uint16_t) — IDN number
- val (corresponding type) — value to write
Return value:
- 0 — success
- -1 — failure (the IDN is not implemented, write protection, state not allowed, or mailbox timeout); the exact cause is not distinguished
Example:
/* write position command S-0-0047 (IDN 0x002F) */
if (soe_write_i32(master, 1, 0, 0x002F, 100000) != 0) {
printf("写入 IDN 0x002F 失败\n"); /* Failed to write IDN 0x002F */
}
Raw read and write (slave/soe.h)
Reads and writes raw bytes by element flag; this is the generic channel beneath the typed entry points. Use SOE_ELEM_VALUE for the data value and the respective flags for name, unit, attributes, minimum/maximum and default value; OR them together to read several items in one call.
dx_soe_read()
BOOL dx_soe_read(uint16_t master_index, uint16_t slave, uint8_t drive_no,
uint8_t element_flags, uint16_t idn,
char** data, int* data_size, int timeout);
Reads the raw bytes of an IDN by element flag.
Parameters:
- master_index (uint16_t) — master index
- slave (uint16_t) — slave index
- drive_no (uint8_t) — drive number
- element_flags (uint8_t) — element flags (SOE_ELEM_*); use SOE_ELEM_VALUE for the data value
- idn (uint16_t) — IDN number
- data (char**) — output: buffer of the bytes read back; free it with FreeMemory
- data_size (int*) — output: number of bytes read back
- timeout (int) — timeout in milliseconds
Return value:
- BOOL — TRUE on success (both outputs have been written); FALSE on failure, in which case the outputs are not guaranteed to be written
Example:
char* raw = NULL;
int n = 0;
if (dx_soe_read(master, 1, 0, SOE_ELEM_VALUE, 0x0033, &raw, &n, 500)) {
/* interpret raw[0..n-1] according to the device definition */
FreeMemory(raw);
}
dx_soe_write()
BOOL dx_soe_write(uint16_t master_index, uint16_t slave, uint8_t drive_no,
uint8_t element_flags, uint16_t idn,
const char* data, int data_size, int timeout);
Writes the raw bytes of an IDN by element flag.
Parameters:
- master_index (uint16_t) — master index
- slave (uint16_t) — slave index
- drive_no (uint8_t) — drive number
- element_flags (uint8_t) — element flags (SOE_ELEM_*)
- idn (uint16_t) — IDN number
- data (const char*) — bytes to write
- data_size (int) — number of bytes
- timeout (int) — timeout in milliseconds
Return value:
- BOOL — TRUE when the write succeeded; FALSE on failure (the IDN is not implemented, write protection, state not allowed, or mailbox timeout)
Parameter information (slave/soe.h)
Dedicated read entry points for name, unit, attributes, value range and IDN list. String and list outputs are allocated by the SDK and must be freed with FreeMemory; on failure the outputs are not guaranteed to be written.
dx_soe_read_name() / dx_soe_read_unit()
BOOL dx_soe_read_name(uint16_t master_index, uint16_t slave, uint8_t drive_no,
uint16_t idn, char** name, int* name_length, int timeout);
BOOL dx_soe_read_unit(uint16_t master_index, uint16_t slave, uint8_t drive_no,
uint16_t idn, char** unit, int* unit_length, int timeout);
Reads the name string and unit string of an IDN.
Parameters:
- master_index (uint16_t) — master index
- slave (uint16_t) — slave index
- drive_no (uint8_t) — drive number
- idn (uint16_t) — IDN number
- name / unit (char**) — output: string buffer; free it with FreeMemory
- name_length / unit_length (int*) — output: string length
- timeout (int) — timeout in milliseconds
Return value:
- BOOL — TRUE on success; FALSE on failure, in which case the outputs are not guaranteed to be written
Example:
char* name = NULL;
int len = 0;
if (dx_soe_read_name(master, 1, 0, 0x0033, &name, &len, 500)) {
printf("名称: %s\n", name); /* Name: %s */
FreeMemory(name);
}
dx_soe_read_attributes()
BOOL dx_soe_read_attributes(uint16_t master_index, uint16_t slave, uint8_t drive_no,
uint16_t idn, uint32_t* attributes, int timeout);
Reads the data attribute bit field of an IDN (data type / length / access rights); the bit definitions follow the device's SERCOS attribute format.
Parameters:
- master_index (uint16_t) — master index
- slave (uint16_t) — slave index
- drive_no (uint8_t) — drive number
- idn (uint16_t) — IDN number
- attributes (uint32_t*) — output: attribute bit field
- timeout (int) — timeout in milliseconds
Return value:
- BOOL — TRUE on success; FALSE on failure, in which case the output is not guaranteed to be written
dx_soe_read_min_max()
BOOL dx_soe_read_min_max(uint16_t master_index, uint16_t slave, uint8_t drive_no,
uint16_t idn, char** min_value, int* min_size,
char** max_value, int* max_size, int timeout);
Reads the minimum and maximum values of an IDN (raw bytes) in one call.
Parameters:
- master_index (uint16_t) — master index
- slave (uint16_t) — slave index
- drive_no (uint8_t) — drive number
- idn (uint16_t) — IDN number
- min_value (char**) — output: minimum value bytes; free with FreeMemory
- min_size (int*) — output: number of minimum value bytes
- max_value (char**) — output: maximum value bytes; free with FreeMemory
- max_size (int*) — output: number of maximum value bytes
- timeout (int) — timeout in milliseconds
Return value:
- BOOL — TRUE on success (all four outputs have been written); FALSE on failure, in which case the outputs are not guaranteed to be written
dx_soe_read_idn_list()
BOOL dx_soe_read_idn_list(uint16_t master_index, uint16_t slave, uint8_t drive_no,
uint16_t** idn_list, int* list_count, int timeout);
Reads the list of IDNs the slave supports.
Parameters:
- master_index (uint16_t) — master index
- slave (uint16_t) — slave index
- drive_no (uint8_t) — drive number
- idn_list (uint16_t**) — output: array of IDNs; free it with FreeMemory
- list_count (int*) — output: number of IDNs
- timeout (int) — timeout in milliseconds
Return value:
- BOOL — TRUE on success; FALSE on failure, in which case the outputs are not guaranteed to be written
AT/MDT mapping
A slave's AT (slave → master) / MDT (master → slave) PDO mapping is given by two configuration IDNs: AT configuration = S-0-0016 (0x0010), MDT configuration = S-0-0024 (0x0018). Read the configuration bytes with dx_soe_read (SOE_ELEM_VALUE), or enumerate the IDNs that appear in the mapping with dx_soe_read_idn_list, to locate the byte offset of a key IDN in the cyclic frame.
The configuration data is a little-endian list: the first 2 bytes are the list length in bytes, the next 2 bytes are reserved, and each entry after that is a 2-byte little-endian IDN. Each IDN's bit length is derived from its attribute length field (0 = 16 bits, 1 = 32 bits, 2 = 64 bits, 3 = cannot be determined); the status word / control word of the first entry counts as a fixed 16 bits per SERCOS. When the configuration cannot be read, that direction's mapping is unknown — do not guess 16 bits.
For a multi-axis slave, enumerate the AT/MDT mapping axis by axis using drive_number; this is common for a uniform scan of multi-axis servos.
Procedure commands
SERCOS procedure commands (such as S-0-0099 reset and S-0-0148 homing) are started by writing the command value with a typed write (commonly 0x0003; see the device manual), then polling the data status element (SOE_ELEM_DATA_STATUS) of that IDN until the command completes: bit0 = command active, bit1 = command error. Always wait with a timeout; a command is not re-entrant (the device returns EC_SOE_ERROR_PROCEDURE_COMMAND_ALREADY_ACTIVE).
Example:
/* trigger the homing command S-0-0148 (IDN 0x0094) */
soe_write_u16(master, 1, 0, 0x0094, 0x0003);
char* st = NULL;
int n = 0;
for (int i = 0; i < 100; i++) {
if (dx_soe_read(master, 1, 0, SOE_ELEM_DATA_STATUS, 0x0094, &st, &n, 500) && st && n >= 1) {
uint8_t data_state = (uint8_t)st[0];
if (data_state & 0x02) { printf("命令出错\n"); } /* Command error */
else if (!(data_state & 0x01)) { printf("命令完成\n"); } /* bit0 clears = done */
}
if (st) { FreeMemory(st); st = NULL; }
}
Parameter change notifications (ethercat_advanced.h)
Monitors changes of IDN parameters on a SERCOS slave and reports them through a callback. When monitoring is enabled, the SDK first writes S-0-0127 (notification request) to try the slave's hardware notification (OpCode 5) and registers polling monitoring regardless of the outcome; when the slave does not support hardware notification it falls back to polling automatically (periodic reads compared against a baseline). Both modes are transparent to the application layer.
Notification structure and types
/* notification event parameters */
typedef struct {
uint16_t slave_index; /* slave index */
uint8_t drive_number; /* drive number */
uint16_t idn; /* IDN number that changed */
uint8_t* new_value; /* new value (release with soe_notification_free()) */
int new_value_size; /* new value size */
uint8_t* old_value; /* old value (release with soe_notification_free()) */
int old_value_size; /* old value size */
} soe_notification_t;
/* notification callback type */
typedef void (*soe_notification_callback_t)(const soe_notification_t* event, void* user_data);
soe_notifier_create()
soe_notifier_t* soe_notifier_create(uint16_t master, uint16_t slave, uint8_t drive);
Creates a notifier instance. For a multi-drive slave, create a separate instance for each drive_number.
Parameters:
- master (uint16_t) — master index
- slave (uint16_t) — slave index
- drive (uint8_t) — drive number
Return value:
- soe_notifier_t* — notifier instance; release it with soe_notifier_destroy(). NULL when allocation fails
soe_notifier_destroy()
void soe_notifier_destroy(soe_notifier_t* notifier);
Destroys the notifier and releases its monitoring table and baseline cache.
Parameters:
- notifier (soe_notifier_t*) — notifier instance
Return value: none
soe_enable_notification()
int soe_enable_notification(soe_notifier_t* notifier, uint16_t idn, int timeout_ms);
Enables parameter change notification for the given IDN. The call first tries to enable hardware notification through S-0-0127, and registers the IDN in the polling monitor list whether or not that succeeds (registering the same IDN again returns the current mode).
Parameters:
- notifier (soe_notifier_t*) — notifier instance
- idn (uint16_t) — IDN number to monitor
- timeout_ms (int) — timeout in milliseconds
Return value:
- 1 — the slave confirmed hardware notification (the S-0-0127 write succeeded)
- 0 — fell back to polling mode (registered)
- -1 — not registered (notifier is NULL, or the monitor table is full and the entry was dropped); a dropped entry is never silently reported as 0
soe_disable_notification()
void soe_disable_notification(soe_notifier_t* notifier, uint16_t idn);
Disables parameter change notification for the given IDN and removes it from the monitor list.
Parameters:
- notifier (soe_notifier_t*) — notifier instance
- idn (uint16_t) — IDN number to disable
Return value: none
soe_disable_all_notifications()
void soe_disable_all_notifications(soe_notifier_t* notifier);
Disables all enabled notifications and clears the monitor list.
Parameters:
- notifier (soe_notifier_t*) — notifier instance
Return value: none
soe_poll_notifications()
int soe_poll_notifications(soe_notifier_t* notifier, int timeout_ms,
soe_notification_callback_t callback, void* user_data);
Polls all monitored IDNs for parameter changes: each current value is read and compared with the previously recorded value, and the callback is invoked when a change is found. Suitable for periodic calls from a timer or a background thread.
Parameters:
- notifier (soe_notifier_t*) — notifier instance
- timeout_ms (int) — timeout for each IDN read, in milliseconds
- callback (soe_notification_callback_t) — parameter change callback function
- user_data (void*) — user data pointer, passed through to the callback
Return value:
- int — the number of IDNs whose change was detected in this poll; 0 when notifier / callback is null or no IDN is registered (an IDN whose read fails is skipped for this round)
soe_notification_free()
void soe_notification_free(soe_notification_t* event);
Releases the dynamically allocated new_value and old_value buffers of a notification event. A callback that receives an event must call it once the event is no longer needed.
Parameters:
- event (soe_notification_t*) — the event received by the callback
Return value: none
Emergency message callback (registration entry points)
SoE OpCode=6 is called SERCOS Emergency in early material, which is why the C SDK keeps a register / unregister pair. The current behavior is: the entry points accept registrations, but the runtime never triggers them — on the wire the real meaning of OpCode=6 is Slave Info, and the runtime delivers such frames through the notification channel.
- No path in the runtime currently triggers the SoE emergency callback, so a registered callback is never called;
- The parameter changes / Slave Info frames that the slave reports should be handled through the notification channel (the notification callback registered with
DarraEcat_RegisterSoENotificationCallback, or thesoe_notifier_*polling in the previous section); - Drive alarms (CoE EMCY, carrying the error register and vendor bytes) are a separate channel:
DarraEcat_RegisterEmergency, whose signature differs from this section; do not mix the two.
This pair of entry points is kept only for compatibility with existing callers; new code should not rely on it for alarm handling.
Callback signature
typedef void (*darraecat_soe_emergency_cb_t)(uint16_t master_index, uint16_t slave_index,
uint8_t drive_no, uint16_t error_code);
| Category | Parameter | Type | Read/write | Description |
|---|---|---|---|---|
| Emergency message | master_index | uint16_t | read-only | Master index |
| Emergency message | slave_index | uint16_t | read-only | Slave index |
| Emergency message | drive_no | uint8_t | read-only | Drive number (axis number; 0 for a single-axis servo) |
| Emergency message | error_code | uint16_t | read-only | In the early design, carried the SERCOS error code (IEC 61491) reported by the drive; nothing triggers it today, so it never arrives in practice |
DarraEcat_RegisterSoEEmergencyCallback() / DarraEcat_UnregisterSoEEmergencyCallback()
void DarraEcat_RegisterSoEEmergencyCallback(darraecat_soe_emergency_cb_t callback);
void DarraEcat_UnregisterSoEEmergencyCallback(darraecat_soe_emergency_cb_t callback);
Parameters:
- callback (darraecat_soe_emergency_cb_t) — callback function pointer; unregister with the same pointer that was registered
Return value: none (void); no error code is returned.
When to call: register before Start(); unregister before the process exits or re-initializes.
Registration semantics:
- The same entry point can hold several listeners without overwriting each other; unregistering removes only the function pointer passed in.
- Passing
NULLforcallbackmeans "do not register" and is ignored; unregistering a pointer that was never registered reports no error and does not affect other registered listeners. - The number of listeners is capped; beyond that, new registrations are ignored (a warning is logged). Unregister promptly once you no longer need it.
- Registering while the SDK is not ready does not crash and does not take effect; check with
DarraEcat_ShellStatus()(continue with business calls only when it returnsDARRAECAT_SHELL_OK). - Callbacks are designed to run synchronously on the mailbox receive thread and must return quickly: never block waiting for a mailbox operation inside a callback (it self-deadlocks); copy the event to a queue and handle it on the main thread when heavier work is needed. Because nothing triggers them today, this constraint currently holds by design only.
Example (shows the shape of the entry points only; no callback arrives today):
static void on_soe_emergency(uint16_t master_index, uint16_t slave_index,
uint8_t drive_no, uint16_t error_code)
{
/* the runtime does not call this today; use the notification channel for slave reports */
}
DarraEcat_RegisterSoEEmergencyCallback(on_soe_emergency);
/* ... run ... */
DarraEcat_UnregisterSoEEmergencyCallback(on_soe_emergency);
Standard IDN constants
| IDN | Name | Description |
|---|---|---|
| 0x0000 | S-0-0000 | Placeholder number for the IDN list |
| 0x0001 | S-0-0001 | Communication cycle time |
| 0x000B | S-0-0011 | Class 1 diagnostic code (UINT16, not a position value) |
| 0x000C | S-0-0012 | Class 2 diagnostic code (UINT16, not a position value) |
| 0x0010 | S-0-0016 | AT mapping configuration list (slave to master) |
| 0x0018 | S-0-0024 | MDT mapping configuration list (master to slave) |
| 0x002F | S-0-0047 | Position command value |
| 0x0033 | S-0-0051 | Position feedback 1 |
| 0x0063 | S-0-0099 | Reset procedure command |
| 0x007F | S-0-0127 | Notification request IDN |
| 0x0094 | S-0-0148 | Homing procedure command |
The meaning and data type of a given IDN follow the servo device manual (parameter number spaces are not identical across vendors).
Asynchronous notifications
Receiving notification events
Notification events are received by polling with the soe_notifier_* family in advanced.h; the callback signature is void(const soe_notification_t*, void*).
Receiving emergency messages
SoE mailbox OpCode=6 is called SERCOS Emergency in early material. The dedicated entry point the C SDK keeps is DarraEcat_RegisterSoEEmergencyCallback, but nothing triggers it today; OpCode=6 frames are actually delivered through the notification channel. It is not the same entry point as DarraEcat_RegisterEmergency for CoE EMCY — see the "Emergency message callback" section.
Threading model
soe_poll_notifications() runs synchronously on the calling thread (one poll walks every registered IDN). Call it from a dedicated background thread or a timer; do not put it in a PDO cycle callback. The callback is responsible for releasing the old and new value buffers of the event it receives: call soe_notification_free() when done.
Notes
- Hardware notification (S-0-0127) behaves inconsistently on slaves from most vendors, so the SDK works on two tracks by default (hardware notification with polling as a fallback)
- For a multi-drive slave, create a separate notifier instance for each drive_number
- Notifications are not guaranteed to arrive in monotonic order; the application layer must handle edge cases between old_value and new_value itself
The C SDK receives SoE parameter change events by polling with the soe_notifier_* family in advanced.h; to receive notification frames the slave pushes on its own, register a notification callback with DarraEcat_RegisterSoENotificationCallback. The two channels serve different purposes; do not process the same data source twice.
The new_value / old_value in a notification event are allocated by the SDK; release them with soe_notification_free when done.
Parameter change notification in the C SDK centres on the soe_notifier_* active polling entry points in advanced.h. They first try S-0-0127 hardware notification and fall back to polling automatically on failure, balancing promptness with broad compatibility, and no separate callback registration is needed.
Full example
Typed read and write
#include "ethercat.h"
#include "ethercat_advanced.h"
#include "slave/soe.h"
#include <stdio.h>
int main(void)
{
uint16_t master = Initialize();
if (master == 0 || master == (uint16_t)-1) {
printf("主站初始化失败\n"); /* Master initialization failed */
return 1;
}
SetNetwork(master, "\\Device\\NPF_{...}", "");
SetStateSequence(master, EC_STATE_PRE_OP, 5000);
uint16_t slave = 1;
uint8_t axis = 0;
/* read position feedback S-0-0051: build the IDN with the encoder, equivalent to 0x0033 */
int32_t actual_pos_idn = soe_idn_encode(1, 0, 51);
if (DARRA_IS_READ_FAIL_INT(actual_pos_idn)) {
printf("IDN 编码失败\n"); /* IDN encoding failed */
Dispose(master);
return 1;
}
int32_t position = 0;
if (soe_read_i32(master, slave, axis, (uint16_t)actual_pos_idn, &position) != 0) {
printf("读取 IDN 0x0033 失败\n"); /* Failed to read IDN 0x0033 */
} else {
printf("位置反馈: %d\n", position); /* Position feedback: %d */
}
/* write position command S-0-0047 (IDN 0x002F) */
if (soe_write_i32(master, slave, axis, 0x002F, 100000) != 0) {
printf("写入 IDN 0x002F 失败\n"); /* Failed to write IDN 0x002F */
}
Dispose(master);
return 0;
}
Parameter change notification
#include "ethercat.h"
#include "ethercat_advanced.h"
#include <stdio.h>
/* notification callback function */
void on_soe_change(const soe_notification_t* event, void* user_data) {
printf("参数变化: IDN 0x%04X, 从站 %d, 驱动器 %d\n", /* Parameter change: IDN 0x%04X, slave %d, drive %d */
event->idn, event->slave_index, event->drive_number);
printf(" 旧值 (%d 字节): ", event->old_value_size); /* Old value (%d bytes): */
for (int i = 0; i < event->old_value_size; i++)
printf("%02X ", event->old_value[i]);
printf("\n 新值 (%d 字节): ", event->new_value_size); /* New value (%d bytes): */
for (int i = 0; i < event->new_value_size; i++)
printf("%02X ", event->new_value[i]);
printf("\n");
soe_notification_free((soe_notification_t*)event); /* release the old and new value buffers when done */
}
int main(void)
{
uint16_t master = Initialize();
if (master == 0 || master == (uint16_t)-1) return 1;
SetNetwork(master, "\\Device\\NPF_{...}", "");
SetStateSequence(master, EC_STATE_PRE_OP, 5000);
uint16_t slave = 1;
/* create the notifier */
soe_notifier_t* notifier = soe_notifier_create(master, slave, 0);
/* enable monitoring of position feedback S-0-0051 (IDN 0x0033) */
int hw = soe_enable_notification(notifier, 0x0033, 500);
if (hw < 0) {
printf("监控登记失败\n"); /* Monitoring registration failed */
} else {
printf("通知模式: %s\n", hw ? "硬件通知" : "轮询"); /* Notification mode: %s (hardware notification or polling) */
}
/* poll periodically from a timer or a loop */
for (int i = 0; i < 100; i++) {
int changed = soe_poll_notifications(notifier, 200, on_soe_change, NULL);
if (changed > 0)
printf("检测到 %d 个参数变化\n", changed); /* Detected %d parameter changes */
}
/* stop monitoring and release resources */
soe_disable_all_notifications(notifier);
soe_notifier_destroy(notifier);
Dispose(master);
return 0;
}
Failures and handling
| Symptom | Cause | Handling |
|---|---|---|
| Read or write returns -1 | IDN not implemented, write protection, state not allowed, or mailbox timeout; the typed entry points return only -1 and do not distinguish the cause | Check the IDN against the device manual and confirm whether it belongs to the standard range or the vendor-specific range; for a protocol-level cause, combine device diagnostics with the raw frame |
| Write returns -1 and device diagnostics report write protection | The parameter is write-protected (password, setting or access rights restriction) | Confirm the parameter is writable, and switch to an access level with write permission before writing if needed |
| Read or write returns -1 and appears as a timeout | Mailbox transaction timeout or the slave did not answer | Confirm the slave mailbox is available and the state is normal, then retry; increase the timeout if it keeps timing out |
| Operation rejected, appearing as state not allowed | The parameter can only be written in a specific servo state | Wait until the servo reaches a state that allows the parameter, avoiding the state transition window |
Error codes
Compare protocol error codes programmatically with ec_soe_error_t (EC_SOE_ERROR_*). Convert a raw 16-bit code to the enum with EcSoEErrorCodeFromRaw(); codes outside the table return EC_SOE_ERROR_UNKNOWN and the raw code itself is unaffected, so report the input value directly when it must be passed through unchanged. Text descriptions come from EcSoE_GetErrorDescription(). The read and write entry points on this page return success or failure only and never return the raw code, which comes from device diagnostics or protocol frames and is converted for branching and display.
uint16_t raw = 0x7008;
ec_soe_error_t code = EcSoEErrorCodeFromRaw(raw);
if (code == EC_SOE_ERROR_INVALID_OPERATION_DATA_CONFIGURED_IDN_NOT_SUPPORTED) {
/* the configured IDN is not supported by the slave: change the IDN, retrying as-is is pointless */
}
printf("SoE 错误 0x%04X: %s\n", raw, EcSoE_GetErrorDescription(raw)); /* SoE error 0x%04X: %s */