Skip to main content

DC synchronization

Slave-level Distributed Clocks (DC) configuration. Accessed through the DC-related methods of the Slave class.

Prefer the master-level method

In most scenarios use the master-level master.ConfigureDC() to configure all DC slaves in one call. The slave-level methods suit cases where individual slaves need different parameters.

DC capability detection​

Before enabling DC, confirm that the slave both supports DC in hardware and declares DC synchronization in the ESI. Only when both hold is it safe to call ConfigureDC().

HasDC()​

bool HasDC() const;

Whether the ESC hardware supports DC (reads ESC register 0x0008). It reflects hardware capability only and does not mean the application layer uses DC. Some slaves report DC capable in the ESC but do not declare a DC OpMode in the ESI; forcing DC on makes the slave refuse to enter OP (a typical case: GCAN-8200).

HasEsiDcSync()​

bool SlaveDC::HasEsiDcSync(dll_t& dll, uint16_t masterIndex, uint16_t slaveIndex);

Whether the ESI declares that this slave uses DC synchronization. The sync mode is decided from the ESI binding information: only DC-Sync0 / DC-Sync01 (that is, a non-zero AssignActivate) counts as declared DC synchronization; when the ESI does not declare it, the call returns false. If the caller has not yet bound an ESI through EsiManager::BindToSlave(), it degrades conservatively to HasDC(), so DC is not switched off by mistake.

There is also a strict overload that decides from a specified ESI XML file path; any <Dc> / OpMode with AssignActivate != 0 returns true (parsing is done inside the SDK):

bool SlaveDC::HasEsiDcSync(dll_t& dll, uint16_t masterIndex, uint16_t slaveIndex,
const std::string& esiFilePath);

