Skip to content
This is the development version of the documentation. It may change before the next release. See 0.14.x for the latest release.

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.

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();
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

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; // 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