DcSysTime
DcSysTime is a type representing a time on the EtherCAT distributed clock (Distributed Clock, DC).
It is used with TransitionMode::SysTime, GpioOut::SysTimeEq, and the like.
In EtherCAT, there is a clock synchronized across all slaves (the distributed clock), and each device operates in sync with it. This time is a 64-bit counter in ns units, counted from 2000-01-01 00:00:00 (UTC).
Construction
Section titled “Construction”DcSysTime is constructed from the current time, a UTC datetime, or raw ns.
let epoch = DcSysTime::ZERO;let now = DcSysTime::now();let at = DcSysTime::from_utc(Utc.with_ymd_and_hms(2025, 1, 1, 0, 0, 0).unwrap()).unwrap();let raw = DcSysTime::from_nanos(1_000_000_000);let ns: u64 = now.sys_time();let utc = now.to_utc();epoch = DcSysTime.ZEROnow = DcSysTime.now()raw = DcSysTime.from_nanos(1_000_000_000)ns = now.sys_timevar epoch = DcSysTime.Zero;var now = DcSysTime.Now();var at = DcSysTime.FromUtc(new DateTime(2025, 1, 1, 0, 0, 0, DateTimeKind.Utc));var raw = DcSysTime.FromNanos(1_000_000_000);ulong ns = now.SysTime;DateTime utc = now.ToUtc();| Operation | Description |
|---|---|
ZERO |
Epoch (2000-01-01 00:00:00 UTC) |
now() |
Current time of the host |
from_nanos(ns) |
Construct from ns elapsed since the epoch |
from_utc(utc) |
Construct from a UTC datetime |
sys_time() |
ns elapsed since the epoch |
to_utc() |
Convert to a UTC datetime |
Arithmetic
Section titled “Arithmetic”DcSysTime defines operations that add and subtract time differences.
let future = DcSysTime::now() + Duration::from_millis(100);let past = future - Duration::from_millis(50);let elapsed: Duration = future - past;let is_after: bool = future > past; // truefuture = DcSysTime.now() + Duration.from_millis(100)past = future - Duration.from_millis(50)var future = DcSysTime.Now() + TimeSpan.FromMilliseconds(100);var past = future - TimeSpan.FromMilliseconds(50);bool isAfter = future > past; // true| Operation | Result | Description |
|---|---|---|
DcSysTime + Duration |
DcSysTime |
Add the specified duration |
DcSysTime - Duration |
DcSysTime |
Subtract the specified duration |
DcSysTime - DcSysTime |
Duration |
Difference between two times (Rust only) |
Comparison (< / > / ==, etc.) |
bool |
Comparison (Rust / C# only) |
Rust uses core::time::Duration for Duration, C# uses TimeSpan, and Python uses autd3.Duration.
Python provides only addition and subtraction (applying a time difference via + / -); it does not have computing a time difference or comparison.