Skip to main content

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.

CategoryFunctionReturn typeRead/writeDescription
AL Status CodeAL_StatusCode_GetSeverity(code)al_status_severity_tread-onlyGets the severity of an AL status code (AL_SEVERITY_NONE / INFO / WARNING / ERROR / FATAL)
AL_StatusCode_GetRecoveryHint(code)const char*read-onlyGets the recommended action; static string, UTF-8, must not be modified or released
AL_StatusCode_IsVendorSpecific(code)intread-onlyWhether the status code is a vendor-specific error (0x8000-0xFFFF)

SDO abort code​

Based on CiA 301 / ETG.1000.6 §6.6.4.

CategoryFunctionReturn typeRead/writeDescription
SDO Abortdx_sdo_abort_get_category(abort_code)sdo_abort_category_tread-onlyGets the abort code category (SDO_ABORT_CAT_TRANSFER / ACCESS / VALUE / HARDWARE / GENERAL)
dx_sdo_abort_get_description(abort_code)const char*read-onlyGets 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-onlyGets guidance for the engineer; static string, UTF-8, must not be modified or released
dx_sdo_abort_is_retryable(abort_code)intread-onlyWhether it can be retried (1 = retryable, 0 = not retryable)

CiA 402 modes and homing​

Based on CiA 402-2 / ETG.6010 §5.4.

CategoryFunctionReturn typeRead/writeDescription
CiA 402 modes and homingCiA402Modes_ModeToSupportedBit(mode)intread-onlyMaps a mode to its bit index in the 0x6502 SupportedDriveModes; -1 means there is no corresponding bit
CiA402Modes_IsModeSupportedInMask(supported_mask, mode)intread-onlyWhether the 0x6502 mask supports the given mode
CiA402Modes_ExpandSupportedMask(supported_mask, modes, capacity)intread/writeExpands the 0x6502 mask into a mode list written into a caller array
CiA402Modes_GetModeName(mode)const char*read-onlyMode name (Chinese + English abbreviation); static string, UTF-8, must not be modified or released
CiA402Modes_GetModeNameEn(mode)const char*read-onlyMode name (full English name); static string, UTF-8, must not be modified or released
CiA402Modes_GetModeDescription(mode)const char*read-onlyWhat the mode is used for; static string, UTF-8, must not be modified or released
CiA402Modes_IsCyclicSyncMode(mode)intread-onlyWhether it is a cyclic synchronous PDO mode (CSP / CSV / CST / CSTCA return 1)
CiA402Modes_RequiresDC(mode)intread-onlyWhether DC synchronization is required (CSP / CSV / CST / CSTCA return 1)
CiA402Modes_IsStandardHomingMethod(method)intread-onlyWhether the homing method falls in the standard ETG.6010 range (1..35 or 37)
CiA402Modes_GetHomingMethodName(method)const char*read-onlyHoming method description, method number -128..127; static string, UTF-8, must not be modified or released
CiA402Modes_GetHomingTrigger(method)homing_trigger_tread-onlyTrigger source of the homing method (HOMING_TRIGGER_NEGATIVE_LIMIT / POSITIVE_LIMIT / HOME_SWITCH / INDEX_PULSE / HARD_STOP / CURRENT_POS / VENDOR)
CiA402Modes_GetHomingDirection(method)intread-onlyMovement direction of the homing method (-1 = negative, 0 = no movement, +1 = positive)
CiA402Modes_ListStandardHomingMethods(array, capacity)intread/writeOutputs all standard homing method numbers into a caller array

EMCY emergency error codes​

Based on CiA 301 v4.2.0 Table 24.

CategoryFunctionReturn typeRead/writeDescription
EMCYEmcyCode_GetClass(error_code)emcy_class_tread-onlyGets the major class of the error code (the high 4 bits of CiA 301)
EmcyCode_GetClassName(class_code)const char*read-onlyGets the class description; static string, UTF-8, must not be modified or released
EmcyCode_GetDescription(error_code)const char*read-onlyGets 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)intread-onlyWhether it is an error recovery message (error_code == 0x0000)
EmcyCode_FormatErrorRegister(error_register, buf, buf_size)voidread/writeFormats 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.

CategoryFunctionReturn typeRead/writeDescription
EtherCAT statesEcState_GetName(state)const char*read-onlyState name (Chinese); static string, UTF-8, must not be modified or released
EcState_GetNameEn(state)const char*read-onlyState name (English); static string, UTF-8, must not be modified or released
EcState_GetTransitionPath(from, to, path, path_capacity)intread/writeWrites the intermediate state sequence from from to to into a caller array and returns the length
EcState_GetTransitionType(from, to)ec_transition_type_tread-onlyGets the transition type (INVALID / UP / DOWN / SAME / BOOTSTRAP / JUMP_UP / JUMP_DOWN)
EcState_HasErrorAck(state)intread-onlyWhether the state value carries the ERROR ACK bit (0x10)
EcState_IsBootstrapRequired(state)intread-onlyWhether that state needs Bootstrap (firmware update)
EcState_IsValidTransition(from, to)intread-onlyWhether the state transition is legal (1 = legal, 0 = illegal)
EcState_StripErrorAck(state)uint16_tread-onlyRemoves 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.

CategoryFunctionReturn typeRead/writeDescription
MailboxEcMailbox_GetTypeName(type)const char*read-onlyMailbox type name in Chinese; static string, UTF-8, must not be modified or released
EcMailbox_GetTypeNameEn(type)const char*read-onlyMailbox type name in English; static string, UTF-8, must not be modified or released
EcMailbox_GetErrorDescription(mbx_error_code)const char*read-onlyMailbox 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_tread-onlyComputes 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.

