monitor_read/
monitor_read.rs

1use slmp::*;
2
3#[tokio::main]
4async fn main() {
5    
6    let connection_props: SLMP4EConnectionProps = SLMP4EConnectionProps {
7        ip: String::from("192.168.3.10"),
8        port: 5007,
9        cpu: CPU::R,
10        serial_id: 0x0001,
11        network_id: 0x00,
12        pc_id: 0xff,
13        io_id: 0x03ff,
14        area_id: 0x00,
15        cpu_timer: 0x0010,
16    };
17
18    let mut client = SLMPClient::new(connection_props);
19    client.connect().await.unwrap();
20
21    // Word data
22    let devices = [
23        Device{device_type: DeviceType::D, address: 20},
24        Device{device_type: DeviceType::D, address: 25},
25        Device{device_type: DeviceType::D, address: 30},
26        Device{device_type: DeviceType::D, address: 35},
27    ];
28
29    let data = [
30        TypedData::U16(10),
31        TypedData::U16(20),
32        TypedData::I16(-40),
33        TypedData::U32(80000),
34    ];
35
36    let wr_data = [
37        DeviceData{device: devices[0], data: data[0]},
38        DeviceData{device: devices[1], data: data[1]},
39        DeviceData{device: devices[2], data: data[2]},
40        DeviceData{device: devices[3], data: data[3]},
41    ];
42    client.random_write(&wr_data).await.unwrap();
43
44    let devices = [
45        TypedDevice{device: devices[0], data_type: DataType::U16},
46        TypedDevice{device: devices[1], data_type: DataType::U16},
47        TypedDevice{device: devices[2], data_type: DataType::I16},
48        TypedDevice{device: devices[3], data_type: DataType::U32},
49    ];
50
51    let monitor_list = client.monitor_register(&devices).await.unwrap();
52
53    tokio::time::sleep(tokio::time::Duration::from_millis(100)).await;
54
55    let ret = client.monitor_read(&monitor_list).await.unwrap();
56
57    println!("\nDevice access:");
58    for x in ret {
59        println!("{:?}", x);
60    }
61
62    client.close().await;
63}
64