ESI/ENI configuration capabilities
ESI (EtherCAT Slave Information) describes the capabilities of a single slave device, while ENI (EtherCAT Network Information) describes the configuration of a whole network. This page covers the C SDK's ESI file deep reads, slave ESI convenience queries, the ESI registry and binding, and the structured ENI/DENI read and write entry points.
Capability overview
ESI XML parsing happens inside the runtime; the C SDK does not bundle an XML parser: the application only hands a file path or a directory path to the SDK, and the parsed results come back from the functions below as scalar, string and array output parameters.
ESI deep reads do not depend on a master / slave instance and produce no bus traffic, so device capabilities can be read offline before a master is initialized. ENI/DENI are used to deliver a whole configuration: the DENI load and delivery chain is covered in the DENI section of the C SDK overview; this page lists only the structured read and write entry points of utils/eni.h, and the function names follow utils/eni.h.
Every output parameter on this page is a caller-provided buffer or scalar; the SDK returns no pointer that needs releasing and there is no release interface to call.
| Category | Function | Return type | Read/write | Description |
|---|---|---|---|---|
| Slave convenience queries | slave_has_esi / slave_get_esi_version | bool | read-only | Checks whether that slave's ESI is readable and fetches the ESI version string |
| slave_set_esi_file | bool | write-only | Sets the ESI file path for that slave | |
| File deep reads | EcEsi_MatchDevice / EcEsi_MatchRevision | int | read-only | Offline comparison of device identity and Revision |
| EcEsi_GetDeviceEeprom / EcEsi_GetDeviceBootstrap / EcEsi_GetDeviceElectrical / EcEsi_GetDevicePortInfo / EcEsi_GetDevicePdoDetail / EcEsi_GetDeviceCoEDetails / EcEsi_GetDeviceDcOpMode / EcEsi_GetDeviceSmDetail | int | read-only | Offline reads of the device's EEPROM / mailbox / electrical / port / PDO / CoE/PdoUpload / DC / SM fields | |
| Direct device field reads | EcEsi_GetDeviceIdentity / EcEsi_GetDevicePdoIndices / EcEsi_GetDevicePdoSizeBits / EcEsi_GetDeviceSmInfo / EcEsi_GetDeviceMailboxTimeout | int | read-only | Reads the identity, PDO, SM and mailbox timeouts of a bound Device by instance |
| EcEsi_GetDeviceDcSyncMode | int | read-only | Reads the DC synchronization grade declared by the ESI, by instance | |
| EcEsi_GetDeviceDcCycleTime0 | int64_t | read-only | Reads the SYNC0 cycle declared by the ESI (nanoseconds), by instance | |
| Registry and binding | esi_init | int | write-only | Installs the EcEsi_* interface into an esi_ctx_t |
| esi_dll_load_file / esi_dll_load_directory / esi_dll_bind_to_slave / esi_dll_auto_match_all / esi_dll_apply_all_slaves / esi_dll_register_startup_parameters | int | write-only | Loads ESI files, binds slaves and registers startup parameters | |
| esi_dll_clear | void | write-only | Clears the ESI cache | |
| esi_dll_get_loaded_count / esi_dll_has_esi_dc_sync / esi_dll_get_device_dc_sync_mode | int | read-only | Number of loaded files, the DC synchronization boolean verdict and the raw grade | |
| Structured ENI read/write | eni_config_load | int | read-only | Parses an ETG.2100 ENI into a DarraEniConfiguration |
| eni_config_save | int | write-only | Writes a DarraEniConfiguration back to an ETG.2100 skeleton file |
eni_config_load in utils/eni.h handles only the standard ENI; the older DENI format is out of its scope. It returns 0 = success, -1 = the file is unreadable, -2 = XML format error, -3 = the file is not a standard ENI. eni_config_save produces a standard-ENI compatible skeleton and returns 0 = success, -1 = invalid input parameters, -2 = XML construction or file write failed; a complete ENI still needs runtime data for the FMMU offsets / runtime DC SystemTime / cyclic frame list, so this entry point suits offline persistence and reload. DENI loading and delivery go through the DENI entry points listed in the C SDK overview.
Slave ESI convenience queries
Queries the ESI state by master / slave instance; slave_index starts at 1.
| Category | Function | Return type | Read/write | Description |
|---|---|---|---|---|
| Slave ESI | slave_has_esi(mi, si) | bool | read-only | Whether the SII read a VendorId (the identity is readable) |
| slave_set_esi_file(mi, si, path) | bool | write-only | Sets the ESI file path for that slave | |
| slave_get_esi_version(mi, si, buf, bufSize) | bool | read-only | Fetches the ESI version string into a caller buffer |
bool slave_has_esi(uint16_t mi, uint16_t si);
bool slave_set_esi_file(uint16_t mi, uint16_t si, const char* path);
bool slave_get_esi_version(uint16_t mi, uint16_t si, char* buf, int bufSize);
slave_set_esi_filereturns true on success;pathis the ESI file path and the buffer stays owned by the caller.slave_get_esi_versionreturns false immediately whenbufis null orbufSize <= 0; before the call it setsbuf[0]to 0, and on success it returns true after writing the version string.
The test behind slave_has_esi is the SII read a VendorId (the identity is readable), and it does not mean an ESI Device is bound. To confirm ESI binding / whether the identity is usable, you must call EcEsi_GetDeviceIdentity (slave/startup.h, see "Startup parameters and DC synchronization mode" below) — relying on slave_has_esi alone misreads "never bound to an ESI" as "there is a real ESI to compare against".
ESI file deep reads (by file path)
The entry points below read an ESI XML file directly; they do not depend on a master / slave instance and produce no bus traffic. Out-of-range values and missing fields are reported through the return values described here, never faked into defaults.
device_ordinal is the index of the <Device> element inside the file, starting at 0. Except for EcEsi_MatchDevice / EcEsi_MatchRevision, the convention is 0 = success, negative = failure.
| Category | Function | Return type | Read/write | Description |
|---|---|---|---|---|
| Identity comparison | EcEsi_MatchDevice(file_path, vendor_id, product_code, revision_no, check_revision_no, strict, out_matched_rev) | int | read-only | 1 = match / 0 = no match / negative = parameter or file error; when strict is a value other than 0, RevisionNo is compared strictly against the policy string, and on a match the device's actual RevisionNo is written back |
| EcEsi_MatchRevision(actual, expected, strategy) | int | read-only | 1 = match / 0 = no match; the policy string is case-insensitive, and it is always true when expected is 0 or the policy is NONE | |
| EEPROM | EcEsi_GetDeviceEeprom(file_path, device_ordinal, out_byte_size, config_data, config_cap, out_config_len) | int | read-only | Reads the device EEPROM configuration data; config_data has capacity config_cap, and the actual length is written to out_config_len |
| Mailbox | EcEsi_GetDeviceBootstrap(file_path, device_ordinal, out_send_off, out_send_size, out_recv_off, out_recv_size) | int | read-only | Reads the receive / send offsets and sizes of the Bootstrap mailbox |
| Electrical | EcEsi_GetDeviceElectrical(file_path, device_ordinal, out_ebus_current_ma) | int | read-only | Reads the EBus current (mA); may be negative (a supplying device) |
| Port | EcEsi_GetDevicePortInfo(file_path, device_ordinal, port_index, type_buf, type_cap, label_buf, label_cap) | int | read-only | Reads the type and label string of the given physical port |
| PDO | EcEsi_GetDevicePdoDetail(file_path, device_ordinal, direction, pdo_ordinal, out_index, name_buf, name_cap, out_is_fixed, out_is_mandatory, out_sm, out_entry_count, entry_idx, entry_sub, entry_bits, max_entries) | int | read-only | Reads the index / name / Fixed·Mandatory / SM / entry table of one PDO |
| CoE | EcEsi_GetDeviceCoEDetails(file_path, device_ordinal, out_sdo_info, out_pdo_assign, out_pdo_config, out_complete_access, out_segmented_sdo, out_diag_history, out_pdo_upload) | int | read-only | Reads the device CoE capability flags (SDO Info / PDO Assign / PDO Config / CompleteAccess / SegmentedSDO / DiagHistory / PdoUpload); PdoUpload is tri-state: 1 = the ESI declares SDO read-back of the PDO assignment / mapping, 0 = declared unsupported, -1 = not declared (treated as readable for compatibility) |
| CoE (per slave) | EcEsi_GetBoundSlaveCoEDetails(master_index, slave_index, out_sdo_info, out_pdo_assign, out_pdo_config, out_complete_access, out_segmented_sdo, out_diag_history, out_pdo_upload) | int | read-only | Reads the CoE capability flags for a bound slave — same shape as EcEsi_GetDeviceCoEDetails (same 7 out params, out_diag_history / out_pdo_upload tri-state), with no need to reverse-look-up the file and document ordinal first. 0 = success, -1 = bad parameters, -2 = no bound ESI Device, -3 = the bound Device has no <CoE>; any value other than 0 means unknown and all 7 out params are written as -1 |
| DC | EcEsi_GetDeviceDcOpMode(file_path, device_ordinal, op_mode_ordinal, out_assign_activate, out_cycle0, out_cycle0_factor, out_shift0, out_cycle1, out_cycle1_factor, out_shift1, out_has_unknown64bit) | int | read-only | Reads the N-th DC operation mode: AssignActivate + Cycle0 / Shift0 + Cycle1 / Shift1 and their factors |
| SM | EcEsi_GetDeviceSmDetail(file_path, device_ordinal, sm_doc_ordinal, out_name_buf, name_cap, out_start_addr, out_default_size, out_control_byte, out_enable, out_min_size, out_max_size) | int | read-only | Reads the details of the N-th SyncManager: name / start address / default size / control byte / Enable / Min·Max size |
int EcEsi_MatchDevice(const char* file_path, uint32_t vendor_id,
uint32_t product_code, uint32_t revision_no,
const char* check_revision_no, int strict,
uint32_t* out_matched_rev);
int EcEsi_MatchRevision(uint32_t actual, uint32_t expected, const char* strategy);
int EcEsi_GetDeviceEeprom(const char* file_path, int device_ordinal,
int* out_byte_size, char* config_data,
int config_cap, int* out_config_len);
int EcEsi_GetDeviceBootstrap(const char* file_path, int device_ordinal,
uint16_t* out_send_off, uint16_t* out_send_size,
uint16_t* out_recv_off, uint16_t* out_recv_size);
int EcEsi_GetDeviceElectrical(const char* file_path, int device_ordinal,
int* out_ebus_current_ma);
int EcEsi_GetDevicePortInfo(const char* file_path, int device_ordinal,
int port_index, char* type_buf, int type_cap,
char* label_buf, int label_cap);
int EcEsi_GetDevicePdoDetail(const char* file_path, int device_ordinal,
int direction, int pdo_ordinal,
uint16_t* out_index, char* name_buf, int name_cap,
int* out_is_fixed, int* out_is_mandatory,
uint8_t* out_sm, int* out_entry_count,
uint16_t* entry_idx, uint16_t* entry_sub,
uint16_t* entry_bits, int max_entries);
int EcEsi_GetDeviceCoEDetails(const char* file_path, int device_ordinal,
int* out_sdo_info, int* out_pdo_assign,
int* out_pdo_config, int* out_complete_access,
int* out_segmented_sdo, int* out_diag_history,
int* out_pdo_upload);
int EcEsi_GetBoundSlaveCoEDetails(uint16_t master_index, uint16_t slave_index,
int* out_sdo_info, int* out_pdo_assign,
int* out_pdo_config, int* out_complete_access,
int* out_segmented_sdo, int* out_diag_history,
int* out_pdo_upload);
int EcEsi_GetDeviceDcOpMode(const char* file_path, int device_ordinal,
int op_mode_ordinal, uint32_t* out_assign_activate,
int64_t* out_cycle0, int* out_cycle0_factor,
int64_t* out_shift0, int64_t* out_cycle1,
int* out_cycle1_factor, int64_t* out_shift1,
int* out_has_unknown64bit);
int EcEsi_GetDeviceSmDetail(const char* file_path, int device_ordinal,
int sm_doc_ordinal, char* out_name_buf, int name_cap,
uint16_t* out_start_addr, uint16_t* out_default_size,
uint8_t* out_control_byte, int* out_enable,
uint16_t* out_min_size, uint16_t* out_max_size);
Parameters and return values:
EcEsi_MatchDevice— whenstrictis a value other than 0, RevisionNo is compared strictly against thecheck_revision_nopolicy string; on a matchout_matched_revreceives the device's actual RevisionNo. Returns 1 = match, 0 = no match, negative = parameter or file error.EcEsi_MatchRevision—strategyis case-insensitive and takesNONE/EQ/EQ_OR_G/LW_EQ/HW_EQ/LW_EQ_OR_G/HW_EQ_OR_G; it is always true whenexpectedis 0 or the strategy isNONE. Returns 1 = match, 0 = no match.EcEsi_GetDeviceEeprom—config_capis the capacity ofconfig_data; the actual length read is written to*out_config_lenand the total byte count to*out_byte_size.EcEsi_GetDevicePortInfo—port_indexis the physical port number; the type and label are written intotype_buf(capacitytype_cap) andlabel_buf(capacitylabel_cap) respectively.EcEsi_GetDevicePdoDetail—direction: 0 = RxPDO, 1 = TxPDO;pdo_ordinalis the document order in that direction.entry_idx/entry_sub/entry_bitsare caller-provided entry-table arrays with capacitymax_entries, and the actual count is written to*out_entry_count.EcEsi_GetDeviceCoEDetails—out_pdo_uploadreports the declaration from the ESI<Mailbox><CoE PdoUpload="...">attribute as three states:1= explicitly declared true, meaning the device supports reading back the PDO assignment / mapping (0x1C12 / 0x1C13 / 0x1600 / 0x1A00) over SDO;0= explicitly declared false, meaning the device does not support read-back and the master must not treat an empty read-back as evidence that the configuration was cleared;-1= the attribute is not declared by the ESI and is treated as readable for compatibility (most ESI files omit it, and an undeclared attribute must not be folded into "unsupported").EcEsi_GetBoundSlaveCoEDetails— bit-for-bit the same output asEcEsi_GetDeviceCoEDetails, only the addressing differs: pass(master_index, slave_index)and the runtime locates the ESI Device by the bound slave (the same binding used at configuration / startup). Returns0= success,-1= bad parameters,-2= no bound ESI Device,-3= the bound Device has no<CoE>; any value other than 0 means unknown, and all 7 out params are then written as-1— never fold that into "explicitly unsupported".EcEsi_GetDeviceDcOpMode—op_mode_ordinalis the index of the DC operation mode inside the device;out_has_unknown64bitmarks whether that mode contains a value that cannot be parsed as 64-bit.EcEsi_GetDeviceSmDetail—sm_doc_ordinalis the document order of the SyncManager; it outputs the name, start address, default size, control byte, enable flag and Min / Max size.
Startup parameters and DC synchronization mode (startup.h)
The entry points below read fields of a bound ESI Device by (master_index, slave_index). The slave must be bound to an ESI first (esi_dll_load_file / esi_dll_load_directory, then bound by the connection setup flow, or explicitly with esi_dll_bind_to_slave / esi_dll_apply_all_slaves).
| Category | Function | Return type | Read/write | Description |
|---|---|---|---|---|
| Device identity | EcEsi_GetDeviceIdentity(mi, si, vendor_id, product_code, revision_no, name_buf, name_buf_size) | int | read-only | Fetches Vendor / Product / Revision / name; non-negative on success (the value is the name byte count, 0 when there is no name), negative on failure |
| PDO | EcEsi_GetDevicePdoIndices(mi, si, direction, out_indices, max_count) | int | read-only | Lists the Device's PDO indexes; returns the number written, -1 = no ESI bound / invalid parameter |
| EcEsi_GetDevicePdoSizeBits(mi, si, pdo_index) | int | read-only | Total bit length of the given PDO (including padding); returns -1 when not found | |
| SM | EcEsi_GetDeviceSmInfo(mi, si, sm_idx, start_addr, default_len, control_byte) | int | read-only | Fetches SyncManager information (sm_idx 0..3); 0 = success, a value other than 0 = failure |
| DC | EcEsi_GetDeviceDcSyncMode(mi, si) | int | read-only | DC synchronization grade declared by the ESI; -2 = not bound / invalid parameter, -1 = no <Dc> node |
| EcEsi_GetDeviceDcCycleTime0(mi, si) | int64_t | read-only | SYNC0 cycle declared by the ESI (nanoseconds); a non-negative value is the cycle (0 = not declared by the ESI), -2 = not bound / parameter error, -1 = runtime interface not ready | |
| Mailbox | EcEsi_GetDeviceMailboxTimeout(mi, si, request_ms, response_ms) | int | read-only | Mailbox Request / Response timeout (milliseconds); 0 = success, a value other than 0 = failure |
int EcEsi_GetDeviceIdentity(uint16_t master_index, uint16_t slave_index,
uint32_t* vendor_id, uint32_t* product_code,
uint32_t* revision_no, char* name_buf, int name_buf_size);
int EcEsi_GetDevicePdoIndices(uint16_t master_index, uint16_t slave_index,
int direction, uint16_t* out_indices, int max_count);
int EcEsi_GetDevicePdoSizeBits(uint16_t master_index, uint16_t slave_index,
uint16_t pdo_index);
int EcEsi_GetDeviceSmInfo(uint16_t master_index, uint16_t slave_index, uint8_t sm_idx,
uint16_t* start_addr, uint16_t* default_len,
uint8_t* control_byte);
int EcEsi_GetDeviceDcSyncMode(uint16_t master_index, uint16_t slave_index);
int64_t EcEsi_GetDeviceDcCycleTime0(uint16_t master_index, uint16_t slave_index);
int EcEsi_GetDeviceMailboxTimeout(uint16_t master_index, uint16_t slave_index,
int* request_ms, int* response_ms);
Parameters and return values:
EcEsi_GetDevicePdoIndices—direction: 0 = RxPDO (master to slave outputs), 1 = TxPDO (slave to master inputs);max_countis the capacity ofout_indices.EcEsi_GetDeviceDcCycleTime0— the value is parsed as written in the ESI (decimal /#x/0x). A return of 0 means the ESI did not declare it or declared 0; the caller should use its own default cycle and must not hide the ESI declaration behind a hard-coded cycle.EcEsi_GetDeviceMailboxTimeout— both output parameters may be NULL if you only need one; do not interpret the outputs when the return value is anything other than 0.
Value path and failure codes of EcEsi_GetDeviceIdentity:
- When an ESI Device is bound, the runtime reads it directly, including the device name, and returns the name byte count on success (0 when there is no name).
- When nothing is bound, it re-locates the Device by the measured Vendor / Product (/ Revision) of that slave among the ESI sources loaded in this process (including an ESI directory next to the executable): success likewise returns non-negative (with an empty device name, returning 0), Vendor / Product are the measured values and Revision is the value declared by the ESI; parsing and matching both happen inside the runtime, and no other device's name is passed off as this one.
- When the directory fallback fails, it returns a distinguishable failure code and writes a readable reason into
name_buf: -1 invalid parameter (the same code as the runtime interface not being loaded), -4 measured Vendor / Product read as 0 (the SII identity is not ready), -5 no usable ESI source, -6 no matching Device in the source, -7 the directory scan exceeded its time budget (the verdict is incomplete and must not be treated as "no match"), -8 the runtime is missing a required entry point. - The query is read-only: the fallback neither creates nor revokes an ESI binding, and it changes no runtime behaviour of DC / SM.
DC synchronization grades (same convention as DC synchronization):
| Category | Value | Meaning | Read/write | Description |
|---|---|---|---|---|
| DC grade | 3 | DC-Sync0 + SYNC1 | read-only | AssignActivate contains the SYNC1 enable bit; only this grade may request DC-Sync01 |
| 2 | DC-Sync0 only | read-only | AssignActivate is non-zero but has no SYNC1 enable bit; only DC-Sync0 is possible | |
| 1 | SM-Sync | read-only | SM is enabled but AssignActivate has no SYNC0 enable bit; this is not DC synchronization | |
| 0 | FreeRun | read-only | The ESI has a <Dc> node but no OpMode | |
| -1 | No <Dc> node | read-only | The slave does not use DC and should run FreeRun | |
| -2 | Not bound / invalid parameter | read-only | Cannot be decided; the caller should fall back to the ESC hardware DC capability query |
There is exactly one rule: only grade 3 may request DC-Sync01; grade 2 allows DC-Sync0 only. Treating 2 as 3 (forcing SYNC1 on) makes a slave that declares Sync0 only refuse to enter OP, and it does not necessarily report an AL status code.
The 0 = not declared / cannot be decided in slave_esi_dc_sync_mode() on the DC synchronization page is the view of this table's raw grades after folding -1 / -2; this table lists the raw values from utils/esi_ext.h, and the two do not contradict each other.
ESI registry and binding (utils/esi_ext.h)
esi_init fills an esi_ctx_t with the EcEsi_* function pointers in one call, and every subsequent esi_dll_* entry point takes that context as its first parameter.
| Category | Function | Return type | Read/write | Description |
|---|---|---|---|---|
| Context | esi_init(ctx) | int | write-only | Installs the EcEsi_* interface into the context; 1 = filled successfully, 0 = ctx is null |
| File loading | esi_dll_load_file(ctx, file_path) | int | write-only | Loads a single ESI file; returns the number of Devices, 0 = failure |
| esi_dll_load_directory(ctx, dir_path) | int | write-only | Loads every .xml / .ESI file in the directory; returns the cumulative Device count | |
| Cache | esi_dll_clear(ctx) | void | write-only | Clears the ESI cache |
| esi_dll_get_loaded_count(ctx) | int | read-only | Number of loaded files | |
| Binding | esi_dll_bind_to_slave(ctx, mi, si, file_path) | int | write-only | Binds an ESI to a single slave (slave_index starts at 1); positive = bound, 0 = failure, negative = parameter error |
| esi_dll_auto_match_all(ctx, mi) | int | write-only | Automatically matches an ESI for every slave under the master; returns the number of slaves matched successfully | |
| esi_dll_apply_all_slaves(ctx, mi) | int | write-only | Registers the startup parameters for every matched slave after automatic matching; returns the total number of registered parameters | |
| Startup parameters | esi_dll_register_startup_parameters(ctx, mi, si) | int | write-only | Registers the startup parameters from the ESI for the given slave; returns the number registered successfully, negative = failure |
| DC queries | esi_dll_has_esi_dc_sync(ctx, mi, si) | int | read-only | 1 = the ESI declares DC synchronization, 0 = it does not |
| esi_dll_get_device_dc_sync_mode(ctx, mi, si) | int | read-only | DC synchronization grade declared by the ESI (raw value, see the table above); returns -2 for an invalid ctx |
typedef struct {
esi_pfn_load_file_t LoadFile;
esi_pfn_load_directory_t LoadDirectory;
esi_pfn_clear_t Clear;
esi_pfn_get_loaded_count_t GetLoadedCount;
esi_pfn_bind_to_slave_t BindToSlave;
esi_pfn_auto_match_all_t AutoMatchAll;
esi_pfn_apply_all_t ApplyAllSlaves;
esi_pfn_register_startup_t RegisterStartupParameters;
esi_pfn_get_dc_sync_mode_t GetDeviceDcSyncMode;
} esi_ctx_t;
int esi_init(esi_ctx_t* ctx);
int esi_dll_load_file(const esi_ctx_t* ctx, const char* file_path);
int esi_dll_load_directory(const esi_ctx_t* ctx, const char* dir_path);
void esi_dll_clear(const esi_ctx_t* ctx);
int esi_dll_get_loaded_count(const esi_ctx_t* ctx);
int esi_dll_bind_to_slave(const esi_ctx_t* ctx,
uint16_t master_index, uint16_t slave_index,
const char* file_path);
int esi_dll_auto_match_all(const esi_ctx_t* ctx, uint16_t master_index);
int esi_dll_apply_all_slaves(const esi_ctx_t* ctx, uint16_t master_index);
int esi_dll_register_startup_parameters(const esi_ctx_t* ctx,
uint16_t master_index, uint16_t slave_index);
int esi_dll_has_esi_dc_sync(const esi_ctx_t* ctx,
uint16_t master_index, uint16_t slave_index);
int esi_dll_get_device_dc_sync_mode(const esi_ctx_t* ctx,
uint16_t master_index, uint16_t slave_index);
Semantic points:
esi_initalways fills successfully: the EcEsi_* entry points exist at compile time and return zero values rather than a missing symbol when the runtime is not ready, so a return of 1 only means the context is filled, not that the runtime is ready; check "SDK readiness check" in the C SDK overview for the runtime state.- The context must be zeroed and passed to
esi_initbefore anyesi_dll_*call. Apart fromesi_initreturning 0 (ctx is null), when ctx or a function pointer is null each entry point returns its own failure value: the load / bind / count families return 0, the register family returns -1, the DC grade query returns -2;esi_dll_has_esi_dc_syncfalls back to the ESC hardware DC capability bit. esi_dll_has_esi_dc_syncdecides as follows: grade 2 or 3 (DC-Sync0 / DC-Sync01) is true; 0 / 1 (FreeRun / SM-Sync) is false; -1 (no<Dc>in the ESI) is false; -2 (not bound / parameter error) falls back to the ESC hardware DC capability bit, conservatively avoiding turning DC off by mistake.- Before enabling DC,
GetSlaveHasDCandesi_dll_has_esi_dc_syncmust both be true: some slaves report the DC capability from the ESC while their ESI has no<Dc>OpMode, and forcing DC on makes their DC register write return WKC=0, or leaves a half-activated DC stuck in SafeOP→OP. - Prerequisite: the ESI has been loaded with
esi_dll_load_directory/esi_dll_load_fileand bound when entering PreOp automatically (or explicitly withesi_dll_apply_all_slaves); while unbound, a reading only means "cannot be decided" and must not be used to conclude that the slave does not support DC.
Typical flow
#include "ethercat.h"
#include <stdio.h>
int main(void)
{
esi_ctx_t esi = {0}; /* Clear it to zero before calling*/
if (!esi_init(&esi)) return 1; /* Fill in the EcEsi_* context*/
/* 1. Hand the ESI to the SDK: all .xml/.ESI in the directory, or a single file*/
if (esi_dll_load_directory(&esi, "C:\\EtherCAT\\ESI") <= 0) {
printf("没有加载到 Device\n"); /* Nothing has been loaded into Device */
return 1;
}
printf("已加载 ESI 文件 %d 个\n", esi_dll_get_loaded_count(&esi)); /* %d ESI files loaded */
uint16_t master = Initialize();
SetNetwork(master, "\\Device\\NPF_{GUID}", "");
SetStateSequence(master, EC_STATE_OPERATIONAL, 10000); /* Binding is completed when the link is established*/
/* You can also bind a single station explicitly:
esi_dll_bind_to_slave(&esi, master, 1, "C:\\EtherCAT\\ESI\\device.xml"); */
/* 2. Confirm the identity (read the bound path directly; on failure distinguish fallback from not-ready by the return code)*/
uint32_t vendor = 0, product = 0, revision = 0;
char name[128];
int rc = EcEsi_GetDeviceIdentity(master, 1, &vendor, &product, &revision,
name, (int)sizeof(name));
if (rc >= 0) {
printf("Vendor=0x%08X Product=0x%08X Rev=0x%08X 名称=%s\n", /* Vendor=0x%08X Product=0x%08X Rev=0x%08X name=%s */
vendor, product, revision, (rc > 0) ? name : "(空)");
} else {
printf("身份读取失败: %d\n", rc); /* -4..-8 see the failure code notes above*/
}
/* 3. Read the PDO capabilities*/
uint16_t pdos[32];
int n = EcEsi_GetDevicePdoIndices(master, 1, 1 /* TxPDO */, pdos, 32);
for (int i = 0; i < n; i++) {
printf("TxPDO 0x%04X: %d bit\n",
pdos[i], EcEsi_GetDevicePdoSizeBits(master, 1, pdos[i]));
}
/* 4. Read the DC capability: check first whether the ESI declares DC synchronisation, then take the declared SYNC0 cycle time*/
if (esi_dll_has_esi_dc_sync(&esi, master, 1)) {
int mode = esi_dll_get_device_dc_sync_mode(&esi, master, 1);
int64_t cycle0 = EcEsi_GetDeviceDcCycleTime0(master, 1);
printf("DC 档位=%d SYNC0=%lld ns\n", mode, (long long)cycle0); /* DC tier=%d SYNC0=%lld ns */
/* A cycle0 of 0 means the ESI does not declare one; use your own default cycle*/
}
/* 5. Register the startup parameters from the ESI into that slave's startup queue*/
printf("注册启动参数 %d 条\n", esi_dll_register_startup_parameters(&esi, master, 1)); /* %d startup parameters registered */
EcClose(master);
return 0;
}