use std::env;
use std::time::Duration;
use tango::dev::DevProxy;
use tango::error::{ErrorKind, Result};
fn report<T>(what: &str, res: Result<T>) {
match res {
Ok(_) => println!("{what}: no error"),
Err(err) => println!("{what}: {err:#}"),
}
}
fn main() -> Result<()> {
let name = env::args().nth(1).unwrap_or_else(|| "test/motor/1".to_string());
let motor = DevProxy::new(name.as_str());
report("MoveTo past the limit", motor.command::<_, f64>("MoveTo", 1000.0));
report("Writing past the limit", motor.write_attr(("position", 1000.0)));
match motor.command::<_, ()>("Home", ()) {
Err(err) if err.kind() == ErrorKind::CommandNotFound => println!("The motor has no Home command, as expected"),
res => report("Unknown command", res),
}
report("Argument of the wrong type", motor.command::<_, f64>("MoveTo", "north"));
report("Writing a read-only attribute", motor.write_attr(("limit", 10.0)));
report("Reading an unknown attribute", motor.read_attr::<f64, _>("velocity"));
report("Reading as the wrong type", motor.read_attr::<String, _>("position"));
let mut missing = DevProxy::new("test/motor/missing");
missing.set_timeout(Duration::from_secs(1));
report("Unknown device", missing.ping());
Ok(())
}