Protocol codes and diagnostic strings
This page collects the C SDK's protocol-layer error code decoding, state and mode queries, and diagnostic string entry points. Related pages: CiA 402, Slave properties, SDO/CoE.
Every interface that returns const char* returns a static string (UTF-8, with Chinese text) that must not be modified or released.
AL status code
Based on ETG.1000.6 §5.2.13 table 11 / ETG.1020 §4 table 1.
| Category | Function | Return type | Read/write | Description |
|---|---|---|---|---|
| AL Status Code | AL_StatusCode_GetSeverity(code) | al_status_severity_t | read-only | Gets the severity of an AL status code (AL_SEVERITY_NONE / INFO / WARNING / ERROR / FATAL) |
| AL_StatusCode_GetRecoveryHint(code) | const char* | read-only | Gets the recommended action; static string, UTF-8, must not be modified or released | |
| AL_StatusCode_IsVendorSpecific(code) | int | read-only | Whether the status code is a vendor-specific error (0x8000-0xFFFF) |
SDO abort code
Based on CiA 301 / ETG.1000.6 §6.6.4.
| Category | Function | Return type | Read/write | Description |
|---|---|---|---|---|
| SDO Abort | dx_sdo_abort_get_category(abort_code) | sdo_abort_category_t | read-only | Gets the abort code category (SDO_ABORT_CAT_TRANSFER / ACCESS / VALUE / HARDWARE / GENERAL) |
| dx_sdo_abort_get_description(abort_code) | const char* | read-only | Gets the abort code description, with Chinese and English combined as "Chinese / English"; static string, UTF-8, must not be modified or released | |
| dx_sdo_abort_get_hint(abort_code) | const char* | read-only | Gets guidance for the engineer; static string, UTF-8, must not be modified or released | |
| dx_sdo_abort_is_retryable(abort_code) | int | read-only | Whether it can be retried (1 = retryable, 0 = not retryable) |
CiA 402 modes and homing
Based on CiA 402-2 / ETG.6010 §5.4.
| Category | Function | Return type | Read/write | Description |
|---|---|---|---|---|
| CiA 402 modes and homing | CiA402Modes_ModeToSupportedBit(mode) | int | read-only | Maps a mode to its bit index in the 0x6502 SupportedDriveModes; -1 means there is no corresponding bit |
| CiA402Modes_IsModeSupportedInMask(supported_mask, mode) | int | read-only | Whether the 0x6502 mask supports the given mode | |
| CiA402Modes_ExpandSupportedMask(supported_mask, modes, capacity) | int | read/write | Expands the 0x6502 mask into a mode list written into a caller array | |
| CiA402Modes_GetModeName(mode) | const char* | read-only | Mode name (Chinese + English abbreviation); static string, UTF-8, must not be modified or released | |
| CiA402Modes_GetModeNameEn(mode) | const char* | read-only | Mode name (full English name); static string, UTF-8, must not be modified or released | |
| CiA402Modes_GetModeDescription(mode) | const char* | read-only | What the mode is used for; static string, UTF-8, must not be modified or released | |
| CiA402Modes_IsCyclicSyncMode(mode) | int | read-only | Whether it is a cyclic synchronous PDO mode (CSP / CSV / CST / CSTCA return 1) | |
| CiA402Modes_RequiresDC(mode) | int | read-only | Whether DC synchronization is required (CSP / CSV / CST / CSTCA return 1) | |
| CiA402Modes_IsStandardHomingMethod(method) | int | read-only | Whether the homing method falls in the standard ETG.6010 range (1..35 or 37) | |
| CiA402Modes_GetHomingMethodName(method) | const char* | read-only | Homing method description, method number -128..127; static string, UTF-8, must not be modified or released | |
| CiA402Modes_GetHomingTrigger(method) | homing_trigger_t | read-only | Trigger source of the homing method (HOMING_TRIGGER_NEGATIVE_LIMIT / POSITIVE_LIMIT / HOME_SWITCH / INDEX_PULSE / HARD_STOP / CURRENT_POS / VENDOR) | |
| CiA402Modes_GetHomingDirection(method) | int | read-only | Movement direction of the homing method (-1 = negative, 0 = no movement, +1 = positive) | |
| CiA402Modes_ListStandardHomingMethods(array, capacity) | int | read/write | Outputs all standard homing method numbers into a caller array |
EMCY emergency error codes
Based on CiA 301 v4.2.0 Table 24.
| Category | Function | Return type | Read/write | Description |
|---|---|---|---|---|
| EMCY | EmcyCode_GetClass(error_code) | emcy_class_t | read-only | Gets the major class of the error code (the high 4 bits of CiA 301) |
| EmcyCode_GetClassName(class_code) | const char* | read-only | Gets the class description; static string, UTF-8, must not be modified or released | |
| EmcyCode_GetDescription(error_code) | const char* | read-only | Gets the description of a 16-bit error code (three-level fallback matching); static string, UTF-8, must not be modified or released | |
| EmcyCode_IsRecovery(error_code) | int | read-only | Whether it is an error recovery message (error_code == 0x0000) | |
| EmcyCode_FormatErrorRegister(error_register, buf, buf_size) | void | read/write | Formats the Error Register bitmask into a caller buffer; for example 0x16 yields the names for general / current / temperature / communication |
EtherCAT states
Based on ETG.1000.6 §6.4.
| Category | Function | Return type | Read/write | Description |
|---|---|---|---|---|
| EtherCAT states | EcState_GetName(state) | const char* | read-only | State name (Chinese); static string, UTF-8, must not be modified or released |
| EcState_GetNameEn(state) | const char* | read-only | State name (English); static string, UTF-8, must not be modified or released | |
| EcState_GetTransitionPath(from, to, path, path_capacity) | int | read/write | Writes the intermediate state sequence from from to to into a caller array and returns the length | |
| EcState_GetTransitionType(from, to) | ec_transition_type_t | read-only | Gets the transition type (INVALID / UP / DOWN / SAME / BOOTSTRAP / JUMP_UP / JUMP_DOWN) | |
| EcState_HasErrorAck(state) | int | read-only | Whether the state value carries the ERROR ACK bit (0x10) | |
| EcState_IsBootstrapRequired(state) | int | read-only | Whether that state needs Bootstrap (firmware update) | |
| EcState_IsValidTransition(from, to) | int | read-only | Whether the state transition is legal (1 = legal, 0 = illegal) | |
| EcState_StripErrorAck(state) | uint16_t | read-only | Removes the ERROR ACK bit from the state value |
Mailbox protocol codes
Based on ETG.1000.6 §5.6.1.4; the SoE part is based on IEC 61491 / ETG.6010.
| Category | Function | Return type | Read/write | Description |
|---|---|---|---|---|
| Mailbox | EcMailbox_GetTypeName(type) | const char* | read-only | Mailbox type name in Chinese; static string, UTF-8, must not be modified or released |
| EcMailbox_GetTypeNameEn(type) | const char* | read-only | Mailbox type name in English; static string, UTF-8, must not be modified or released | |
| EcMailbox_GetErrorDescription(mbx_error_code) | const char* | read-only | Mailbox error code description (ETG.1000.6 §5.6.1.4 table 17); static string, UTF-8, must not be modified or released | |
| EcMailbox_NextCounter(current) | uint8_t | read-only | Computes the next Mailbox Counter (cycling 1..7) |
PDO codec and port topology
Based on ETG.1000.6 §5.6.7.4 and ETG.1000.4 ESC 0x0110.
| Category | Function | Return type | Read/write | Description |
|---|---|---|---|---|
| PDO codec | EcPdoCodec_ExtractU64(src, src_size, bit_offset, bit_length, out) | int | read-only | Extracts a 1..64 bit unsigned BitField into out, little-endian |
| EcPdoCodec_ExtractI64(src, src_size, bit_offset, bit_length, out) | int | read-only | Extracts a BitField with sign extension | |
| EcPdoCodec_ExtractReal32(src, src_size, bit_offset, out) | int | read-only | Extracts a REAL32 (bit_offset must be 8-byte aligned) | |
| EcPdoCodec_ExtractReal64(src, src_size, bit_offset, out) | int | read-only | Extracts a REAL64 | |
| EcPdoCodec_InsertU64(dst, dst_size, bit_offset, bit_length, value) | int | read/write | Writes an unsigned BitField into a caller buffer | |
| EcPdoCodec_InsertI64(dst, dst_size, bit_offset, bit_length, value) | int | read/write | Writes a signed BitField into a caller buffer | |
| EcPdoCodec_InsertReal32(dst, dst_size, bit_offset, value) | int | read/write | Writes a REAL32 into a caller buffer | |
| EcPdoCodec_InsertReal64(dst, dst_size, bit_offset, value) | int | read/write | Writes a REAL64 into a caller buffer | |
| EcPdoCodec_CountActivePorts(active_ports) | int | read-only | Counts the active ports from the ActivePorts byte (0..4, low 4 bits only) | |
| EcPdoCodec_IsPortActive(active_ports, port) | int | read-only | Whether the given port (0..3) is active | |
| EcPdoCodec_GetTopology(active_ports) | ec_pdo_topology_t | read-only | Gets the topology type from ActivePorts (EC_PDO_TOPO_UNKNOWN / LINE / PASS / BRANCH / CROSS) | |
| EcPdoCodec_GetTopologyName(topo) | const char* | read-only | Topology type name in Chinese; static string, UTF-8, must not be modified or released | |
| EcPdoCodec_GetTopologyNameEn(topo) | const char* | read-only | Topology type name in English; static string, UTF-8, must not be modified or released |
SII capability bits
Based on ETG.1000.6 §5.4.
| Category | Function | Return type | Read/write | Description |
|---|---|---|---|---|
| SII capability bits | EcSii_CoeEnabled(coe_details) | int | read-only | The CoE enabled bit in the CoE Details bit field |
| EcSii_CoeSdoInfo(coe_details) | int | read-only | The SDO Information bit in the CoE Details bit field | |
| EcSii_CoePdoAssign(coe_details) | int | read-only | The PDO Assign bit in the CoE Details bit field | |
| EcSii_CoePdoConfig(coe_details) | int | read-only | The PDO Configuration bit in the CoE Details bit field | |
| EcSii_CoeCompleteAccess(coe_details) | int | read-only | The Complete Access bit in the CoE Details bit field | |
| EcSii_CoeUploadAtStartup(coe_details) | int | read-only | The upload-at-startup bit in the CoE Details bit field | |
| EcSii_EoeEnabled(eoe_details) | int | read-only | The enabled bit in the EoE Details bit field (bit 0) | |
| EcSii_FoeEnabled(foe_details) | int | read-only | The enabled bit in the FoE Details bit field (bit 0) | |
| EcSii_GetConfiguredAlias(sii_data, sii_size) | uint16_t | read-only | Reads SII Word 4 = Configured Station Alias | |
| EcSii_GetRevision(sii_data, sii_size) | uint32_t | read-only | Reads SII Word 12-13 = Revision | |
| EcSii_GetSerialNumber(sii_data, sii_size) | uint32_t | read-only | Reads SII Word 14-15 = Serial Number |
Coupler identification
Based on the 14 vendor IDs and the known coupler ProductCode list built into the SDK.
| Category | Function | Return type | Read/write | Description |
|---|---|---|---|---|
| Coupler identification | EcCouplerId_IsCoupler(vendor_id, product_code) | int | read-only | Whether VendorID + ProductCode identify a coupler (head module) |
| EcCouplerId_IsTerminal(vendor_id, product_code) | int | read-only | Whether VendorID + ProductCode identify a terminal I/O module | |
| EcCouplerId_DetectDeviceType(vendor_id, product_code) | ec_device_type_t | read-only | Identifies the device type from VendorID + ProductCode (EC_DEV_UNKNOWN / COUPLER / TERMINAL / DRIVE / SENSOR / GATEWAY / SAFETY / CONTROLLER) | |
| EcCouplerId_GetDeviceTypeName(type) | const char* | read-only | Device type name (Chinese); static string, UTF-8, must not be modified or released | |
| EcCouplerId_GetCouplerModel(vendor_id, product_code) | const char* | read-only | Model string of a known coupler (such as EK1100); returns NULL when nothing matches; static string, UTF-8, must not be modified or released | |
| EcCouplerId_GetVendorName(vendor_id) | const char* | read-only | Vendor name (Chinese); static string, UTF-8, must not be modified or released | |
| EcCouplerId_GetVendorNameEn(vendor_id) | const char* | read-only | Vendor name (English); static string, UTF-8, must not be modified or released | |
| EcCouplerId_GetVendorCount() | int | read-only | Table statistic (for diagnostics): number of vendors | |
| EcCouplerId_GetEntryCount() | int | read-only | Table statistic (for diagnostics): number of device entries |
Diagnostic strings
| Category | Function | Return type | Read/write | Description |
|---|---|---|---|---|
| Diagnostic strings | EcDiagStrings_BreakpointType(bp) | const char* | read-only | Breakpoint description (Chinese); static string, UTF-8, must not be modified or released |
| EcDiagStrings_FormatBreakpoint(slave_idx, port, bp, buf, buf_size) | void | read/write | Formats the combined breakpoint information into a caller buffer, for example slave 5 P2 disconnected | |
| EcDiagStrings_TimingMode(mode) | const char* | read-only | Timing mode description (Chinese); static string, UTF-8, must not be modified or released | |
| EcDiagStrings_TopologyDescription(topo) | const char* | read-only | Topology description (Chinese); static string, UTF-8, must not be modified or released |
Example
Expanding the 0x6502 SupportedDriveModes mask
#include "protocol/protocol_codes.h"
#include <stdio.h>
/* supported = the SupportedDriveModes bitmap the slave read back from 0x6502*/
uint32_t supported = 0x0000;
int8_t modes[16];
int n = CiA402Modes_ExpandSupportedMask(supported, modes,
(int)(sizeof(modes) / sizeof(modes[0])));
for (int i = 0; i < n; ++i) {
cia402_op_mode_t mode = (cia402_op_mode_t)modes[i];
printf("模式 %d: %s (%s)\n", (int)mode, /* Mode %d: %s (%s) */
CiA402Modes_GetModeName(mode),
CiA402Modes_GetModeNameEn(mode));
}
/* Judge separately whether CSP is supported and take its bit index in 0x6502*/
if (CiA402Modes_IsModeSupportedInMask(supported, CIA402_OPMODE_CSP)) {
int bit = CiA402Modes_ModeToSupportedBit(CIA402_OPMODE_CSP);
printf("CSP 支持, bit=%d, 周期同步=%d, 需要 DC=%d\n", /* CSP supported, bit=%d, cyclic synchronization=%d, DC required=%d */
bit,
CiA402Modes_IsCyclicSyncMode(CIA402_OPMODE_CSP),
CiA402Modes_RequiresDC(CIA402_OPMODE_CSP));
}
Homing method lookup and direction test
#include "protocol/protocol_codes.h"
#include <stdio.h>
int8_t methods[64];
int count = CiA402Modes_ListStandardHomingMethods(
methods, (int)(sizeof(methods) / sizeof(methods[0])));
for (int i = 0; i < count; ++i) {
int8_t method = methods[i];
/* Only the standard method interprets the trigger source and direction per ETG.6010*/
if (!CiA402Modes_IsStandardHomingMethod(method))
continue;
printf("方法 %d: %s, 方向 %d, 触发源 %d\n", /* Method %d: %s, direction %d, trigger source %d */
(int)method,
CiA402Modes_GetHomingMethodName(method),
CiA402Modes_GetHomingDirection(method),
(int)CiA402Modes_GetHomingTrigger(method));
/* Direction: -1=negative, 0=stationary, +1=positive*/
if (CiA402Modes_GetHomingDirection(method) < 0)
printf(" 该回零方法向负方向寻找\n"); /* This homing method searches in the negative direction */
}