block_access/
block_access.rs1use 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 let data= [
22 BlockedDeviceData {
23 access_type: AccessType::Word,
24 start_device: Device{device_type: DeviceType::D, address: 10},
25 data: &[ TypedData::U16(10), TypedData::U16(20) ]
26 },
27 BlockedDeviceData {
28 access_type: AccessType::Word,
29 start_device: Device{device_type: DeviceType::D, address: 20},
30 data: &[ TypedData::U16(30), TypedData::U16(40) ]
31 },
32 BlockedDeviceData {
33 access_type: AccessType::Bit,
34 start_device: Device{device_type: DeviceType::M, address: 0},
35 data: &[ TypedData::Bool(true), TypedData::Bool(false), TypedData::Bool(true) ]
36 },
37 ];
38 client.block_write(&data).await.unwrap();
39
40 let device_blocks = [
41 DeviceBlock{ access_type: data[0].access_type, start_device: data[0].start_device, size: data[0].data.len()},
42 DeviceBlock{ access_type: data[1].access_type, start_device: data[1].start_device, size: data[1].data.len()},
43 DeviceBlock{ access_type: data[2].access_type, start_device: data[2].start_device, size: data[2].data.len()},
44 ];
45
46 let ret: Vec<DeviceData> = client.block_read(&device_blocks).await.unwrap();
47 println!("\nDevice & Bit access:");
48 for data in ret {
49 println!("{:?}", data);
50 }
51 println!();
52
53 client.close().await;
54}
55
56