bulk_access/
bulk_access.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 start_device: Device = Device{device_type: DeviceType::D, address: 4000};
23    let data = [
24        TypedData::U16(10),
25        TypedData::U16(20),
26        TypedData::U16(30),
27        TypedData::U16(40),
28        TypedData::U16(50),
29        TypedData::U16(60),
30        TypedData::U16(70),
31        TypedData::U16(80),
32    ];
33
34    client.bulk_write(start_device, &data).await.unwrap();
35
36    let ret: Vec<DeviceData> = client.bulk_read(start_device, data.len(), DataType::U16).await.unwrap();
37    println!("\nDevice access:");
38    for x in ret {
39        println!("{:?}", x);
40    }
41
42    // Bit data
43    let start_device: Device = Device{device_type: DeviceType::M, address: 0};
44    let data = vec![
45        TypedData::Bool(true),
46        TypedData::Bool(false),
47        TypedData::Bool(false),
48        TypedData::Bool(true),
49    ];
50
51    client.bulk_write(start_device, &data).await.unwrap();
52
53    let ret: Vec<DeviceData> = client.bulk_read(start_device, data.len(), DataType::Bool).await.unwrap();
54    println!("\nBit access:");
55    for x in ret {
56        println!("{:?}", x);
57    }
58    println!();
59
60    client.close().await;
61}
62