random_access/
random_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 devices = [
23 Device{device_type: DeviceType::D, address: 20},
24 Device{device_type: DeviceType::D, address: 25},
25 Device{device_type: DeviceType::D, address: 30},
26 Device{device_type: DeviceType::D, address: 35},
27 ];
28
29 let data = [
30 TypedData::U16(10),
31 TypedData::U16(20),
32 TypedData::I16(-40),
33 TypedData::U32(80000),
34 ];
35
36 let wr_data = [
37 DeviceData{device: devices[0], data: data[0]},
38 DeviceData{device: devices[1], data: data[1]},
39 DeviceData{device: devices[2], data: data[2]},
40 DeviceData{device: devices[3], data: data[3]},
41 ];
42 client.random_write(&wr_data).await.unwrap();
43
44 let devices = [
45 TypedDevice{device: devices[0], data_type: DataType::U16},
46 TypedDevice{device: devices[1], data_type: DataType::U16},
47 TypedDevice{device: devices[2], data_type: DataType::I16},
48 TypedDevice{device: devices[3], data_type: DataType::U32},
49 ];
50
51 let ret = client.random_read(&devices).await.unwrap();
52 println!("\nDevice access:");
53 for x in ret {
54 println!("{:?}", x);
55 }
56
57 let devices = [
59 Device{device_type: DeviceType::M, address: 0},
60 Device{device_type: DeviceType::M, address: 1},
61 Device{device_type: DeviceType::M, address: 2},
62 Device{device_type: DeviceType::M, address: 3},
63 ];
64
65 let data = [
66 TypedData::Bool(true),
67 TypedData::Bool(false),
68 TypedData::Bool(true),
69 TypedData::Bool(false),
70 ];
71
72 let wr_data = [
73 DeviceData{device: devices[0], data: data[0]},
74 ];
75 client.random_write(&wr_data).await.unwrap();
76
77 let ret: Vec<DeviceData> = client.bulk_read(devices[0], data.len(), DataType::Bool).await.unwrap();
78 println!("\nBit access:");
79 for x in ret {
80 println!("{:?}", x);
81 }
82 println!();
83
84 client.close().await;
85}
86