Configuration
Startup parameters
Startup parameters are the SDO and register sequence that the master writes to a slave automatically around ESM state transitions, following the ETG.1500 PO->SO Init command convention. They cover vendor-specific initialization sequences (mapping PDOs, setting the operating mode, writing motor parameters and so on), so the caller does not have to write a state machine: the SDK applies them in transition + priority order during SetStateSequence.
The startup parameter queue also provides two snapshot entry points: a read-only query, and a whole-queue replace with optimistic concurrency on the version number.
| Category | Function | Return type | Read/write | Description |
|---|---|---|---|---|
| Startup parameter | ReadStartupSnapshot(mi, si, buffer, capacity, required, generation, revision, source_flags) | int | Read-only | Read-only snapshot of the startup parameters; the queue is not modified. Insufficient capacity does not truncate (buffer is left as it is) and required returns the real count, so the caller can grow the buffer and retry |
| Startup parameter | ReplaceStartupSnapshot(mi, si, params, count, expected_generation, expected_revision, new_revision) | int | Write-only | Whole-queue replace with optimistic concurrency on (generation, revision); a mismatch is rejected and never silently overwrites a queue someone else just wrote; the new version number is written to new_revision |
AddStartupParameter()
int AddStartupParameter(uint16_t master_index, uint16_t slave_index,
const ec_startup_param_t* param);
Appends one startup parameter to the given slave. The parameter is cached in the slave slot and applied in priority order during state transitions.
Parameters:
master_index(uint16_t) — master indexslave_index(uint16_t) — slave index (1-based)param(const ec_startup_param_t*) — startup parameter description
Returns:
int— 0 = success, a value other than 0 = failure (slave does not exist / slots full / invalid parameter)
Related structure:
#pragma pack(push, 1)
typedef struct {
uint16_t index; /* SDO index */
uint8_t sub_index; /* SDO sub-index */
uint8_t data[256]; /* parameter data (EC_STARTUP_PARAM_MAX_DATA) */
uint16_t data_len; /* data length (bytes) */
uint8_t transition; /* transition flag (EC_TRANS_*) */
uint8_t timing; /* execution timing (EC_TIMING_*) */
uint16_t priority; /* execution priority (lower runs first) */
uint8_t complete_access; /* complete access (CA=1 writes the whole index) */
uint8_t is_register_write; /* 1 = register write, 0 = SDO write */
} ec_startup_param_t;
#pragma pack(pop)
transition:EC_TRANS_IP=0(Init→PreOp),EC_TRANS_PS=1(PreOp→SafeOp),EC_TRANS_SO=2(SafeOp→OP),EC_TRANS_OS=3,EC_TRANS_SP=4,EC_TRANS_PI=5timing:EC_TIMING_BEFORE=0(applied before the transition),EC_TIMING_AFTER=1(applied after the transition)- At most
EC_MAX_STARTUP_PARAMS=128entries per slave
Add every entry before SetStateSequence/SetStateWithStartup. Entries added after the network is already in OP do not take effect in the current cycle; run the state transition again.
Example:
/* write the motor operating mode = 8 before PreOp (CSP, CiA402) */
ec_startup_param_t p = {0};
p.index = 0x6060;
p.sub_index = 0x00;
p.data[0] = 8;
p.data_len = 1;
p.transition = EC_TRANS_PS; /* PreOp → SafeOp */
p.timing = EC_TIMING_BEFORE;
p.priority = 100;
p.complete_access = 0;
p.is_register_write = 0;
if (AddStartupParameter(master, 1, &p) != 0)
printf("启动参数追加失败\n"); /* Failed to append the startup parameter */
Since C99 a designated initializer fits this on one line: ec_startup_param_t sp = EC_SDO_DOWNLOAD_SHORT(0x6060, 0, 8, /*priority*/100);. Cycle, CPU and priority also have 4 preset macros — EC_PRESET_CYCLE_4MS / 1MS / 500US / 250US — or fill only the fields you want with ec_cycle_preset_t cfg = { .cycle_ns = 1000000 }.
ApplyStartupParameters()
int ApplyStartupParameters(uint16_t master_index, uint16_t slave_index,
uint8_t transition, uint8_t timing);
Applies the startup parameters matching (transition + timing) to the given slave immediately, for manual driving scenarios (when you skip the SetStateSequence pipeline).
Parameters:
master_index(uint16_t) — master indexslave_index(uint16_t) — slave index (1-based)transition(uint8_t) — state transition flag (EC_TRANS_*)timing(uint8_t) — execution timing (EC_TIMING_BEFORE/EC_TIMING_AFTER)
Returns:
int— number of parameters applied successfully; a negative value means failure
Almost every application can just use SetStateSequence; the framework calls this function automatically before and after each transition. Call it manually only when a custom state machine needs exact control of the timing.
Example:
/* manual: apply the EC_TRANS_PS / BEFORE stage before PreOp → SafeOp */
int n = ApplyStartupParameters(master, 1, EC_TRANS_PS, EC_TIMING_BEFORE);
printf("从站1 应用了 %d 条启动参数\n", n); /* Applied %d startup parameters to slave1 */
ApplyStartupParametersAll()
int ApplyStartupParametersAll(uint16_t master_index, uint8_t transition, uint8_t timing);
Applies the startup parameters matching (transition + timing) to every slave in one call; equivalent to calling ApplyStartupParameters in a loop.
Parameters:
master_index(uint16_t) — master indextransition(uint8_t) — state transition flag (EC_TRANS_*)timing(uint8_t) — execution timing (EC_TIMING_BEFORE/EC_TIMING_AFTER)
Returns:
int— total number of parameters applied successfully; a negative value means failure
Example:
/* apply the PS/BEFORE stage to all slaves before entering OP */
ApplyStartupParametersAll(master, EC_TRANS_PS, EC_TIMING_BEFORE);
SetStateWithTimeout(master, EC_STATE_SAFE_OP, 5000);
ApplyStartupParametersAll(master, EC_TRANS_PS, EC_TIMING_AFTER);
Related helpers
ClearStartupParameters(mi, si)→int— clears every startup parameter of the given slaveGetStartupParameterCount(mi, si)→int— returns how many startup parameters the given slave currently has cachedAddStartupParameterBatch(mi, si, params, count)→int— appends a batch in one call (avoids the overhead of calling per entry in a loop)
ReadStartupSnapshot()
int ReadStartupSnapshot(uint16_t master_index, uint16_t slave_index,
ec_startup_param_t* buffer, int capacity,
int* required, uint32_t* generation,
uint64_t* revision, uint32_t* source_flags);
Takes a read-only snapshot of the startup parameter queue without changing its contents. Insufficient capacity never truncates: buffer is left as it is and required returns the real count, so the caller can grow the buffer and retry.
Parameters:
master_index(uint16_t) — master indexslave_index(uint16_t) — slave index (1-based)buffer(ec_startup_param_t*) — array that receives the snapshotcapacity(int) — array capacity (entries)required(int*) — output: real number of entriesgeneration(uint32_t*) — output: generation the snapshot belongs torevision(uint64_t*) — output: queue version numbersource_flags(uint32_t*) — output: source flags
Returns:
int— 0 = success
Example:
ec_startup_param_t params[EC_MAX_STARTUP_PARAMS];
int required = 0;
uint32_t gen = 0;
uint64_t rev = 0;
uint32_t flags = 0;
if (ReadStartupSnapshot(master, 1, params, EC_MAX_STARTUP_PARAMS,
&required, &gen, &rev, &flags) == 0) {
printf("从站1 共 %d 条启动参数, generation=%u revision=%llu\n", /* Slave1 has %d startup parameters in total, generation=%u revision=%llu */
required, gen, (unsigned long long)rev);
}
ReplaceStartupSnapshot()
int ReplaceStartupSnapshot(uint16_t master_index, uint16_t slave_index,
const ec_startup_param_t* params, int count,
uint32_t expected_generation,
uint64_t expected_revision,
uint64_t* new_revision);
Replaces the whole queue with optimistic concurrency on (generation, revision). A mismatch is rejected, so a queue someone else just wrote is never silently overwritten; on success the new version number is written to new_revision.
Parameters:
master_index(uint16_t) — master indexslave_index(uint16_t) — slave index (1-based)params(const ec_startup_param_t*) — new queue contentscount(int) — number of entries in the new queueexpected_generation(uint32_t) — expected generation (from ReadStartupSnapshot)expected_revision(uint64_t) — expected version number (from ReadStartupSnapshot)new_revision(uint64_t*) — output: new version number after the replace
Returns:
int— 0 = success; expected values do not match = rejected (queue unchanged)
Example:
uint64_t new_rev = 0;
if (ReplaceStartupSnapshot(master, 1, params, required, gen, rev, &new_rev) != 0) {
/* someone else changed it in the meantime: read the snapshot again before deciding, do not just overwrite */
}
JSON configuration loading
LoadConfigJson()
int LoadConfigJson(uint16_t master_index, const char* json_str);
Loads configuration (including slave startup parameters) from JSON or DENI/ENI XML text. Returns 0 = success, a negative value = failure (the error code can be turned into a readable reason with describe_load_config_error).
The argument is configuration content (JSON or DENI/ENI XML text), not a file path. To load a product DENI/ENI from a path, read the whole file yourself first and then pass the content to this function (see the Initialization examples). deni_load reads only the legacy offline structure and does not apply to product DENI; eni_load is for offline structure reads of standard ENI.
AutoConfigureSM()
int AutoConfigureSM(uint16_t master_index, uint16_t slave_index);
Computes SM2/SM3 automatically from the startup parameters. With slave_index=0 every slave is processed.
Log control
void SetPDOLogging(BOOL enable);
void SetMailboxLogging(BOOL enable);
void SetDebugLogging(BOOL enable);
Log categories:
typedef enum {
LOG_CATEGORY_ERROR = 0,
LOG_CATEGORY_WARNING = 1,
LOG_CATEGORY_MESSAGE = 2,
LOG_CATEGORY_MAILBOX = 3,
LOG_CATEGORY_PDO = 4,
LOG_CATEGORY_DEBUG = 5
} log_category_t;
Mutex protection
void SetMutexProtection(uint16_t master_index, BOOL enable);
BOOL GetMutexProtection(uint16_t master_index);
Mutex protection switch. It controls whether PDO reads and writes take a lock automatically to stay thread-safe.
- Enabled (default) — the framework locks automatically, so access is thread-safe
- Disabled — the automatic mutex is off; you manage thread safety yourself and save the lock contention overhead
With mutex protection disabled you must keep PDO data thread-safe yourself. This suits scenarios with very tight latency requirements where you can manage concurrency on your own.
IOmap locking
void LockIOmap(uint16_t master_index);
void UnlockIOmap(uint16_t master_index);
Locks and unlocks the IOmap manually, for atomic multi-axis batch writes. With SetMutexProtection(mi, FALSE) you call these functions yourself to keep PDO data atomic.
Three thread-safety modes compared:
| Mode | Setting | Latency | Use case |
|---|---|---|---|
| Automatic mutex | SetMutexProtection(mi, TRUE) (default) | ~200ns | General use; thread safety handled for you |
| Manual lock | SetMutexProtection(mi, FALSE) + LockIOmap/UnlockIOmap | Same as the automatic mutex | Multi-axis interpolation that needs atomic batch writes |
| No lock | SetMutexProtection(mi, FALSE), Lock not called | 0 | Single-threaded writes with no contention |
In coordinated multi-axis interpolation the target positions of several slaves must take effect within the same PDO cycle. A manual IOmap lock commits a batch of writes atomically inside one PDO frame.
Example (multi-axis interpolation, batch write):
// turn off the automatic mutex
SetMutexProtection(mi, FALSE);
// batch write inside the PDO callback
void pdo_callback(uint16_t mi) {
LockIOmap(mi);
// every write happens under the same lock, so the batch is atomic
uint32_t written = 0, required = 0;
// size must equal the slave's current full output frame length (4 bytes here); otherwise it returns 3 and writes nothing
WriteSlaveOutputPdo(mi, 1, target_pos1_data, 4, &written, &required);
WriteSlaveOutputPdo(mi, 2, target_pos2_data, 4, &written, &required);
WriteSlaveOutputPdo(mi, 3, target_pos3_data, 4, &written, &required);
UnlockIOmap(mi);
}
PDO cycle configuration
SetMasterLoopCycleTime()
void SetMasterLoopCycleTime(uint16_t master_index, uint32_t time_ns);
PDO exchange cycle time, in nanoseconds (ns).
The master's real-time thread sends and receives PDO frames at this cycle. The value sets how often process data is refreshed between master and slaves — smaller values refresh faster but demand more from the system's real-time behaviour. Real-time mode supports a minimum of 31 µs (= 31,000 ns, whole microseconds) — the product's minimum cycle is 31 µs, which is the specification floor.
On Windows stay at or above 125,000ns (125 µs). Real-time mode fully supports the 31 µs specification floor (= 31,000 ns, whole microseconds); smaller values mean nothing on Windows because the application layer cannot write at a higher rate.
Example:
SetMasterLoopCycleTime(mi, 1000000); /* 1ms = 1,000,000ns */
SetMasterLoopCycleTime(mi, 500000); /* 500 µs = 500,000ns */
SetMasterLoopCycleTime(mi, 250000); /* 250 µs = 250,000ns */
SetMasterLoopCycleTime(mi, 125000); /* 125 µs = 125,000ns (recommended minimum on Windows) */
DC drift compensation is automatic; no extra configuration is needed.
Mailbox frames (SDO reads and writes, FoE file transfer, emergency messages and so on) ride along in the PDO cycle and use no extra frames.
Mailbox response latency: about 2-3 PDO cycles. With LoopCycle=1ms, an SDO read takes about 2-3ms.
config_set_high_resolution_timer()
int config_get_high_resolution_timer(void);
int config_set_high_resolution_timer(int enable);
Read: whether the system clock resolution is already 1 ms (or finer); the result is not hard-wired to false. Write: turn it on or off for this process, effective immediately. The installer leaves it off; you set it in the cycle configuration. With it on, waits are more accurate but the mouse may feel sluggish; PDO on isolated cores does not depend on it. It is a no-op on non-Windows systems.
The read returns whether the system is already at 1 ms; it is not hard-wired to false, and the installer does not turn it on.
Example:
config_set_high_resolution_timer(1);
Communication configuration properties
The settings below are read and written through inline functions in master/config.h, calling the public config_* / Set* interfaces directly.
Using these functions requires master/config.h, which ethercat.h already includes for you.
All config_get_* / config_set_* functions are plain C functions called directly — no DLL handle, no function-pointer table. The first argument is master, so a full call looks like config_set_frame_repeat_count(mi, 2). Exception: config_get_high_resolution_timer / config_set_high_resolution_timer are process-wide and take no master argument.
| Category | Function (Get/Set) | Type | Read/write | Default | Description |
|---|---|---|---|---|---|
| Frame priority | config_get/set_frame_high_priority(master) | BOOL | Read/write | FALSE | OS-level frame priority (Linux: SO_PRIORITY, Windows: thread priority) |
| PDO optimization | config_get/set_overlapping_groups(master) | BOOL | Read/write | FALSE | FMMU logical-address overlapping mode (TI ESC); set only in INIT/PREOP |
| config_get/set_packed_mode(master) | BOOL | Read/write | FALSE | Bit-packed PDO mapping (Beckhoff EL1008/EL2008); set only in INIT/PREOP | |
| Frame repeat | config_get/set_frame_repeat_count(master) | uint8_t | Read/write | 1 | PDO frames sent per cycle (1 = disabled, 2-3 = ETG.1500 5.4.3) |
| Frame loss detection | config_get/set_filter_threshold(master) | uint16_t | Read/write | 3 | Consecutive lost-frame threshold; reaching it fires the PDOFrameLoss callback |
| Adaptive timeout | config_get/set_adaptive_timeout(master) | BOOL | Read/write | FALSE | Adjusts the PDO timeout dynamically from the network RTT |
| State timeout | config_get/set_timeout_init_to_preop(master) | uint32_t | Read/write | 3000 | INIT→PREOP timeout (ms; the default follows ETG.1020 §9.4 Table 55) |
| config_get/set_timeout_preop_to_safeop(master) | uint32_t | Read/write | 10000 | PREOP→SAFEOP timeout (ms, same basis, ETG.1020 §9.4 Table 55) | |
| config_get/set_timeout_safeop_to_op(master) | uint32_t | Read/write | 10000 | SAFEOP→OP timeout (ms, same basis, ETG.1020 §9.4 Table 55) | |
| Watchdog | config_get/set_pd_watchdog_ms(master) | uint16_t | Read/write | 0 | Process data watchdog timeout (ms; 0 = slave default, ETG.1000.4) |
| config_get/set_pdi_watchdog_ms(master) | uint16_t | Read/write | 0 | PDI watchdog timeout (ms; 0 = slave default) | |
| VLAN | config_get/set_vlan_id(master) | uint16_t | Read/write | 0 | VLAN ID (0 = disabled, 1-4095, IEEE 802.1Q); real-time mode only |
| config_get/set_vlan_priority(master) | uint8_t | Read/write | 0 | VLAN priority PCP (0-7, 7 highest); VlanId must be set first | |
| PDO cycle | SetMasterLoopCycleTime(master, time_ns) | void | Write-only | 1000000 | PDO exchange cycle (ns) |
| PDO cycle | DarraEcat_GetMasterLoopCycleTime(master) | uint32_t | Read-only | — | Reads back the current PDO exchange cycle (ns); provided under the DarraEcat_ name only, with no short-name wrapper |
| High-resolution timer | config_get/set_high_resolution_timer() | int | Read/write | — | The read returns whether the system is already at 1 ms, not hard-wired to false; the write turns it on or off for this process with immediate effect. The installer leaves it off |
| UDP | SetUdpMode(master, enable) / GetUdpMode(master) | BOOL | Read/write | FALSE | UDP frame transmission mode (ETG.1500 5.3.7) |
| IsUdpAvailable(master) | BOOL | Read-only | - | Whether UDP frame transmission is available |
Frame priority
BOOL config_get_frame_high_priority(uint16_t master);
int config_set_frame_high_priority(uint16_t master, BOOL enabled); /* 0 = written, -1 = not written (master state unavailable) */
Raises frame transmission priority at the OS level. It does not insert a VLAN tag and is independent of the VLAN feature.
PDO optimization
/* Overlapping Groups (TI ESC overlapping mode) */
BOOL config_get_overlapping_groups(uint16_t master);
int config_set_overlapping_groups(uint16_t master, BOOL enabled); /* 0 = written, -1 = not written (master state unavailable) */
/* Packed PDO mapping (bit-level IO modules) */
BOOL config_get_packed_mode(uint16_t master);
int config_set_packed_mode(uint16_t master, BOOL enabled); /* 0 = written, -1 = not written (master state unavailable) */
Set Overlapping Groups and Packed Mode only in INIT or PRE_OP; changes made in SafeOp/OP have no effect.
Frame repeat (ETG.1500 5.4.3)
uint8_t config_get_frame_repeat_count(uint16_t master);
int config_set_frame_repeat_count(uint16_t master, uint8_t count); /* 0 = written, -1 = not written (master state unavailable), -2 = value out of range (count not in 1-3, not written) */
How many times the same frame is sent in each PDO cycle. count=1 disables it (default), count=2-3 enables it. The slave must support frame repeat (mark it with SetSlaveSupportsFrameRepeat).
Frame loss detection threshold (filter_threshold)
uint16_t config_get_filter_threshold(uint16_t master);
int config_set_filter_threshold(uint16_t master, uint16_t threshold); /* 0 = written, -1 = not written (master state unavailable) */
The PDOFrameLoss callback fires when this many consecutive frames are lost. The default is 3.
Adaptive timeout
BOOL config_get_adaptive_timeout(uint16_t master);
int config_set_adaptive_timeout(uint16_t master, BOOL enabled); /* 0 = written, -1 = not written (master state unavailable) */
When enabled, the PDO timeout follows the network round-trip time (RTT) dynamically; this suits networks whose latency fluctuates.
State transition timeouts (ETG.1020)
/* INIT → PREOP (default 3000 ms) */
uint32_t config_get_timeout_init_to_preop(uint16_t master);
int config_set_timeout_init_to_preop(uint16_t master, uint32_t timeout_ms); /* 0 = written, -1 = not written (master state unavailable) */
/* PREOP → SAFEOP (default 10000 ms) */
uint32_t config_get_timeout_preop_to_safeop(uint16_t master);
int config_set_timeout_preop_to_safeop(uint16_t master, uint32_t timeout_ms); /* 0 = written, -1 = not written (master state unavailable) */
/* SAFEOP → OP (default 10000 ms) */
uint32_t config_get_timeout_safeop_to_op(uint16_t master);
int config_set_timeout_safeop_to_op(uint16_t master, uint32_t timeout_ms); /* 0 = written, -1 = not written (master state unavailable) */
State transition timeout control. Set it before SetStateSequence or SetStateWithTimeout; it adjusts how long the master waits for slave responses.
Process data watchdog (ETG.1000.4)
/* process data watchdog (default 0 = slave default) */
uint16_t config_get_pd_watchdog_ms(uint16_t master);
int config_set_pd_watchdog_ms(uint16_t master, uint16_t timeout_ms); /* 0 = written, -1 = not written (master state unavailable) */
/* PDI watchdog (default 0 = slave default) */
uint16_t config_get_pdi_watchdog_ms(uint16_t master);
int config_set_pdi_watchdog_ms(uint16_t master, uint16_t timeout_ms); /* 0 = written, -1 = not written (master state unavailable) */
Global watchdog timeout configuration. A value of 0 uses the default stored in the slave EEPROM. It is independent of the per-slave watchdog SetSlaveWatchdog.
UDP frame transmission (ETG.1500 5.3.7)
BOOL SetUdpMode(uint16_t master_index, BOOL enable);
BOOL GetUdpMode(uint16_t master_index);
BOOL IsUdpAvailable(uint16_t master_index);
Enables UDP frame transmission mode. IsUdpAvailable reports whether the current environment supports UDP transmission.
VLAN configuration (IEEE 802.1Q)
uint16_t config_get_vlan_id(uint16_t master);
int config_set_vlan_id(uint16_t master, uint16_t vlan_id); /* 0 = written, -1 = not written (master state unavailable), -2 = value out of range (vlan_id > 4095, not written) */
uint8_t config_get_vlan_priority(uint16_t master);
int config_set_vlan_priority(uint16_t master, uint8_t priority); /* 0 = written, -1 = not written (master state unavailable), -2 = value out of range (priority > 7, not written) */
Most standard EtherCAT slaves (Beckhoff EK/EL series and similar) do not support VLAN frames. Enabling VLAN widens the frame header from 14 to 18 bytes, and incompatible slaves drop the frame outright (WKC=0). Enable it only when every slave is confirmed to support 802.1Q.
- Takes effect in real-time mode only
- Set
VlanIdbeforeSetNetwork VlanPrioritytakes effect only whenVlanIdis non-zero
Configuration example
uint16_t mi = Initialize();
/* set the state transition timeouts (config_* are plain C functions; the first argument is the master index) */
config_set_timeout_init_to_preop(mi, 5000);
config_set_timeout_preop_to_safeop(mi, 15000);
config_set_timeout_safeop_to_op(mi, 10000); /* = ETG.1020 Table 55 default */
/* enable frame priority */
config_set_frame_high_priority(mi, TRUE);
/* set frame repeat (the slave must support it) */
config_set_frame_repeat_count(mi, 2);
/* set the process data watchdog to 100ms */
config_set_pd_watchdog_ms(mi, 100);
/* enable the adaptive timeout */
config_set_adaptive_timeout(mi, TRUE);
/* set the frame loss detection threshold */
config_set_filter_threshold(mi, 5);
SetNetwork(mi, adapter, "");
SetStateSequence(mi, EC_STATE_OPERATIONAL, 15000);
Scan version matching policy
The C SDK does not provide an option that controls how strictly the version number of a scanned slave must match the DENI configuration: master/config.h declares no config_* function for it, so it cannot be configured from C.
To check slave version consistency from the C SDK use VerifySlaveIdentity / VerifyAllSlaveIdentities: the check_rev parameter controls whether RevisionNo is checked, so you can compare identities explicitly before entering OP.
DC drift compensation
In the C SDK, DC drift compensation is configured through EnableDriftCompensation() (not a config_* function). Once enabled, the master periodically measures the deviation of the DC system time and writes a compensation value.
The C SDK has no GetDriftCompensation interface: after calling EnableDriftCompensation the caller caches the current on/off state itself.
void EnableDriftCompensation(uint16_t master_index, BOOL enable,
int32_t threshold_ns, int32_t gain);
Timeout configuration best practices
The many timeout fields involved in EtherCAT communication are independent of each other and directly affect both how sensitively network faults are detected and how long recovery takes. The table below sums up the common fields, their typical defaults and the recommended ranges. When you deploy, balance three dimensions: network length / interference level / how much you prioritise real-time behaviour.
Key fields at a glance:
| Category | Field | Unit | Read/write | Default | Recommended range | Effect |
|---|---|---|---|---|---|---|
| PDO cycle | loop_cycle | ns | Write-only | 1,000,000 (1ms) | 125,000 ~ 4,000,000 (125 µs ~ 4ms) | PDO cycle; sets the refresh rate and the CPU load |
| State timeout | timeout_init_to_preop | ms | Read/write | 3000 | 3000 ~ 10000 | INIT→PREOP wait time (slow slaves / EEPROM loading) |
| State timeout | timeout_preop_to_safeop | ms | Read/write | 10000 | 10000 ~ 30000 | PREOP→SAFEOP wait time (includes SM/FMMU/PDO mapping; increase it on large networks) |
| State timeout | timeout_safeop_to_op | ms | Read/write | 10000 | 10000 ~ 15000 | SAFEOP→OP wait time |
| Watchdog | pd_watchdog_ms | ms | Read/write | 0 (slave default ≈100) | loop_cycle × 10 ~ 100 | How long a slave waits before falling back to SafeOp after losing the master connection |
| Watchdog | pdi_watchdog_ms | ms | Read/write | 0 (slave default) | 0 ~ 200 | Detection window for the slave's local firmware stopping its ESC access |
When to increase or decrease
Increase for:
- Long cables / across cabinets / across a workshop — large physical transmission delay, so occasional RTT jitter needs headroom
- High EMI / welding / near high-power inverters — noise causes occasional frame loss, so allow more room for retries
- VLAN / TSN composite networks — switches add queuing jitter
- Large networks (>50 slaves) —
timeout_preop_to_safeopmust be increased, otherwise the SafeOp transition fails - Slow slaves (large FoE downloads / EEPROM writes) — both the mailbox and Init→PreOp need longer values
Decrease for:
- Fast fault detection first — emergency-stop scenarios; set the watchdog to 5×loop_cycle to detect frame loss within 50ms
- Short desktop cables / lab — RTT is very low, so the watchdog can go down to 20~50ms
- Tight real-time budgets (≤ 250 µs cycles) — the whole timetable is compact, so every timeout must be short
Four presets: default, lab, industrial, high EMI
/* (1) SDK default — suits standard short cables + desktop ~ ordinary workshop */
SetMasterLoopCycleTime(mi, 1000000); /* 1ms */
config_set_timeout_preop_to_safeop(mi, 10000); /* = ETG.1020 Table 55 default */
config_set_pd_watchdog_ms(mi, 0); /* slave default (~100ms) */
/* (2) Lab high speed — short cable + tight real-time budget */
SetMasterLoopCycleTime(mi, 250000); /* 250 µs */
config_set_timeout_preop_to_safeop(mi, 5000);
config_set_pd_watchdog_ms(mi, 20); /* very fast detection */
/* (3) Typical industrial — long cable + large network */
SetMasterLoopCycleTime(mi, 1000000);
config_set_timeout_preop_to_safeop(mi, 20000); /* relaxed for a large network */
config_set_pd_watchdog_ms(mi, 200);
/* (4) High EMI / welding site — tolerate occasional frame loss */
SetMasterLoopCycleTime(mi, 2000000); /* 2ms */
config_set_timeout_preop_to_safeop(mi, 30000);
config_set_pd_watchdog_ms(mi, 500);
config_set_adaptive_timeout(mi, TRUE); /* let adaptive timing absorb the jitter */
- Timeout too large — a real fault is only reported when the timeout expires, so application alarms / safety stops are delayed
- Timeout too small — occasional jitter is misread as a fault, firing frequent
PDOFrameLoss/StateChangenuisance alarms - Watchdog below a few multiples of
loop_cycle— it fires during normal operation and slaves keep falling back to SafeOp - After any change, run a 24h communication stress test before going live
With config_set_adaptive_timeout(mi, TRUE) the SDK computes the per-frame PDO timeout from the real RTT,
so you do not have to tighten loop_cycle by hand. The watchdog / state transition fields above still need per-scenario values.
Configuration load error descriptions
static inline int describe_load_config_error(int rc, char* buf, int buf_size);
Writes a negative failure code from LoadConfigJson / EcInit / automatic hot-plug rebuild accounting / the startup parameter snapshot and similar entry points as one readable line of reason (UTF-8 Chinese). It is an inline function in master/config.h, and the code table ships together with the header, so you can call it directly with no extra initialization and no additional runtime entry point.
| Category | Function | Return type | Read/write | Description |
|---|---|---|---|---|
| Error description | describe_load_config_error | int | read-only | Writes the failure code as one readable line of reason; returns the number of bytes written (the snprintf convention, excluding the NUL) |
Parameters:
rc(int) — failure code (negative)buf(char*) — output bufferbuf_size(int) — buffer size in bytes (the header recommends >= 64)
Return value:
int— number of bytes written (excluding the terminating NUL), with the same convention assnprintf; a return value >=buf_sizemeans the text was truncated and you need a larger buffer. Whenbufis null orbuf_size <= 0, returns 0 and writes no bytes.
This function does not return a const char*; it writes the static text from the code table into the caller's buffer. Prepare your own buffer if you need a string, and do not treat it as an interface that "returns a static string".
Result code groups
The code table is grouped by source (the sole authority for the numbers is the result code definition on the runtime side, and the table in the header is the same one):
| Code range | Group | Typical meaning |
|---|---|---|
| -1 / -2 / -3 / -5 / -7 | General parameters, queues, SDO, length | Invalid master index / invalid slave index / parameter queue full / SDO write failed / data exceeds the maximum length |
| -4 | Invalid content | The call arguments or configuration content are invalid (neither parseable DENI XML nor valid JSON) |
| -6 | State | Master not initialized / state not ready |
| -20 ~ -26 | Automatic hot-plug rebuild accounting | BUSY / RESCAN_0 / reconfiguration-phase SDO abort / target state not reached / state transition timeout / resources exhausted; -26 is a historical code, no longer returned by the current kernel and kept only to recognise old return values |
| -30 ~ -32 | Startup parameter snapshot / atomic replacement | Snapshot capacity insufficient / queue changed / master context rebuilt, replacement not executed |
| -40 ~ -50 | DENI / ENI configuration | XML parse failure / contract cross-validation failure / NIC bind failure / not enough slaves online / identity mismatch / mailbox SM write failure / DC deactivation not confirmed / watchdog declaration or write failure / DC apply failure / startup parameter queue rebuild failure / slave grouping apply failure |
| -51 | JSON structure validation | Unknown configuration key / invalid type or value / required key missing |
| -52 | NIC open | SetNetwork returned (uint16)-1: the NIC was not opened and no slave count was produced (not "not enough slaves"); check NIC binding / driver load / exclusive ownership / link, and the Network open failed log plus line state from the same cycle |
Do not guess the meaning of unknown codes: any negative value outside the table is written as 未识别的失败码 (原始值: N) keeping the raw number, so the original value reaches the field report.
Relationship to the configuration load return codes
LoadConfigJson() returns 0 on success and a negative value on failure; pass the negative value to describe_load_config_error() only on failure to get the reason. Do not guess the reason from the sign alone.
EcInit() returns uint16_t (the master index), not a failure code; only convert to text when you actually have a negative failure code, and do not pass an index value in as a failure code.
Example:
int rc = LoadConfigJson(master, json_text);
if (rc < 0) {
char msg[128];
int n = describe_load_config_error(rc, msg, sizeof msg);
if (n >= (int)sizeof msg) {
/* snprintf convention: the text was truncated, use a larger buffer and fetch again*/
char big[256];
describe_load_config_error(rc, big, sizeof big);
printf("配置加载失败 (%d): %s\n", rc, big); /* Configuration load failed (%d): %s */
} else {
printf("配置加载失败 (%d): %s\n", rc, msg); /* Configuration load failed (%d): %s */
}
}
/* Three common cases: invalid configuration content / JSON structure check failed / unknown code*/
char msg[128];
describe_load_config_error(-4, msg, sizeof msg);
printf("%s\n", msg); /* Invalid call parameters or configuration content ...*/
describe_load_config_error(-51, msg, sizeof msg);
printf("%s\n", msg); /* JSON configuration structure check failed: unknown configuration key / ...*/
describe_load_config_error(-999, msg, sizeof msg);
printf("%s\n", msg); /* Unrecognised failure code (raw value: -999)*/