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