bulk_access/
bulk_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 start_device: Device = Device{device_type: DeviceType::D, address: 0};
23
24 for i in 0..200 {
25 let data: Vec<TypedData> = [0u16; 120]
26 .iter()
27 .enumerate()
28 .map(|(j, _)| TypedData::U16(i as u16 + j as u16))
29 .collect();
30
31 client.bulk_write(start_device, &data).await.unwrap();
32
33 tokio::time::sleep(tokio::time::Duration::from_millis(100)).await;
34 }
35
36 let ret: Vec<DeviceData> = client.bulk_read(start_device, 8, DataType::U16).await.unwrap();
37 println!("\nDevice access:");
38 for x in ret {
39 println!("{:?}", x);
40 }
41
42 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}