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