rstango 0.3.0

Implementation of the Tango distributed control system
Documentation
//! The basics of a client, against a device of the `server` example: its state,
//! reading and writing its attributes, and executing its commands.
//!
//! ```sh
//! cargo run --example client -- test/motor/1
//! ```

use std::env;

use tango::dev::{AttrRead, DevProxy};
use tango::error::Result;


fn main() -> Result<()> {

    let name = env::args().nth(1).unwrap_or_else(|| "test/motor/1".to_string());

    // Nothing is reached yet: the device is looked up in the database on the first request.
    let motor = DevProxy::new(name.as_str());
    println!("{} is {:?}: {}", motor.name()?, motor.state()?, motor.status()?);

    // A reading carries more than the value: the set point of a writable attribute, the
    // quality of the value and when it was read.
    let read: AttrRead<f64> = motor.read_attr::<f64, _>("position")?;
    println!("position = {:?} (set point {:?}, {:?})", read.value, read.w_value, read.quality);

    // A tuple of names is read in one request, each reading being typed on its own.
    let (position, limit) = motor.read_attr::<(f64, f64), _>(("position", "limit"))?;
    println!("position = {:?}, limit = {:?}", position?.value, limit?.value);

    // Writing the position moves the axis, and the read back saves a second request.
    motor.write_attr(("position", 12.5))?;
    let read = motor.write_read_attr(("position", 25.0))?;
    println!("position written and read back = {:?}", read.value);

    // A command is typed on both of its sides, `()` being no data.
    let reached: f64 = motor.command("MoveTo", -42.0)?;
    println!("MoveTo(-42) -> {reached}");
    motor.command::<_, ()>("Stop", ())?;

    println!("{} is {:?}: {}", motor.name()?, motor.state()?, motor.status()?);
    Ok(())

}