atcommand_query/
atcommand_query.rs

1//! AtCommand API Query example
2//!
3//! This example shows how to read the NodeId from connected XBee Device
4//!
5//!
6
7use rustbee::{api, device::DigiMeshDevice};
8use std::error;
9
10#[cfg(target_os = "linux")]
11static PORT: &'static str = "/dev/ttyUSB0";
12
13#[cfg(target_os = "windows")]
14static PORT: &'static str = "COM1";
15
16fn main() -> Result<(), Box<dyn error::Error>> {
17    // first create instance of device
18    let mut device = DigiMeshDevice::new(PORT, 9600)?;
19
20    // Construct At command to ask for node_id of device
21    let node_id_request = api::AtCommandFrame("NI", None);
22    // returns dyn trait RecieveApiFrame
23    let response = device.send_frame(node_id_request)?;
24    // We can downcast to original AtCommandResponse struct to access members
25    let atcommand_response = response.downcast_ref::<api::AtCommandResponse>();
26
27    if let Some(obj) = atcommand_response {
28        let cmd_data = &obj.command_data;
29        println!("{:?}", cmd_data);
30    }
31
32    Ok(())
33}