Skip to content

Link State Monitoring

The Checker lets you monitor whether the EtherCAT link to the device is working correctly.

Using open_with_checker instead of the usual Client::open returns a pair of Client and Checker.

let (client, mut checker) = Client::open_with_checker(
&geometry,
EchocatLinkOption::default(),
ClientConfig::default(),
)
.await?;

Checker::check returns the link state LinkStatus at the time of the call. LinkStatus holds the following.

  • devices: the state of each device (DeviceState). OP when normal, LOST when disconnected, etc.
  • all_op: whether all devices are in the OP state.
  • any_lost: whether any device is in the LOST state.
  • recoveries: the cumulative number of recoveries from disconnection.

The following is an example that calls check at fixed intervals and outputs only when the state changes.

let mut last: Option<LinkStatus> = None;
loop {
let status = checker.check().await?;
if last.as_ref() != Some(&status) {
for (i, state) in status.devices().iter().enumerate() {
println!("device[{i}]: {state}");
}
println!(
"all operational: {}, any lost: {}, recoveries: {}",
status.all_op(),
status.any_lost(),
status.recoveries()
);
last = Some(status);
}
tokio::time::sleep(CHECK_INTERVAL).await;
}

How often to call check is up to the user.