Device location rules (by the real identity on this bus, not the first device in the file):

  • identity readable (SII VendorId / ProductCode / RevisionNo) and exactly one Device found → use that Device's declaration;
  • identity readable but no matching Device / several candidates that cannot be determined uniquely / vendor section mismatch → log a Warning and degrade to HasDC() (do not borrow another device's conclusion, and do not switch DC off by mistake);
  • identity not readable and the file has exactly one Device → use that Device;
  • <Dc> missing / no OpMode / every AssignActivate is 0 → explicitly return false.

Example (the safe way to write it before enabling DC):

auto& s = master.GetSlave(1);
if (s.HasDC() && SlaveDC::HasEsiDcSync(s.Dll(), master.MasterNumber(), 1)) {
s.ConfigureDC(1'000'000);
} else {
// Go with FreeRun / SM-Sync instead of forcing DC on
}
HasDC vs HasEsiDcSync
  • HasDC() — ESC register 0x0008 bit, hardware capability
  • HasEsiDcSync() — at least one ESI <Dc> / OpMode with AssignActivate != 0, an application-layer declaration

Trusting only HasDC() makes slaves such as GCAN-8200 — "hardware capable / ESI does not declare" — refuse to enter OP after DC is enabled. Both must be true to be safe.

EsiDcSyncMode()​

int SlaveDC::EsiDcSyncMode(dll_t& dll, uint16_t masterIndex, uint16_t slaveIndex);

The DC synchronization tier the ESI declares for this slave, so that the layer above can decide "whether SYNC1 can be enabled":

ValueMeaningTypical ESI
3ESI declares DC-Sync0 + SYNC1: AssignActivate contains the SYNC1 enable bit 0x0400 (for example #x700)Beckhoff EL7411
2ESI declares DC-Sync0 only: AssignActivate is non-zero but does not contain 0x0400 (for example #x300)EL7041 / Ezi-SERVO2
0ESI does not declare DC, or it cannot be determined (ESI not bound / unreadable)EK1100 / EK1110 / EL6022 / GCAN-8200

There is only one rule: only when the value is 3 may DC-Sync01 be requested; when the value is 2, only DC-Sync0. Using 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.

ESI-declared value ≠ landed value: EcEsiGetDeviceDcAssignActivate() returns the three-state EsiDeclareU16 (Declared / NotDeclared / Unreadable) carrying the raw 16-bit SYNC0 AssignActivate declared in the ESI <Dc><OpMode><AssignActivate>. It is not the landed value written into the slave's 0x0980 — read SlaveDC::GetDcAssignActivate() for that.

Relationship with HasEsiDcSync(): at >= 2, HasEsiDcSync() agrees with EsiDcSyncMode() >= 2, but when the runtime returns -2 (ESI not bound) it keeps the conservative branch that degrades to HasDC(); EsiDcSyncMode() instead folds -1 / -2 / 0 / 1 all into 0 (not declared / cannot be determined). If you want a boolean for "can DC be enabled", use HasEsiDcSync(); to decide "can SYNC1 be enabled" you must look at EsiDcSyncMode().

Precondition: the ESI is bound to the slave (EsiManager::BindToSlave()). When it is not bound, the reading only means "cannot be determined", and it must not be taken as proof that the slave does not support DC.

Example:

using namespace darra;

auto& s = master.GetSlave(1);
uint16_t mi = master.MasterNumber();

int mode = SlaveDC::EsiDcSyncMode(s.Dll(), mi, 1);

if (s.HasDC() && SlaveDC::HasEsiDcSync(s.Dll(), mi, 1)) {
if (mode == 3) {
// ESI declares DC-Sync0 + SYNC1: DC-Sync01 can be requested
SlaveDC::ConfigureDC(s.Dll(), mi, 1, DcSyncMode::DcSynchron01, 1'000'000, 1'000'000);
} else {
// Declares DC-Sync0 only: do not enable SYNC1
SlaveDC::ConfigureDC(s.Dll(), mi, 1, DcSyncMode::DcSynchron, 1'000'000);
}
}

DcSyncMode enum​

enum class DcSyncMode : int {
FreeRun = 0, // Free run (local clock, not DC synchronisation)
SmSynchron = 1, // SyncManager event synchronisation (SM-Sync)
DcSynchron = 2, // DC synchronisation (SYNC0 only)
DcSynchron01 = 3 // DC synchronisation (SYNC0 + SYNC1)
};
FreeRun is not DC synchronization

DcSyncMode::FreeRun can be queried, but it is the slave's local clock, not DC enabled and not synchronized. DC synchronization = SYNC0 armed and the synchronization window InSync true. 0x0980 (DCActive) is only the landed mirror; the common value 0x0300 does not mean synchronized. InSync is always false under FreeRun.

CurrentDcSyncMode()​

DcSyncMode CurrentDcSyncMode() const;

Get the slave's current synchronization mode. FreeRun / SmSynchron can be queried but are not DC synchronization. DC synchronization is only DcSynchron / DcSynchron01 and requires 0x1C32/0x1C33 = 2; whether it is really armed is seen from SlaveDC::Sync0Armed, and whether it has converged from the synchronization window InSync (which requires Applicable == true). The 0x0300 of 0x0980 is only the common landed value, not a synchronization criterion.

Example:

auto mode = slave.CurrentDcSyncMode();
if (mode == DcSyncMode::DcSynchron) {
printf("从站使用 SYNC0 同步\n"); // Slave is synchronizing with SYNC0\n
}

DC parameter settings​

ConfigureDC()​

bool ConfigureDC(uint32_t sync0CycleNs, uint32_t sync1CycleNs = 0,
int32_t shiftNs = kDcShiftUnspecified) const;

Set the slave DC synchronization parameters. All parameter units: nanoseconds (ns).

Parameters:

  • sync0CycleNs — SYNC0 cycle (nanoseconds); 0 means disarm SYNC0 (back to FreeRun)
  • sync1CycleNs — SYNC1 delta time (nanoseconds); 0 means SYNC0 only
  • shiftNs — phase shift (nanoseconds). kDcShiftUnspecified (INT32_MIN) is the only sentinel for "unspecified", and only it is resolved by priority; 0 and negative values are explicit user phase and are sent as given (0 is literally phase 0 and does not fall back to 70%)
Phase default and FreeRun
  • Only when the phase is "unspecified" (kDcShiftUnspecified) is it resolved by priority: ESI ShiftTimeSync0 (a value other than 0) → the user's explicit shiftNs → the default 1 × cycle + 70% sync0CycleNs * 70 / 100 (1 ms → 700 µs).
  • The phase is only a phase displacement and does not add software propagation delay compensation; the propagation delay is corrected by the ESC in hardware per 0x0928.
  • shiftNs = 0 is literally phase 0, not "unspecified", and does not fall back to 70%; for the default 70% use the default argument (do not pass the parameter).
  • For FreeRun / SM-Sync slaves the product writes 0x1C32:01 / 0x1C33:01 back to 0, clearing what the previous session left behind (otherwise the step up to SafeOp may report AL=0x002D); when SM2/SM3 are not mapped, the write is deferred until mapping completes.
  • Hot-plug recovery re-arming rewrites 0x09A0 and 0x0990; 0x0990 must come after re-reading 0x0910 (re-read the slave DC time first, then compute the start point, and activate 0x0980 right after writing), otherwise the start point is stale and the first SYNC0 beat never arrives. The phase comes from the same source as the first arming (the same resolution result, pure phase) and does not jump with re-arming; when the reference clock fails it is reselected immediately.

Example:

auto& slave = master.GetSlave(1);

// SYNC0 = 1ms
slave.ConfigureDC(1'000'000);

// SYNC0 = 1ms, SYNC1 = 2ms
slave.ConfigureDC(1'000'000, 2'000'000);

// SYNC0 = 1 ms, phase offset 200 µs
slave.ConfigureDC(1'000'000, 0, 200'000);

ConfigureDC(DcSyncMode)​

// Slave member overloads (same-named overloads as the cyclic value forms above)
bool ConfigureDC(DcSyncMode mode, uint32_t sync0CycleNs = 0,
uint32_t sync1CycleNs = 0,
int32_t shiftNs = kDcShiftUnspecified) const;

// Equivalent free function in the darra::SlaveDC namespace
bool SlaveDC::ConfigureDC(dll_t& dll, uint16_t mi, uint16_t si,
DcSyncMode mode,
uint32_t sync0CycleNs = 0,
uint32_t sync1CycleNs = 0,
int32_t shiftNs = kDcShiftUnspecified);

Configure the slave DC by synchronization mode (ETG.1020). The SDK writes the corresponding SM sync type register / SYNC0 / SYNC1 automatically, saving you from computing the AssignActivate bitmask by hand.

Member overload and free function are equivalent

Besides the "cycle numbers" form, the Slave class has a member overload that takes DcSyncMode, which calls SlaveDC::ConfigureDC() internally. The free function form takes dll_t& / master index / slave index explicitly, and suits call sites that do not go through a Slave object.

Parameters:

  • dll (dll_t&) — DLL reference (obtainable from slave.Dll())
  • mi (uint16_t) — master index (master.MasterNumber())
  • si (uint16_t) — slave index (1-based)
  • mode (DcSyncMode) — synchronization mode
  • sync0CycleNs / sync1CycleNs — valid only in DcSynchron / DcSynchron01 mode
  • shiftNs — valid only in DC mode; kDcShiftUnspecified = unspecified (resolved by priority), 0 and negative values = explicit user phase, applied as given

Example:

using namespace darra;
auto& s = master.GetSlave(1);
uint16_t mi = master.MasterNumber();

// DC SYNC0 = 1 ms (conventional servo)
SlaveDC::ConfigureDC(s.Dll(), mi, 1, DcSyncMode::DcSynchron, 1'000'000);

// SM event synchronisation (the default for most IO modules)
SlaveDC::ConfigureDC(s.Dll(), mi, 1, DcSyncMode::SmSynchron);

// Free run (no DC synchronisation)
SlaveDC::ConfigureDC(s.Dll(), mi, 1, DcSyncMode::FreeRun);

DisableDC()​

void DisableDC() const;

Disables DC on the slave.

ResolveDcSyncShift()​

namespace darra::SlaveDC {
inline int32_t ResolveDcSyncShift(dll_t& dll, uint16_t mi, uint16_t si,
uint32_t sync0CycleNs);
}

Single-slave automatic DC phase resolution. It outputs the phase only (the whole priority decision between ESI ShiftTimeSync0 / the explicit user value / the default 70% is done by the runtime), and the propagation delay is corrected by the ESC in hardware per 0x0928, with no software propagation compensation. Callers must not compute the phase formula themselves. When there is a phase conclusion the runtime also writes the return value into that slave's DC shift; when there is no conclusion it does not write.

Parameters:

  • dll (dll_t&) — DLL reference (obtainable from slave.Dll())
  • mi (uint16_t) — master index (master.MasterNumber())
  • si (uint16_t) — slave index (1-based)
  • sync0CycleNs (uint32_t) — SYNC0 cycle in nanoseconds; 0 means not armed / FreeRun, and under that configuration there is no phase conclusion (it returns kDcShiftNoConclusionNoPhase, not "phase 0")

The return value has only two mutually exclusive forms:

  • A legal phase = every int32_t greater than kDcShiftNoConclusionMax. 0 and any negative value are legal: 0 = the phase lands exactly on a cycle boundary, a negative value = a lead offset (both the ESI ShiftTimeSync0 and an explicit offset support negative phases); -1, -700000 and 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:
ConstantValueMeaning
kDcShiftUnspecifiedINT32_MINA "not specified" sentinel for the input parameter only; appearing in the return-value position means the contract is broken
SlaveDC::kDcShiftNoConclusionNotInitINT32_MIN + 1Not initialized / context unavailable (a runtime that is not ready also falls in this class)
SlaveDC::kDcShiftNoConclusionBusGateINT32_MIN + 2Rejected by the bus configuration gate; the current bus state does not allow resolution
SlaveDC::kDcShiftNoConclusionBadSlaveINT32_MIN + 3Invalid slave index
SlaveDC::kDcShiftNoConclusionNoPhaseINT32_MIN + 4No phase can be resolved under this configuration (for example sync0CycleNs = 0, not armed)

The only predicate is r <= SlaveDC::kDcShiftNoConclusionMax (= INT32_MIN + 4, that is the inclusive upper bound). Judge with SlaveDC::DcShiftResultIsNoConclusion(r); do not enumerate the specific constants, and do not treat negative values as failures.

Difference from AutoCalculateDCShift: this entry point resolves a single slave only and does not touch other slaves' shifts; for batch calibration use AutoCalculateDCShift.

Example:

using namespace darra;

auto& s = master.GetSlave(1);
int32_t shift = SlaveDC::ResolveDcSyncShift(
s.Dll(), master.MasterNumber(), 1, /*sync0CycleNs=*/1'000'000);

if (SlaveDC::DcShiftResultIsNoConclusion(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)\n
} else {
// 0 and negative values are all legal phases; use them as they are
printf("DC 相位偏移 = %d ns\n", shift); // DC phase offset = %d ns\n
}

GetDcShiftTruth()​

namespace darra::SlaveDC {
inline int32_t GetDcShiftTruth(dll_t& dll, uint16_t mi, uint16_t si,
int32_t* out_shift, int32_t* out_source);

// C++ idiomatic form: returns DcShiftTruth; when available == false, shift_ns / source are not values
inline DcShiftTruth GetDcShiftTruth(dll_t& dll, uint16_t mi, uint16_t si);
}

Single-slave DC phase truth (read-only): reads the landed dc.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 resolve the phase formula and does not change dc.shift; it only reports the current state.

Parameters:

  • out_shift (int32_t*) — landed phase (ns); valid only when the return value is 1; 0 and negative values are both legal phases.
  • out_source (int32_t*) — phase source tier, values in the table below; valid only when the return value is 1:
ValueDcShiftSourceMeaning
0UserExplicit user value (including a literal 0 and negative values)
1EsiExplicitly declared by the ESI <ShiftTimeSync0>
2Default70The product default 70% phase
3UnknownNone of the three tiers matches (a carried-over value / no evidence); never guessed from the number

Return value:

  • 1 — both output parameters are filled, and out_shift is then a valid phase.
  • <= SlaveDC::kDcShiftNoConclusionMax — no conclusion, the output parameters are invalid; judge with SlaveDC::DcShiftResultIsNoConclusion(). When the runtime is not ready it likewise returns kDcShiftNoConclusionNotInit.

The DcShiftTruth struct overload wraps the same conclusion in C++ form: when available == false, neither shift_ns nor source is a value; do not treat shift_ns == 0 as "phase 0".

Example:

using namespace darra;

auto& s = master.GetSlave(1);
uint16_t mi = master.MasterNumber();

// Output-parameter form: only a return of 1 means a valid phase
int32_t shift = 0;
int32_t source = static_cast<int32_t>(SlaveDC::DcShiftSource::Unknown);
if (SlaveDC::GetDcShiftTruth(s.Dll(), mi, 1, &shift, &source) == 1) {
printf("相位 %d ns, 来源档 %d\n", shift, source); // Phase %d ns, source tier %d\n
}

// C++ idiomatic form: do not read shift_ns when available == false
SlaveDC::DcShiftTruth truth = SlaveDC::GetDcShiftTruth(s.Dll(), mi, 1);
if (truth.available) {
printf("相位 %d ns\n", truth.shift_ns); // Phase %d ns\n
}

Read-only properties​

auto& slave = master.GetSlave(1);

// Propagation delay (nanoseconds)
int delay = slave.PropagationDelay();
printf("传播延迟: %d ns\n", delay); // Propagation delay: %d ns\n

// DC-related register values
uint16_t dcActive = slave.DCActive();
int dcCycle0 = slave.DCCycle0();
int dcCycle1 = slave.DCCycle1();
int dcShift = slave.DCShift();

Synchronization window diagnostics​

GetSyncWindowStatus()​

std::optional<SyncWindowStatus> GetSyncWindowStatus() const;

Get the detailed status of the slave DC synchronization window. Returns std::nullopt when DC is not supported or the read fails.

Related structure:

struct SyncWindowStatus {
int DiffNs; // Time difference to the reference clock (nanoseconds)
int MaxDiffNs; // Maximum time difference (nanoseconds)
int MinDiffNs; // Minimum time difference (nanoseconds)
bool InSync; // Whether inside the DC SYNC0 synchronisation window. Always false in FreeRun and must not be treated as synchronised
uint32_t OutOfSyncCount; // Number of times outside the sync window
};

Example:

auto status = slave.GetSyncWindowStatus();
if (status) {
printf("同步差=%dns, 最大=%dns, 同步=%s\n", // sync diff=%dns, max=%dns, synced=%s\n
status->DiffNs, status->MaxDiffNs,
status->InSync ? "是" : "否");
printf("超出同步次数: %u\n", status->OutOfSyncCount); // Out-of-sync count: %u\n
}

ResetSyncWindowStats()​

Reset the synchronization window statistics; the Slave member and the SlaveDC free function are two equivalent entry points:

slave.ResetSyncWindowStats();

darra::SlaveDC::ResetSyncWindowStats(slave.Dll(), master.MasterNumber(), 1);

DC diagnostics (per slave)​

The diagnostic surface reads only local caches (slave state / synchronization state) and sends no bus frames, so it can be read directly from the interface thread or a diagnostic thread. Every "not applicable / unreadable / cannot be determined" case is expressed with std::nullopt or a reason enum, and is never faked with 0.

Diagnostic methods​

CategoryMethodReturnRead/writeDescription
DC diagnosticsSlaveDC::GetDcCapability(dll, mi, si)DcCapabilityread-onlyESC capability bits + the tier declared by the ESI. Unknown = cannot be determined, not "no capability"; only None / FreeRunOnly / Sync0 / Sync0AndSync1 are definite conclusions. Answers "can it do SYNC0", not "is it armed right now"
DC diagnosticsSlaveDC::TryGetDcArmOutcome(dll, mi, si)std::optional<DcArmResult>read-onlyAlways returns nullopt: the automatic startup arming final-state accounting is maintained by the SDK, and this language wrapper cannot obtain it equivalently. For the reason see DcArmOutcomeUnavailableReason(). Do not use it as DcArmResult::Unknown — the latter means "there is accounting but no record for this slave in this sample"
DC diagnosticsSlaveDC::DcArmOutcomeUnavailableReason()const char*read-onlyThe reason text for why TryGetDcArmOutcome is always unavailable (Chinese, can be displayed directly)
DC diagnosticsSlaveDC::GetDcAssignActivate(dll, mi, si)std::optional<uint16_t>read-only0x0980 landed mirror (proven by read-back after the runtime writes). nullopt = no DC capability / unreadable; 0 = has DC capability but is not active right now (FreeRun). Does not mean armed or synchronized
DC diagnosticsSlaveDC::GetDcSync0CycleNs(dll, mi, si)std::optional<int>read-only0x09A0 landed mirror (ns). nullopt = no DC / unreadable; 0 = the runtime has not landed a cycle (not armed / FreeRun), not a "0 ns cycle"
DC diagnosticsSlaveDC::GetDcSync1CycleNs(dll, mi, si)std::optional<int>read-only0x09A4 landed mirror; nullopt / 0 have the same meaning as SYNC0
DC diagnosticsSlaveDC::GetDcShiftTruth(dll, mi, si, &shift, &source) / SlaveDC::GetDcShiftTruth(dll, mi, si)int32_t / DcShiftTruthread-onlyPer-slave phase truth: 1 = both output parameters are valid (0 and negative values are all legal phases), <= SlaveDC::kDcShiftNoConclusionMax = no conclusion and the output parameters are invalid. In the struct overload, when available == false the shift_ns / source members are not values. Read-only, sends no frames, writes no registers, readable in OP
DC diagnosticsSlaveDC::GetDcPropagationDelayNs(dll, mi, si)std::optional<int>read-only0x0928 landed value (ns). nullopt = no DC / unreadable / the underlying reading is negative
DC diagnosticsSlaveDC::GetDcPropagationDelaySource(dll, mi, si)DcPropagationDelayOriginread-onlyCompanion to the previous item: Unknown = no conclusion; ZeroNsAmbiguous = 0 ns has two meanings (domain root / not measured), so do not invent "this slave is the domain root"; NonZeroLandedBaseline = non-zero landed baseline (this measurement and reuse within the session cannot be distinguished)
DC diagnosticsSlaveDC::GetDcSyncWindow(dll, mi, si)DcSyncWindowInforead-only0x092C measured surface + domain shell; when not applicable every numeric field is nullopt, and the constructor guarantees that an instance which is "unavailable yet carries 0 values" cannot be created
DC diagnosticsSlaveDC::Sync0Armed(dll, mi, si)std::optional<bool>read-onlyWhether SYNC0 is armed, three states: true = armed (configuration landed) / false = not armed with evidence / nullopt = cannot be determined. Being armed does not mean the whole network clock has converged
DC diagnosticsMasterDiagnosticsInfo::DcConvergenceMs(si)std::optional<int>read-onlyConvergence time (ms). Requires 2 s of accumulated snapshots; nullopt until the complete transition "first armed but not in window → first in window" has been observed
DC diagnosticsMasterDiagnosticsInfo::DcJitter(si)std::optional<DcJitterStats>read-onlySteady-state quality (σ / peak-to-peak / maximum adjacent change). With fewer than 2 samples the whole result is nullopt; a single point is not passed off as stable

DcSyncWindowInfo fields​

CategoryFieldTypeRead/writeDescription
DC diagnosticsApplicableboolread-onlytrue = this slave is a SYNC0 participant and a measurement was read; for false see NotApplicableReason
DC diagnosticsNotApplicableReasonDcSyncWindowNaReasonread-onlyReason it does not apply; None when it does apply
DC diagnosticsDiffNsstd::optional<int>read-onlyCurrent synchronization difference (ns); nullopt when unavailable
DC diagnosticsMaxDiffNsstd::optional<int>read-onlyMaximum difference within the window (ns); nullopt when unavailable
DC diagnosticsMinDiffNsstd::optional<int>read-onlyMinimum difference within the window (ns); nullopt when unavailable
DC diagnosticsOutOfSyncCountstd::optional<uint32_t>read-onlyCumulative number of times the synchronization window was exceeded; nullopt when unavailable
DC diagnosticsInSyncstd::optional<bool>read-onlyWhether this sample is inside the synchronization window (runtime measurement ∧ SYNC0 armed). Exceeding the window is a real conclusion false, not "unavailable"
DC diagnosticsSyncWindowThresholdNsstd::optional<int>read-onlySynchronization window threshold (ns); nullopt = unreadable
DC diagnosticsReadingUnchangedstd::optional<bool>read-onlyWhether the four 0x092C readings have stayed completely unchanged for several consecutive samples (frozen proxy bit). nullopt = not enough samples; false does not equal "confirmed to be advancing"
DC diagnosticsUnchangedStreakintread-onlyNumber of consecutive samples with identical readings (the same counter as ReadingUnchanged)
DC diagnosticsSampledAtUtcstd::optional<std::chrono::system_clock::time_point>read-onlySampling time of this sample (UTC); nullopt when unavailable
DC diagnosticsState()std::optional<DcSyncWindowState>read-onlySeven-state display classification; nullopt = not one of the seven states (read-failure family / armed but out of window)

Seven states​

CategoryStateDecision conditionRead/writeMeaning
DC diagnosticsNoDcCapabilityno DC capability and the ESI has a conclusionread-onlyThere is no SYNC0 cycle unit, so synchronization error does not exist
DC diagnosticsSync0NotArmedSync0Armed == falseread-onlyKnown not to participate in DC synchronization, 0x092C is undefined
DC diagnosticsReferenceClockItselfthe reference clock slave index is known and equals this slaveread-onlyThe reference clock's own synchronization error does not exist by definition
DC diagnosticsReadingFrozenApplicable and ReadingUnchanged == trueread-onlyThe four readings have stayed completely unchanged for several consecutive samples (frozen proxy bit)
DC diagnosticsInWindowApplicable and InSync == trueread-onlyArmed and measured inside the synchronization window
DC diagnosticsArmedUnknownSync0Armed == nulloptread-onlyThe runtime cannot answer, so participation cannot be asserted either way
DC diagnosticsNotSampledApplicable == false and the reason is NotSampledread-onlyAll four are 0 and not in the window; 0 is not "perfect synchronization"

The two classes outside the seven states (State() returns nullopt)​

CategoryCaseRead/writeDecision and handling
DC diagnosticsread-failure family: SlaveReadFailed / ReferenceClockUnknown / WindowReadFailedread-onlyThe reason can still be read from NotApplicableReason; it must not be forced into one of the states. The three respectively mean: the slave snapshot cannot be read, the reference clock slave index cannot be read, armed and not the reference clock but the window measurement failed
DC diagnosticsarmed but out of window: Applicable == true and InSync == false (not frozen)read-onlyThis is a real conclusion, not an unknown. Read the false of InSync; do not treat it as "not armed" or "unknown"

Three honest states​

CategoryConclusionTypeRead/writeRepresentation when there is no conclusion
DC diagnosticswhether all are in the window AllInSyncstd::optional<bool>read-onlyno confirmed participant (no DC / all not armed / only the reference clock) → nullopt, not true
DC diagnosticsmaximum synchronization difference MaxDriftNsstd::optional<int>read-onlyno usable measurement window at all → nullopt, not 0
DC diagnosticsSYNC0 armed Sync0Armedstd::optional<bool>read-onlythe runtime cannot answer → nullopt, not false

Supplementary rules:

  • "Not applicable" is never written as 0. The reference clock's own synchronization window is always N/A; not armed / no DC / never sampled likewise produce no 0 ns.
  • "Don't know" and "definitely not armed / definitely not in the window" are two conclusions, and no layer may convert one into the other.
  • AllInSync can be true / false only when there is a confirmed participant that is "armed + not the reference clock"; when a participant exists but was not sampled, cannot be read or has not entered the window it is truthfully false; when any DC slave's arming is unknown it is conservatively false.
  • TryGetDcArmOutcome being unavailable means "this language has no such accounting", not "not participating in arming", and not DcArmResult::Unknown.

Example:

using namespace darra;

auto& s = master.GetSlave(1);
uint16_t mi = master.MasterNumber();

// Tri-state: nullopt = cannot determine, do not collapse it to false
if (SlaveDC::Sync0Armed(s.Dll(), mi, 1).value_or(false)) {
printf("SYNC0 已武装\n"); // SYNC0 armed\n
}

DcSyncWindowInfo win = SlaveDC::GetDcSyncWindow(s.Dll(), mi, 1);
if (auto state = win.State()) {
// One of the seven states
} else if (win.Applicable) {
// Armed but measured outside the window: *win.InSync == false is a real conclusion
} else {
// Read-failure family: see win.NotApplicableReason
}

if (SlaveDC::GetDcCapability(s.Dll(), mi, 1) == DcCapability::Unknown) {
// Cannot be determined (not "no capability")
}

DC synchronization loss event​

Register a DC synchronization loss callback through the master event with OnDCSyncLost():

master.Events().OnDCSyncLost([](uint16_t mi, uint16_t si, int diffNs) {
printf("[从站%d] DC 同步丢失: 偏差 %dns\n", si, diffNs); // [Slave%d] DC sync lost: deviation %dns\n
});

Reference clock and time base​

  • Reference clock: the master selects, in chain order, the first slave on the link that has DC activated (real SYNC0); when there is no armed slave at all it falls back to the first DC-capable slave on the chain. The whole bus has this one time base.
  • Single start point: the reference domain has only one start instant (the same physical instant); the master converts it per each slave's time domain and writes it into 0x0990 — it is not a separately measured start point per slave.
  • Reference clock change (lost slave / hot-plug / capability change): every 0x0920 written in the old clock's time domain becomes invalid. In chain order the master re-reads 0x0920 for every DC slave that is not in OP, not offline and not the reference clock itself, proves it by reading back, then rewrites that slave's 0x0990 in the new time domain; slaves in OP do not interrupt SYNC0 and have their error corrected by the online correction.
  • Pure phase: 0x0928 is corrected by the ESC in hardware when SYNC0 is generated; shiftNs is only a phase displacement and contains no propagation delay compensation.
  • Diagnostics: the current SDK does not expose read-only properties for 0x0990 / 0x0920; register-level evidence can be found in the DC diagnostic output of events.log.

Full example​

#include "ethercat.hpp"
using namespace darra;

int main() {
EtherCATMaster master(dll);
master.SetNetwork("\\Device\\NPF_{...}")
.SetENI("config.deni")
.Build();

auto& slave = master.GetSlave(1);

// Configure SYNC0 = 1 ms
slave.ConfigureDC(1'000'000);

printf("传播延迟: %d ns\n", slave.PropagationDelay()); // Propagation delay: %d ns\n

// Enter OP
master.SetState(EcState::OP);
master.Start();

// Monitor the sync status
auto status = slave.GetSyncWindowStatus();
if (status) {
printf("同步差=%dns, 同步=%s, 超出次数=%u\n", // sync diff=%dns, synced=%s, out-of-sync count=%u\n
status->DiffNs,
status->InSync ? "是" : "否",
status->OutOfSyncCount);
}

getchar();
return 0;
}