block_access/
block_access.rs

1use slmp::*;
2
3const SLMP_PROPS: SLMP4EConnectionProps = SLMP4EConnectionProps {
4    ip: "192.168.3.10",
5    port: 5007,
6    cpu: CPU::R,
7    serial_id: 0x0001,
8    network_id: 0x00,
9    pc_id: 0xff,
10    io_id: 0x03ff,
11    area_id: 0x00,
12    cpu_timer: 0x0010,
13};
14
15#[tokio::main]
16async fn main() {
17    let mut client = SLMPClient::new(SLMP_PROPS);
18    client.connect().await.unwrap();
19
20    let data= [
21        BlockedDeviceData { 
22            access_type: AccessType::Word,
23            start_device: Device{device_type: DeviceType::D, address: 10},
24            data: &[ TypedData::U16(10), TypedData::U16(20) ]
25        },
26        BlockedDeviceData {
27            access_type: AccessType::Word,
28            start_device: Device{device_type: DeviceType::D, address: 20},
29            data: &[ TypedData::U16(30), TypedData::U16(40) ]
30        },
31        BlockedDeviceData {
32            access_type: AccessType::Bit,
33            start_device: Device{device_type: DeviceType::M, address: 0},
34            data: &[ TypedData::Bool(true), TypedData::Bool(false), TypedData::Bool(true) ]
35        },
36    ];
37    client.block_write(&data).await.unwrap();
38
39    let device_blocks = [
40        DeviceBlock{ access_type: data[0].access_type, start_device: data[0].start_device, size: data[0].data.len()},
41        DeviceBlock{ access_type: data[1].access_type, start_device: data[1].start_device, size: data[1].data.len()},
42        DeviceBlock{ access_type: data[2].access_type, start_device: data[2].start_device, size: data[2].data.len()},
43    ];
44
45    let ret: Vec<DeviceData> = client.block_read(&device_blocks).await.unwrap();
46    println!("\nDevice & Bit access:");
47    for data in ret {
48        println!("{:?}", data);
49    }
50    println!();
51
52    client.close().await;
53}
54
55