rstango 0.4.0

Implementation of the Tango distributed control system
Documentation
//! What a client learns of a device without knowing it in advance, against a device of the
//! `server` example: its class, its commands and its attributes, as the device
//! describes them, and its admin device.
//!
//! ```sh
//! cargo run --example info -- test/motor/1
//! ```

use std::env;

use tango::dev::{All, DevProxy, Named};
use tango::error::Result;


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

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

    let info = motor.info()?;
    println!("{} is a {} served by {} on {}", motor.name()?, info.class, info.server_id, info.server_host);
    println!("  documented at {:?}", info.doc_url);

    // Every command, the ones every device has included, as the device describes them,
    // each entry carrying its own failure.
    println!("Commands:");
    for Named { name, value: info } in motor.command_info(All)? {
        let info = info?;
        println!("  {:<10} {:?} -> {:?}", name.value(), info.in_kind, info.out_kind);
    }

    // The attributes, `limit` included: it is added by each device at its initialization
    // rather than by the class, which a client cannot tell apart.
    println!("Attributes:");
    for Named { name, value: info } in motor.attr_info(All)? {
        let info = info?;
        println!("  {:<10} {:?} {:?} {:?}, unit {:?}", name.value(), info.mode, info.data_kind,
            info.data_format, info.config.unit);
    }

    // One attribute is described by its name alone, with the whole of its configuration.
    let position = motor.attr_info("position")?;
    println!("position: {:?}, format {:?}, change event {:?}", position.config.doc,
        position.config.display_format, position.config.change_event);

    // The admin device is the one of the server, which every device has.
    let admin = motor.admin_dev()?;
    println!("The admin device is {}, which is {:?}", admin.name()?, admin.state()?);

    Ok(())

}