DC synchronization (slave level)
Slave-level DC (distributed clock) properties and configuration.
For most scenarios use ConfigureDCAll() to configure all DC slaves in one call.
The slave-level methods are for cases where individual slaves need different parameters. Both resolve an unspecified phase with the same precedence order.
Read-only properties
| Category | Function | Return type | Read/write | Description |
|---|---|---|---|---|
| DC state | GetSlaveHasDC(mi, si) | BOOL | Read-only | Whether the ESC hardware supports DC |
| DC state | slave_has_esi_dc_sync(mi, si) | BOOL | Read-only | Whether the ESI declares DC synchronization for this slave (high-level wrapper in slave/dc.h) |
| DC state | slave_esi_dc_sync_mode(mi, si) | int | Read-only | DC synchronization tier declared by the ESI: 3 = DC-Sync0 + SYNC1; 2 = DC-Sync0 only; 0 = DC not declared / cannot be determined (verbatim raw value, no hardware fallback) |
| DC state | GetSlaveDCActive(mi, si) | uint16_t | Read-only | Mirror of the landed 0x0980 AssignActivate value. 0 = DC capable but not currently active (FreeRun); 0x0300 is only a common landed value, not the criterion for "armed" or "in sync" — whether the slave is armed is read from dc_sync0_armed() / C++ Sync0Armed; whether it is in sync is read from dc_get_sync_window_info() and applicable of in_sync |
| DC time | GetSlaveDCCycle0(mi, si) | int32_t | Read-only | Current SYNC0 cycle (nanoseconds) |
| DC time | GetSlaveDCCycle1(mi, si) | int32_t | Read-only | Current SYNC1 cycle (nanoseconds) |
| DC time | GetSlaveDCShift(mi, si) | int32_t | Read-only | Current phase shift (nanoseconds) |
| DC time | GetDcShiftTruth(mi, si, &shift, &source) | int32_t | Read-only | Landed phase shift plus its phase source tier (slave/dc.h). 1 = the output parameters are valid; <= DC_SHIFT_NO_CONCLUSION_MAX = no conclusion. Read-only, sends no frames, readable in OP |
| DC time | GetSlavePropagationDelay(mi, si) | int32_t | Read-only | Propagation delay of a frame from the master to this slave (nanoseconds) |
| DC topology | GetSlaveDCNext(mi, si) / GetSlaveDCPrevious(mi, si) | uint16_t | Read-only | Next / previous slave index in the DC chain |
| DC topology | GetSlaveDCParentPort(mi, si) | int32_t | Read-only | Compatibility entry for GetSlaveParentPort: 0..3 = parent port, -1 = unknown |
| DC receive time | GetSlaveDCReceiveTimeA/B/C/D(mi, si) | int32_t | Read-only | Receive time of each port (nanoseconds) |
GetSlaveHasDC reflects only the ESC hardware bit; it does not mean the application actually uses DC. Some slaves report DC capable in the ESC while the ESI declares no DC OpMode; in that case run FreeRun / SM-Sync, because forcing DC on makes the slave refuse to enter OP.
slave_has_esi_dc_sync() performs a real ESI DC OpMode query (the ESI is handed to the SDK during construction or configuration — esi_dll_load_file() / esi_dll_load_directory() — and is bound when SetStateSequence() establishes the link): it returns true when the ESI declares DC-Sync0/01, and false for FreeRun/SM-Sync or when the ESI has no <Dc> node; while no ESI is bound it falls back to the conservative hardware-bit check of GetSlaveHasDC.
Safe pattern before enabling DC (slave_has_esi_dc_sync is a slave/dc.h high-level wrapper; call it directly):
#include "slave/dc.h"
if (GetSlaveHasDC(master, 1) && slave_has_esi_dc_sync(master, 1)) {
SetSyncBySlaveIndex(master, 1, 1000000, 0, 0);
}
DC_FREE_RUN can be queried, but it is the slave's local clock: it does not mean DC is enabled, and it does not mean the slave is in sync. Whether the slave is armed is read from dc_sync0_armed() / C++ Sync0Armed; whether it is in sync is read from dc_get_sync_window_info() and applicable of in_sync. Neither GetSlaveDCActive() in 0x0300 nor a GetSlaveDCCycle0() greater than 0 can be used to infer that the slave is in sync. Under FreeRun, in_sync must not be read as in-sync.
DC synchronization types declared by the ESI
GetSlaveHasDC answers only "does the ESC hardware support DC"; slave_esi_dc_sync_mode() answers "which DC synchronization tier does the vendor require for this slave in the ESI". The tier decides whether SYNC1 may be enabled:
| Value | Meaning | Typical ESI |
|---|---|---|
3 | ESI declares DC-Sync0 + SYNC1: AssignActivate contains the SYNC1 enable bit 0x0400 (for example #x700) | Beckhoff EL7411 |
2 | ESI declares DC-Sync0 only: AssignActivate is non-zero but does not contain 0x0400 (for example #x300) | EL7041 / Ezi-SERVO2 |
0 | ESI does not declare DC, or it cannot be determined (ESI not bound / unreadable) | EK1100 / EK1110 / EL6022 / GCAN-8200 |
There is only one rule: DC-Sync01 may be requested only when the value is 3; with a value of 2 only DC-Sync0 is allowed. Treating 2 as 3 (forcing SYNC1 on) makes a slave that declares Sync0 only refuse to enter OP, and an AL status code is not necessarily reported.
ESI-declared value ≠ landed value: DarraEcat_EcEsi_GetDeviceDcAssignActivate() returns the raw 16-bit SYNC0 <Dc><OpMode><AssignActivate> declared in the ESI AssignActivate (returns 1 = declared and out is valid, 0 = not declared in the ESI, -2 = ESI not bound / bad argument). It is not the landed value written into the slave's 0x0980 — read GetSlaveDCActive() for that.
Division of labour with slave_has_esi_dc_sync(): the latter is the boolean capability query "can DC be enabled at all", and when the query fails (no ESI bound / bad parameter) it conservatively falls back to the GetSlaveHasDC hardware bit — better to over-check than to wrongly disable a slave that really can run DC. slave_esi_dc_sync_mode() is a verbatim raw reading: -1 / -2 always map to 0 (not declared / cannot be determined) with no hardware fallback at all. To tell "the ESI explicitly does not use DC" apart from "no ESI is bound at all", use the former; if only a boolean conclusion is needed, use the latter.
Prerequisite: the ESI is handed to the SDK during construction or configuration (esi_dll_load_file() / esi_dll_load_directory()), and is bound when SetStateSequence() establishes the link (or explicitly with esi_dll_apply_all_slaves()). While it is not bound, the reading only means "cannot be determined" and must not be taken as evidence that the slave does not support DC.
Example:
#include "slave/dc.h"
int mode = slave_esi_dc_sync_mode(master, 1);
if (GetSlaveHasDC(master, 1) && slave_has_esi_dc_sync(master, 1)) {
if (mode == 3) {
/* ESI declares DC-Sync0 + SYNC1 DC-Sync01 may be requested */
dc_configure_with_mode(master, 1, DC_SYNCHRON_01, 1000000, 1000000, DC_SHIFT_UNSPECIFIED);
} else {
/* DC-Sync0 only: do not enable SYNC1 */
dc_configure_with_mode(master, 1, DC_SYNCHRON, 1000000, 0, DC_SHIFT_UNSPECIFIED);
}
}
Configuration methods
SetSyncBySlaveIndex()
void SetSyncBySlaveIndex(uint16_t master_index, uint16_t slave_index,
uint32_t sync0_ns, uint32_t sync1_ns, int32_t shift_ns);
Configures the DC synchronization parameters of a single slave. All parameters are in nanoseconds. sync0_ns=0 disarms SYNC0 (back to FreeRun, not a 「0 ns cycle」); sync1_ns=0 means SYNC0 only; shift_ns is tri-state: DC_SHIFT_UNSPECIFIED = not specified (resolved by precedence), 0 = literal 0 phase, a negative value = explicit negative phase; the latter two are applied as given.
- Only when the phase is not specified (
DC_SHIFT_UNSPECIFIED) is it resolved by precedence: ESIShiftTimeSync0other than 0 → explicit usershift_ns→ default 「1 cycle + 70%」sync0_ns * 70 / 100(1 ms → 700 µs). - The phase is a phase shift only and adds no software propagation-delay compensation; the propagation delay is corrected in hardware by the ESC according to
0x0928. shift_ns = 0is a literal 0 phase, not "not specified", and does not fall back to 70%; passDC_SHIFT_UNSPECIFIEDif you want the default 70%.- For FreeRun / SM-Sync slaves the product writes
0x1C32:01/0x1C33:01back to 0 to clear what the previous session left behind (otherwise the move to SafeOp may report AL=0x002D); when SM2/SM3 are not mapped the write is deferred until mapping completes. - Hot-plug recovery re-arms and rewrites
0x09A0and0x0990;0x0990must follow a fresh read of0x0910(re-read the slave DC time first, then compute the start point, and write0x0980to activate right after), otherwise the start point goes stale and the first SYNC0 never arrives. The phase comes from the same source as the first arming (the same resolution result, phase only) and does not jump when the slave is re-armed; if the reference clock becomes invalid it is re-selected immediately.
Example:
/* SYNC0 = 1ms, no SYNC1, phase resolved by precedence */
SetSyncBySlaveIndex(master, 1, 1000000, 0, DC_SHIFT_UNSPECIFIED);
/* SYNC0 + SYNC1, phase 500 µs */
SetSyncBySlaveIndex(master, 1, 1000000, 2000000, 500000);
/* disable DC */
SetSyncBySlaveIndex(master, 1, 0, 0, DC_SHIFT_UNSPECIFIED);
ResolveDcSyncShift()
int32_t ResolveDcSyncShift(uint16_t master_index, uint16_t slave_index, uint32_t sync0_ns);
Single-slave automatic DC phase resolution: it outputs only the phase (the precedence between ESI ShiftTimeSync0 / the explicit user value / the default 70%); the propagation delay is corrected in hardware by the ESC according to 0x0928, and no software propagation compensation is included. When there is a phase conclusion it returns the final value, and the runtime writes it into that slave's DC shift at the same time (a subsequent GetSlaveDCShift() then reads exactly that value).
The return value has only two mutually exclusive forms:
- A legal phase =
DC_SHIFT_NO_CONCLUSION_MAXevery** ** greater thanint32_t.0and any negative value are legal:0= the phase lands exactly on a cycle boundary, a negative value = a lead offset (both the ESIShiftTimeSync0and an explicit offset support negative phases);-1,-700000and so on are all real phases, not failures. - No conclusion = occupies only the lowest 5 values of
int32_t, each named, and in that case the return value is not a phase:
| Constant | Value | Meaning |
|---|---|---|
DC_SHIFT_INPUT_UNSPECIFIED | INT32_MIN | A "not specified" sentinel for the input parameter only; appearing in the return-value position means the contract is broken |
DC_SHIFT_NO_CONCLUSION_NOT_INIT | INT32_MIN + 1 | Not initialized / context unavailable (a runtime that is not ready also falls in this class) |
DC_SHIFT_NO_CONCLUSION_BUS_GATE | INT32_MIN + 2 | Rejected by the bus configuration gate; the current bus state does not allow resolution |
DC_SHIFT_NO_CONCLUSION_BAD_SLAVE | INT32_MIN + 3 | Invalid slave index |
DC_SHIFT_NO_CONCLUSION_NO_PHASE | INT32_MIN + 4 | No phase can be resolved under this configuration (for example sync0_ns = 0, not armed) |
The only predicate is r <= DC_SHIFT_NO_CONCLUSION_MAX (DC_SHIFT_NO_CONCLUSION_MAX = INT32_MIN + 4, that is the inclusive upper bound). One comparison is enough; there is no need to enumerate the specific constants, and the predicate helpers ec_dc_shift_is_no_conclusion(r) / ec_dc_shift_is_value(r) can also be used directly.
- Unit is nanoseconds; the value may be negative.
- Resolves a single slave only and does not modify other slaves; to compute the whole bus in one call use
AutoCalculateDCShift(). - When there is no conclusion, that slave's DC shift is not written. To decide whether the runtime is loaded, query
DarraEcat_ShellStatus(); do not guess from the return value.
Example:
#include "slave/dc.h"
int32_t shift = ResolveDcSyncShift(master, 1, 1000000);
if (ec_dc_shift_is_no_conclusion(shift)) {
/* no conclusion: the return value is not a phase; do not use it as 0 and do not write it into the DC shift */
printf("无相位结论 (返回值 %d)\n", shift); /* No phase conclusion (return value %d) */
} else {
/* 0 and negative values are all legal phases; use them as they are */
printf("从站1 SYNC0=1000000 ns 的相位偏移: %d ns\n", shift); /* Phase offset of slave 1 at SYNC0=1000000 ns: %d ns */
SetSyncBySlaveIndex(master, 1, 1000000, 0, shift);
}
GetDcShiftTruth()
int32_t GetDcShiftTruth(uint16_t master_index, uint16_t slave_index,
int32_t* out_shift, int32_t* out_source);
Single-slave DC phase truth (read-only): reads the landed phase shift and the tier it came from. It sends no frames / writes no registers / does not go through the bus configuration gate — it reads the master context directly and is readable in OP as well; a status bar or diagnostics can use it to show honestly "what the phase is and which tier it came from". Difference from ResolveDcSyncShift(): this entry does not re-run the phase formula and does not change that slave's shift; it only reports the current state.
Parameters:
out_shift(int32_t*) — landed phase (ns); valid only when the return value is1;0and negative values are both legal phases.out_source(int32_t*) — phase source tier; valid only when the return value is1:
| Value | Constant | Meaning |
|---|---|---|
0 | EC_DC_SHIFT_SOURCE_USER | Explicit user value (including a literal 0 and negative values) |
1 | EC_DC_SHIFT_SOURCE_ESI | Explicitly declared by the ESI <ShiftTimeSync0> |
2 | EC_DC_SHIFT_SOURCE_DEFAULT70 | The product default 70% phase |
3 | EC_DC_SHIFT_SOURCE_UNKNOWN | None of the three tiers matches (a carried-over value / no evidence); never guessed from the number |
Return value:
1— both output parameters are filled, andout_shiftis then a valid phase.<= DC_SHIFT_NO_CONCLUSION_MAX— no conclusion, the output parameters are invalid; the predicate is the same as forResolveDcSyncShift()(ec_dc_shift_is_no_conclusion()). When the runtime is not ready it likewise returnsDC_SHIFT_NO_CONCLUSION_NOT_INIT.
Example:
#include "slave/dc.h"
int32_t shift = 0;
int32_t source = EC_DC_SHIFT_SOURCE_UNKNOWN;
if (GetDcShiftTruth(master, 1, &shift, &source) == 1) {
/* shift is legal whether it is 0 or negative */
printf("相位 %d ns, 来源档 %d\n", shift, source); /* Phase %d ns, source tier %d */
} else {
/* no conclusion: the output parameters are not a phase */
printf("相位真值不可用\n"); /* Phase true value unavailable */
}
SetDcSyncMode()
typedef enum {
DC_FREE_RUN = 0, /* free run: DC not used */
DC_SM_SYNCHRON = 1, /* SM event synchronization */
DC_SYNCHRON = 2, /* DC SYNC0 synchronization */
DC_SYNCHRON_01 = 3 /* DC SYNC0 + SYNC1 */
} dc_sync_mode_t;
BOOL SetDcSyncMode(uint16_t master_index, uint16_t slave_index, uint8_t sync_type);
uint8_t GetDcSyncMode(uint16_t master_index, uint16_t slave_index);
/* high-level wrapper (slave/dc.h) */
BOOL dc_configure_with_mode(uint16_t master_index, uint16_t slave_index,
dc_sync_mode_t mode,
uint32_t sync0_ns, uint32_t sync1_ns,
int32_t shift_ns);
SetDcSyncMode() sets or reads the slave SyncManager synchronization type directly. dc_configure_with_mode() is the high-level wrapper provided by slave/dc.h; it completes the slave DC configuration in one call according to the synchronization mode (SYNC0/SYNC1 signals plus the SyncManager synchronization type). DC synchronization modes follow ETG.1020 §22 / ESI AssignActivate in four tiers.
Return values (dc_configure_with_mode, semantics tightened):
TRUE— the DC configuration has been issued and the synchronization type has been confirmed written by the slaveFALSE— invalid parameter (unknown mode) / runtime not ready / slave does not support DC / the write of synchronization type0x1C32:01/0x1C33:01was not confirmed by the slave
Failures are reported honestly, never swallowed: when the synchronization type write is not confirmed, the call returns FALSE and also writes a diagnostics line to the SDK log with master / slave / expected tier / measured tier. Callers must not read FALSE as "configuration succeeded, the status just could not be read". To check the tier actually in effect, call GetDcSyncMode() again (0 means both FreeRun and unreadable).
Call dc_configure_with_mode() and the other slave/dc.h high-level wrappers directly (no handle, no function-pointer table); they require #include "slave/dc.h".
Example:
#include "slave/dc.h"
/* SYNC0 only, 1ms cycle, phase resolved by precedence */
dc_configure_with_mode(master, 1, DC_SYNCHRON, 1000000, 0, DC_SHIFT_UNSPECIFIED);
/* SYNC0 + SYNC1, shift 500 µs */
dc_configure_with_mode(master, 1, DC_SYNCHRON_01, 1000000, 2000000, 500000);
Disabling DC
/* set SetSyncBySlaveIndex to 0 through sync0_ns */
SetSyncBySlaveIndex(master, 1, 0, 0, DC_SHIFT_UNSPECIFIED);
Sync window diagnostics
GetSlaveSyncWindowStatus()
BOOL GetSlaveSyncWindowStatus(uint16_t master_index, uint16_t slave_index,
int* diff_ns, int* max_diff_ns, int* min_diff_ns,
BOOL* in_sync, uint32_t* out_of_sync_count);
Reads detailed status of the slave DC sync window. Returns FALSE when DC is not supported or the read fails. Output parameters: current/maximum/minimum time difference, whether the slave is inside the DC SYNC0 sync window, and the cumulative out-of-sync count. in_sync must not be read as in-sync under FreeRun; to decide that the slave is "genuinely in the window" require dc_get_sync_window_info() and applicable = TRUE from in_sync = TRUE. DCActive / DCCycle0 do not imply the slave is in sync.
The reference clock itself: by definition 0x092C (time difference) is N/A for it, and the SDK no longer synthesizes an in-sync value. When this slave is the reference clock and SYNC0 is armed,
in_syncisTRUE(same convention as C++IsInSync()/TryIsInSync()) — a reference clock cannot be out of step with itself, which is the only conclusion that can be determined (non-reference slaves still follow the sync-window criterion). The value only means "can be treated as in sync"; it does not mean a measured deviation exists, and it does not mean the whole network clock has converged; for the reference clockdc_get_sync_window_info()still honestly reportsapplicable=FALSE+EC_DC_WINDOW_NA_REFERENCE_CLOCK_ITSELF.
This function has only two outcomes, TRUE / FALSE, so it cannot distinguish "known to be outside the window" from "arming conclusion unknown". When three states are needed, use dc_sync0_armed() and dc_get_sync_window_info() from "DC diagnostics (per slave)" below.
If only in_sync or the current difference is needed, use interfaces such as GetSlaveLinkQuality / IsAllSlavesInSync; GetSlaveSyncWindowStatus() suits scenarios that need the full statistics.
ResetSlaveSyncWindowStats()
void ResetSlaveSyncWindowStats(uint16_t master_index, uint16_t slave_index);
int GetMaxSyncDifference(uint16_t master_index);
BOOL IsAllSlavesInSync(uint16_t master_index);
ResetSlaveSyncWindowStats() resets the sync-window statistics of this slave. GetMaxSyncDifference() / IsAllSlavesInSync() are global queries.
DC diagnostics (per slave, C / C++ low level)
Per-slave DC diagnostics answer four questions: can this slave do SYNC0, is it armed, is it in sync, and can each reading be trusted. All entry points read only the local cache; they do not read registers or send bus frames, so they can be called directly from the UI thread or a diagnostics thread.
Armed (dc_sync0_armed() / Sync0Armed) only means the slave has committed to generating SYNC0; whether the whole network clock has converged is read from applicable and in_sync of the sync window. The two must be read separately; one must never be inferred from the other.
Entry points
| Category | C entry | C++ low-level entry | Read/write | Description |
|---|---|---|---|---|
| Capability tier | dc_capability(mi, si) | SlaveDC::GetDcCapability(dll, mi, si) | Read-only | ESC capability bits plus the tier declared by the ESI. EC_DC_CAPABILITY_UNKNOWN means it cannot be determined, not "no capability" |
| Arm final outcome | ec_dc_slave_snapshot_t.arm_outcome / arm_outcome_available | SlaveDC::TryGetDcArmOutcome(dll, mi, si) | Read-only | In C it is always EC_DC_ARM_RESULT_UNAVAILABLE + FALSE; in C++ it is always std::nullopt. See below for the reason |
| 0x0980 landed value | dc_assign_activate(mi, si, &out) | SlaveDC::GetDcAssignActivate(...) | Read-only | Returns FALSE = no DC capability / unreadable, and does not write out; when TRUE, 0 = DC capable but not active |
| SYNC0 cycle | dc_sync0_cycle_ns(mi, si, &out) | SlaveDC::GetDcSync0CycleNs(...) | Read-only | Mirror of the landed 0x09A0 value; 0 = the cycle has not landed, not a "0 ns cycle" |
| SYNC1 cycle | dc_sync1_cycle_ns(mi, si, &out) | SlaveDC::GetDcSync1CycleNs(...) | Read-only | Mirror of the landed 0x09A4 value, semantics as above |
| Phase shift | dc_shift_ns(mi, si, &out) | Snapshot field DcSlaveSnapshot::ShiftNs | Read-only | Landed value (ns), may be negative; the C++ low level has no per-slave phase-shift entry, read the snapshot |
| Propagation delay | dc_propagation_delay_ns(mi, si, &out) | SlaveDC::GetDcPropagationDelayNs(...) | Read-only | Landed 0x0928 value; a negative underlying value is treated as a read failure (returns FALSE) |
| Propagation delay origin | dc_propagation_delay_origin(mi, si) | SlaveDC::GetDcPropagationDelaySource(...) | Read-only | EC_DC_PDELAY_ORIGIN_ZERO_NS_AMBIGUOUS = may be the domain root or may not have been measured yet; nothing is invented |
| Sync window | dc_get_sync_window_info(mi, si, &out) / dc_build_sync_window_info(...) | SlaveDC::GetDcSyncWindow(dll, mi, si) | Read-only | Per-slave property entry; when assembling in bulk, call dc_build_sync_window_info first to reuse the already-read reference clock slave index and threshold |
| SYNC0 arming | dc_sync0_armed(mi, si, &armed) | SlaveDC::Sync0Armed(...) | Read-only | Tri-state return code, see below |
| Convergence time | dc_get_convergence_ms(mi, si, &out) | MasterDiagnosticsInfo::DcConvergenceMs(si) | Read-only | Comes from the most recent completed 2-second sample; unavailable unless a complete transition was observed |
| Steady-state jitter | dc_get_jitter(mi, si, &out) | MasterDiagnosticsInfo::DcJitter(si) | Read-only | The whole reading is unavailable with fewer than 2 samples; a single point is never passed off as stable |
| Reference clock facts | dc_reference_clock_info(mi, &out) | SlaveDC::GetDcReferenceClock(dll, mi) | Read-only | Slave index + tier + reason text; when no DC slave exists, an explicit instance (slave index 0) is returned rather than fabricated facts |
The return code of dc_sync0_armed() is tri-state; callers must branch on it:
| Category | Return value | Meaning | Handling of *armed | Read/write |
|---|---|---|---|---|
| DC diagnostics | 0 | Conclusion valid | *armed is written: TRUE = committed to generate SYNC0, FALSE = not armed, with evidence | Read-only |
| DC diagnostics | non-0 | Cannot be determined (bad parameter / context not ready / entry unavailable) | *armed is not written; the caller keeps the previous value or treats it as "unknown"; collapsing it to "not armed" is forbidden | Read-only |
C++ Sync0Armed() returns std::optional<bool>: std::nullopt means "cannot be determined", equivalent to a non-0 return above.
Sync window structure ec_dc_sync_window_info_t
| Category | Field | Read/write | Description |
|---|---|---|---|
| DC diagnostics | applicable | Read-only | TRUE = this slave participates in SYNC0 and a real measurement was read; when FALSE, all has_xxx flags of the numeric fields are FALSE |
| DC diagnostics | na_reason | Read-only | Reason when applicable = FALSE; EC_DC_WINDOW_NA_NONE when applicable |
| DC diagnostics | has_diff_ns / diff_ns | Read-only | Current synchronization error (ns) |
| DC diagnostics | has_max_diff_ns / max_diff_ns | Read-only | Maximum error within the observation window (ns) |
| DC diagnostics | has_min_diff_ns / min_diff_ns | Read-only | Minimum error within the observation window (ns) |
| DC diagnostics | has_out_of_sync_count / out_of_sync_count | Read-only | Cumulative number of times the sync window was exceeded |
| DC diagnostics | has_in_sync / in_sync | Read-only | Whether this sample is inside the window (armed and measured inside) |
| DC diagnostics | has_threshold_ns / threshold_ns | Read-only | Sync window threshold (ns) |
| DC diagnostics | has_reading_unchanged / reading_unchanged | Read-only | Whether the four 0x092C readings have stayed completely unchanged over several consecutive samples (frozen proxy flag); has = FALSE = not enough samples to conclude |
| DC diagnostics | unchanged_streak | Read-only | Number of consecutive samples with identical readings (same counter as reading_unchanged) |
| DC diagnostics | has_sampled_at_utc / sampled_at_utc_ms | Read-only | Sample timestamp of this reading (UTC milliseconds) |
reading_unchanged = FALSE is not the same as "confirmed to be advancing"; it only means the freeze-decision sample count has not been reached. It is a direct observation of "the reading was not updated", not the freeze criterion for the reference clock's 1:1 ramp.
Seven states
The seven states describe only "determinable sync window states". The C side has no single seven-state enum; the state is expressed as a combination of applicable + na_reason + in_sync / reading_unchanged:
| Category | State | Predicate | Meaning | C expression | C++ DcSyncWindowState | Read/write |
|---|---|---|---|---|---|---|
| DC diagnostics | No capability | No DC capability | There is no SYNC0 cycle unit, so a synchronization error does not exist | applicable=FALSE + EC_DC_WINDOW_NA_NO_DC_CAPABILITY | NoDcCapability | Read-only |
| DC diagnostics | Not armed | Known not armed | Not participating in DC synchronization, 0x092C is undefined | applicable=FALSE + EC_DC_WINDOW_NA_SYNC0_NOT_ARMED | Sync0NotArmed | Read-only |
| DC diagnostics | Reference clock itself | This slave is the reference clock | A synchronization error does not exist by definition | applicable=FALSE + EC_DC_WINDOW_NA_REFERENCE_CLOCK_ITSELF | ReferenceClockItself | Read-only |
| DC diagnostics | Reading frozen | Applicable and the readings are continuously unchanged | All four readings completely unchanged over several samples (frozen proxy flag) | applicable=TRUE + has_reading_unchanged=TRUE + reading_unchanged=TRUE | ReadingFrozen | Read-only |
| DC diagnostics | Genuinely in window | Applicable and measured inside the window | Armed and measured inside the sync window | applicable=TRUE + has_in_sync=TRUE + in_sync=TRUE | InWindow | Read-only |
| DC diagnostics | Arming unknown | Arming conclusion unknown | The query cannot answer; participating / not participating cannot be asserted | applicable=FALSE + EC_DC_WINDOW_NA_ARMED_UNKNOWN | ArmedUnknown | Read-only |
| DC diagnostics | Never sampled | Applicable but no valid sample | All four values are 0 and in_sync=FALSE; 0 is not "perfect synchronization" | applicable=FALSE + EC_DC_WINDOW_NA_NOT_SAMPLED | NotSampled | Read-only |
The read-failure family is not one of these seven states; the C side also goes through na_reason, and C++ State() returns std::nullopt (the reason stays readable):
| Category | Reason | Meaning | Read/write |
|---|---|---|---|
| DC diagnostics | EC_DC_WINDOW_NA_SLAVE_READ_FAILED | The slave snapshot cannot be read, so even the capability cannot be determined | Read-only |
| DC diagnostics | EC_DC_WINDOW_NA_REFERENCE_CLOCK_UNKNOWN | The reference clock slave index cannot be read, so it cannot be decided whether this slave is the time base | Read-only |
| DC diagnostics | EC_DC_WINDOW_NA_WINDOW_READ_FAILED | Armed and not the reference clock, but reading the measured window failed (read failure / context generation changed) | Read-only |
Armed but outside the window (applicable = TRUE, in_sync = FALSE, not frozen) is none of the seven states either. C++ State() returns std::nullopt; the caller must read applicable and in_sync and take the real conclusion "outside the window", never "not armed" or "unknown".
The evaluation order is fixed: slave snapshot unreadable → no capability → reference clock slave index unreadable → this slave is the reference clock → arming unknown → known not armed → window read failed → never sampled → measured.
Three honest tri-states
| Category | Conclusion | When there is no conclusion | C | C++ | Read/write |
|---|---|---|---|---|---|
| DC diagnostics | Whether all are in the window | No confirmed participant → unknown, not TRUE | all_in_sync_known = FALSE | AllInSync = std::nullopt | Read-only |
| DC diagnostics | Maximum synchronization difference | No usable window at all → unknown, not 0 | has_max_drift_ns = FALSE | MaxDriftNs = std::nullopt | Read-only |
| DC diagnostics | SYNC0 arming | The query cannot answer → unknown, not FALSE | sync0_armed_known = FALSE | Sync0Armed = std::nullopt | Read-only |
"Not applicable" is never written as 0. The sync window of the reference clock itself is always N/A; not armed / no DC / never sampled likewise never produce 0 ns.
Arm final outcome: unavailable at this layer
The bookkeeping source of DcArmOutcome is maintained by the SDK's automatic start policy; the C / C++ low level has no equivalent source:
| Category | Language | Expression | Description | Read/write |
|---|---|---|---|---|
| DC diagnostics | C | arm_outcome = EC_DC_ARM_RESULT_UNAVAILABLE, arm_outcome_available = FALSE | Dedicated "unavailable" value, not EC_DC_ARM_RESULT_UNKNOWN | Read-only |
| DC diagnostics | C++ | TryGetDcArmOutcome() is always std::nullopt | Does not fabricate DcArmResult::Unknown; the reason is given by DcArmOutcomeUnavailableReason() | Read-only |
The semantics of UNKNOWN are "bookkeeping exists, but this sample has no final-outcome record for that slave"; this layer is "no such bookkeeping at all". The two must not be mixed, and UNKNOWN must not be called "not yet armed" or "not participating". For a real final outcome, use the C# SDK.
Reference clock and time base
- Reference clock: in chain order, the master selects the first slave on the link that has active DC (real SYNC0); if no slave is armed, it falls back to the first DC-capable slave in the chain. The whole bus has exactly this one time base.
- Single start point: the reference domain has exactly one start instant (the same physical instant); after converting it into each slave's time domain, the master writes it to
0x0990. Start points are not measured per slave. - Reference clock handover (slave drop / hot-plug / capability change): every
0x0920written in the old clock's time domain becomes invalid. In chain order, the master re-reads0x0920for each DC slave that is not in OP, not dropped and not the reference clock itself, proves it by reading back, then rewrites that slave's0x0990in the new time domain; slaves in OP are not interrupted in their SYNC0 and have their error trimmed by online correction. - Phase only:
0x0928is corrected in hardware by the ESC when generating SYNC0;shift_nsis a phase shift only and contains no propagation-delay compensation. - Diagnostics: the SDK does not currently expose read-only properties for
0x0990/0x0920; for register-level evidence see the DC synchronization diagnostics lines inevents.log.
Full example
#include "ethercat.h"
#include <stdio.h>
int main(void) {
uint16_t master = Initialize();
SetNetwork(master, "\\Device\\NPF_{GUID}", "");
SetStateSequence(master, EC_STATE_OPERATIONAL, 10000);
Start(master);
if (GetSlaveHasDC(master, 1)) {
/* configure slave 1: SYNC0 = 1ms */
SetSyncBySlaveIndex(master, 1, 1000000, 0, 0);
printf("DC 激活: %d\n", GetSlaveDCActive(master, 1)); /* DC active: %d */
printf("SYNC0 周期: %d ns\n", GetSlaveDCCycle0(master, 1)); /* SYNC0 cycle: %d ns */
printf("相位偏移: %d ns\n", GetSlaveDCShift(master, 1)); /* Phase offset: %d ns */
printf("传播延迟: %d ns\n", GetSlavePropagationDelay(master, 1)); /* Propagation delay: %d ns */
/* sync window diagnostics */
int diff, max_d, min_d;
BOOL sync;
uint32_t oos;
if (GetSlaveSyncWindowStatus(master, 1, &diff, &max_d, &min_d, &sync, &oos)) {
printf("同步差: %d ns, 同步=%s, 失步=%u\n", /* Sync difference: %d ns, in sync=%s, out-of-sync=%u */
diff, sync ? "是" : "否", oos);
}
if (IsAllSlavesInSync(master))
printf("所有从站已同步\n"); /* All slaves are synchronized */
/* disable DC */
SetSyncBySlaveIndex(master, 1, 0, 0, 0);
}
Stop(master);
Dispose(master);
return 0;
}