output_only/
output-only.rs

1//! Simple example of using remote_xy library with only one output signal plotted in the app.
2//! Just run this example and add a new Ethernet device in the RemoteXY app (port 6377)
3
4use anyhow::Result;
5use remote_xy::remote_xy;
6use remote_xy::RemoteXY;
7use serde::Deserialize;
8use serde::Serialize;
9use std::time::Duration;
10
11const CONF_BUF: &[u8] = &[
12    255, 0, 0, 4, 0, 11, 0, 16, 31, 0, 68, 17, 0, 0, 100, 63, 8, 36,
13];
14
15#[derive(Serialize, Deserialize, Default)]
16#[repr(C)]
17struct InputData {
18    // no input variables
19}
20
21#[derive(Serialize, Deserialize)]
22#[repr(C)]
23struct OutputData {
24    // output variables
25    online_graph_1: f32,
26    // do not include the `connect_flag` variable
27}
28
29// provide custom initial values for the output variables if needed:
30impl Default for OutputData {
31    fn default() -> Self {
32        Self {
33            online_graph_1: 1.23,
34        }
35    }
36}
37
38#[tokio::main]
39async fn main() -> Result<()> {
40    let remotexy = remote_xy!(InputData, OutputData, "[::]:6377", CONF_BUF).await?;
41    let mut output = OutputData::default();
42    let mut x = 0.0;
43
44    while remotexy.is_connected() == false {
45        tokio::time::sleep(Duration::from_millis(200)).await;
46    }
47
48    println!("Connected to RemoteXY app");
49
50    // wait some time to see the effect of default custum signals
51    tokio::time::sleep(Duration::from_millis(2000)).await;
52
53    println!("Starting to send data");
54    loop {
55        output.online_graph_1 = f32::sin(x);
56        remotexy.set_output(&output);
57        x += 0.1;
58
59        tokio::time::sleep(Duration::from_millis(50)).await;
60    }
61}