Link State Monitoring
The Checker lets you monitor whether the EtherCAT link to the device is working correctly.
Obtaining the Checker
Section titled “Obtaining the Checker”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?;client, checker = await Client.open_with_checker( geometry, echocat.EchocatLinkOption(), ClientConfig(),)var (client, checker) = await Client.OpenWithCheckerAsync( geometry, new EchocatLinkOption(), new ClientConfig());Obtaining the State
Section titled “Obtaining the State”Checker::check returns the link state LinkStatus at the time of the call.
LinkStatus holds the following.
devices: the state of each device (DeviceState).OPwhen normal,LOSTwhen disconnected, etc.all_op: whether all devices are in theOPstate.any_lost: whether any device is in theLOSTstate.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;}last = Nonewhile True: status = await checker.check() if status != last: for i, state in enumerate(status.device_states): print(f"device[{i}]: {state}") print(f"all operational: {status.all_op}, any lost: {status.any_lost}, recoveries: {status.recoveries}") last = status await asyncio.sleep(CHECK_INTERVAL)LinkStatus? last = null;while (true){ var status = await checker.CheckAsync(); if (status != last) { for (var i = 0; i < status.Devices.Count; i++) { Console.WriteLine($"device[{i}]: {status.Devices[i]}"); } Console.WriteLine($"all operational: {status.AllOp}, any lost: {status.AnyLost}, recoveries: {status.Recoveries}"); last = status; } await Task.Delay(CheckInterval);}How often to call check is up to the user.