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