SysTime
SysTime is a type representing the time of the devices.
It is used with TransitionMode::SysTime, GpioOut::SysTimeEq, and the like.
Each device has its own clock, and output switching and the like happen on this time.
This time is a 64-bit counter in ns units, counted from the moment the Client opens.
It does not correspond to the host clock (date and time).
The current time of the devices is obtained with device_time_now() of the Client.
Since the time of the devices cannot be read directly, the value returned by device_time_now() is an estimate.
The estimate is more accurate when there are more samples of sent and received data, and when data was sent and received just before.
To estimate accurately, send heartbeat periodically, and also send heartbeat just before calling device_time_now.
Construction
Section titled “Construction”SysTime is constructed from the current time of the devices or raw ns.
let opened = SysTime::ZERO;let now = client.device_time_now()?;let raw = SysTime::from_nanos(1_000_000_000);let ns: u64 = now.sys_time();opened = SysTime.ZEROnow = client.device_time_now()raw = SysTime.from_nanos(1_000_000_000)ns = now.sys_timevar opened = SysTime.Zero;var now = client.DeviceTimeNow();var raw = SysTime.FromNanos(1_000_000_000);ulong ns = now.Nanos;| Operation | Description |
|---|---|
ZERO |
The moment the Client opened |
Client::device_time_now() |
Current time of the devices |
from_nanos(ns) |
Construct from ns elapsed since the open |
sys_time() |
ns elapsed since the open |
Arithmetic
Section titled “Arithmetic”SysTime defines operations that add and subtract time differences.
let future = client.device_time_now()? + Duration::from_millis(100);let past = future - Duration::from_millis(50);let elapsed: Duration = future - past;let is_after: bool = future > past; // truefuture = client.device_time_now() + Duration.from_millis(100)past = future - Duration.from_millis(50)elapsed = future - pastis_after = future > pastvar future = client.DeviceTimeNow() + TimeSpan.FromMilliseconds(100);var past = future - TimeSpan.FromMilliseconds(50);TimeSpan elapsed = future - past;bool isAfter = future > past; // true| Operation | Result | Description |
|---|---|---|
SysTime + Duration |
SysTime |
Add the specified duration |
SysTime - Duration |
SysTime |
Subtract the specified duration |
SysTime - SysTime |
Duration |
Difference between two times (0 if it would be negative) |
Comparison (< / > / ==, etc.) |
bool |
Comparison |