CategoryFunctionReturn typeRead/writeDescription
PDO codecEcPdoCodec_ExtractU64(src, src_size, bit_offset, bit_length, out)intread-onlyExtracts a 1..64 bit unsigned BitField into out, little-endian
EcPdoCodec_ExtractI64(src, src_size, bit_offset, bit_length, out)intread-onlyExtracts a BitField with sign extension
EcPdoCodec_ExtractReal32(src, src_size, bit_offset, out)intread-onlyExtracts a REAL32 (bit_offset must be 8-byte aligned)
EcPdoCodec_ExtractReal64(src, src_size, bit_offset, out)intread-onlyExtracts a REAL64
EcPdoCodec_InsertU64(dst, dst_size, bit_offset, bit_length, value)intread/writeWrites an unsigned BitField into a caller buffer
EcPdoCodec_InsertI64(dst, dst_size, bit_offset, bit_length, value)intread/writeWrites a signed BitField into a caller buffer
EcPdoCodec_InsertReal32(dst, dst_size, bit_offset, value)intread/writeWrites a REAL32 into a caller buffer
EcPdoCodec_InsertReal64(dst, dst_size, bit_offset, value)intread/writeWrites a REAL64 into a caller buffer
EcPdoCodec_CountActivePorts(active_ports)intread-onlyCounts the active ports from the ActivePorts byte (0..4, low 4 bits only)
EcPdoCodec_IsPortActive(active_ports, port)intread-onlyWhether the given port (0..3) is active
EcPdoCodec_GetTopology(active_ports)ec_pdo_topology_tread-onlyGets the topology type from ActivePorts (EC_PDO_TOPO_UNKNOWN / LINE / PASS / BRANCH / CROSS)
EcPdoCodec_GetTopologyName(topo)const char*read-onlyTopology type name in Chinese; static string, UTF-8, must not be modified or released
EcPdoCodec_GetTopologyNameEn(topo)const char*read-onlyTopology type name in English; static string, UTF-8, must not be modified or released

SII capability bits​

Based on ETG.1000.6 §5.4.

CategoryFunctionReturn typeRead/writeDescription
SII capability bitsEcSii_CoeEnabled(coe_details)intread-onlyThe CoE enabled bit in the CoE Details bit field
EcSii_CoeSdoInfo(coe_details)intread-onlyThe SDO Information bit in the CoE Details bit field
EcSii_CoePdoAssign(coe_details)intread-onlyThe PDO Assign bit in the CoE Details bit field
EcSii_CoePdoConfig(coe_details)intread-onlyThe PDO Configuration bit in the CoE Details bit field
EcSii_CoeCompleteAccess(coe_details)intread-onlyThe Complete Access bit in the CoE Details bit field
EcSii_CoeUploadAtStartup(coe_details)intread-onlyThe upload-at-startup bit in the CoE Details bit field
EcSii_EoeEnabled(eoe_details)intread-onlyThe enabled bit in the EoE Details bit field (bit 0)
EcSii_FoeEnabled(foe_details)intread-onlyThe enabled bit in the FoE Details bit field (bit 0)
EcSii_GetConfiguredAlias(sii_data, sii_size)uint16_tread-onlyReads SII Word 4 = Configured Station Alias
EcSii_GetRevision(sii_data, sii_size)uint32_tread-onlyReads SII Word 12-13 = Revision
EcSii_GetSerialNumber(sii_data, sii_size)uint32_tread-onlyReads SII Word 14-15 = Serial Number

Coupler identification​

Based on the 14 vendor IDs and the known coupler ProductCode list built into the SDK.

CategoryFunctionReturn typeRead/writeDescription
Coupler identificationEcCouplerId_IsCoupler(vendor_id, product_code)intread-onlyWhether VendorID + ProductCode identify a coupler (head module)
EcCouplerId_IsTerminal(vendor_id, product_code)intread-onlyWhether VendorID + ProductCode identify a terminal I/O module
EcCouplerId_DetectDeviceType(vendor_id, product_code)ec_device_type_tread-onlyIdentifies the device type from VendorID + ProductCode (EC_DEV_UNKNOWN / COUPLER / TERMINAL / DRIVE / SENSOR / GATEWAY / SAFETY / CONTROLLER)
EcCouplerId_GetDeviceTypeName(type)const char*read-onlyDevice type name (Chinese); static string, UTF-8, must not be modified or released
EcCouplerId_GetCouplerModel(vendor_id, product_code)const char*read-onlyModel 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-onlyVendor name (Chinese); static string, UTF-8, must not be modified or released
EcCouplerId_GetVendorNameEn(vendor_id)const char*read-onlyVendor name (English); static string, UTF-8, must not be modified or released
EcCouplerId_GetVendorCount()intread-onlyTable statistic (for diagnostics): number of vendors
EcCouplerId_GetEntryCount()intread-onlyTable statistic (for diagnostics): number of device entries

Diagnostic strings​

CategoryFunctionReturn typeRead/writeDescription
Diagnostic stringsEcDiagStrings_BreakpointType(bp)const char*read-onlyBreakpoint description (Chinese); static string, UTF-8, must not be modified or released
EcDiagStrings_FormatBreakpoint(slave_idx, port, bp, buf, buf_size)voidread/writeFormats the combined breakpoint information into a caller buffer, for example slave 5 P2 disconnected
EcDiagStrings_TimingMode(mode)const char*read-onlyTiming mode description (Chinese); static string, UTF-8, must not be modified or released
EcDiagStrings_TopologyDescription(topo)const char*read-onlyTopology 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 */
}