pub struct SLMPClient { /* private fields */ }Implementations§
Source§impl SLMPClient
impl SLMPClient
Sourcepub fn new(connection_props: SLMP4EConnectionProps) -> Self
pub fn new(connection_props: SLMP4EConnectionProps) -> Self
Examples found in repository?
examples/bulk_access.rs (line 17)
16async fn main() {
17 let mut client = SLMPClient::new(SLMP_PROPS);
18 client.connect().await.unwrap();
19
20 // Word data
21 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 // Bit data
42 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}More examples
examples/block_access.rs (line 17)
16async fn main() {
17 let mut client = SLMPClient::new(SLMP_PROPS);
18 client.connect().await.unwrap();
19
20 let data= [
21 BlockedDeviceData {
22 access_type: AccessType::Word,
23 start_device: Device{device_type: DeviceType::D, address: 10},
24 data: &[ TypedData::U16(10), TypedData::U16(20) ]
25 },
26 BlockedDeviceData {
27 access_type: AccessType::Word,
28 start_device: Device{device_type: DeviceType::D, address: 20},
29 data: &[ TypedData::U16(30), TypedData::U16(40) ]
30 },
31 BlockedDeviceData {
32 access_type: AccessType::Bit,
33 start_device: Device{device_type: DeviceType::M, address: 0},
34 data: &[ TypedData::Bool(true), TypedData::Bool(false), TypedData::Bool(true) ]
35 },
36 ];
37 client.block_write(&data).await.unwrap();
38
39 let device_blocks = [
40 DeviceBlock{ access_type: data[0].access_type, start_device: data[0].start_device, size: data[0].data.len()},
41 DeviceBlock{ access_type: data[1].access_type, start_device: data[1].start_device, size: data[1].data.len()},
42 DeviceBlock{ access_type: data[2].access_type, start_device: data[2].start_device, size: data[2].data.len()},
43 ];
44
45 let ret: Vec<DeviceData> = client.block_read(&device_blocks).await.unwrap();
46 println!("\nDevice & Bit access:");
47 for data in ret {
48 println!("{:?}", data);
49 }
50 println!();
51
52 client.close().await;
53}examples/random_access.rs (line 17)
16async fn main() {
17 let mut client = SLMPClient::new(SLMP_PROPS);
18 client.connect().await.unwrap();
19
20 // Word data
21 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 // Bit data
57 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}Sourcepub async fn close(&self)
pub async fn close(&self)
Examples found in repository?
examples/bulk_access.rs (line 59)
16async fn main() {
17 let mut client = SLMPClient::new(SLMP_PROPS);
18 client.connect().await.unwrap();
19
20 // Word data
21 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 // Bit data
42 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}More examples
examples/block_access.rs (line 52)
16async fn main() {
17 let mut client = SLMPClient::new(SLMP_PROPS);
18 client.connect().await.unwrap();
19
20 let data= [
21 BlockedDeviceData {
22 access_type: AccessType::Word,
23 start_device: Device{device_type: DeviceType::D, address: 10},
24 data: &[ TypedData::U16(10), TypedData::U16(20) ]
25 },
26 BlockedDeviceData {
27 access_type: AccessType::Word,
28 start_device: Device{device_type: DeviceType::D, address: 20},
29 data: &[ TypedData::U16(30), TypedData::U16(40) ]
30 },
31 BlockedDeviceData {
32 access_type: AccessType::Bit,
33 start_device: Device{device_type: DeviceType::M, address: 0},
34 data: &[ TypedData::Bool(true), TypedData::Bool(false), TypedData::Bool(true) ]
35 },
36 ];
37 client.block_write(&data).await.unwrap();
38
39 let device_blocks = [
40 DeviceBlock{ access_type: data[0].access_type, start_device: data[0].start_device, size: data[0].data.len()},
41 DeviceBlock{ access_type: data[1].access_type, start_device: data[1].start_device, size: data[1].data.len()},
42 DeviceBlock{ access_type: data[2].access_type, start_device: data[2].start_device, size: data[2].data.len()},
43 ];
44
45 let ret: Vec<DeviceData> = client.block_read(&device_blocks).await.unwrap();
46 println!("\nDevice & Bit access:");
47 for data in ret {
48 println!("{:?}", data);
49 }
50 println!();
51
52 client.close().await;
53}examples/random_access.rs (line 83)
16async fn main() {
17 let mut client = SLMPClient::new(SLMP_PROPS);
18 client.connect().await.unwrap();
19
20 // Word data
21 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 // Bit data
57 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}pub fn set_send_timeout(&mut self, dur: Duration)
pub fn set_recv_timeout(&mut self, dur: Duration)
Sourcepub async fn connect(&self) -> Result<()>
pub async fn connect(&self) -> Result<()>
Examples found in repository?
examples/bulk_access.rs (line 18)
16async fn main() {
17 let mut client = SLMPClient::new(SLMP_PROPS);
18 client.connect().await.unwrap();
19
20 // Word data
21 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 // Bit data
42 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}More examples
examples/block_access.rs (line 18)
16async fn main() {
17 let mut client = SLMPClient::new(SLMP_PROPS);
18 client.connect().await.unwrap();
19
20 let data= [
21 BlockedDeviceData {
22 access_type: AccessType::Word,
23 start_device: Device{device_type: DeviceType::D, address: 10},
24 data: &[ TypedData::U16(10), TypedData::U16(20) ]
25 },
26 BlockedDeviceData {
27 access_type: AccessType::Word,
28 start_device: Device{device_type: DeviceType::D, address: 20},
29 data: &[ TypedData::U16(30), TypedData::U16(40) ]
30 },
31 BlockedDeviceData {
32 access_type: AccessType::Bit,
33 start_device: Device{device_type: DeviceType::M, address: 0},
34 data: &[ TypedData::Bool(true), TypedData::Bool(false), TypedData::Bool(true) ]
35 },
36 ];
37 client.block_write(&data).await.unwrap();
38
39 let device_blocks = [
40 DeviceBlock{ access_type: data[0].access_type, start_device: data[0].start_device, size: data[0].data.len()},
41 DeviceBlock{ access_type: data[1].access_type, start_device: data[1].start_device, size: data[1].data.len()},
42 DeviceBlock{ access_type: data[2].access_type, start_device: data[2].start_device, size: data[2].data.len()},
43 ];
44
45 let ret: Vec<DeviceData> = client.block_read(&device_blocks).await.unwrap();
46 println!("\nDevice & Bit access:");
47 for data in ret {
48 println!("{:?}", data);
49 }
50 println!();
51
52 client.close().await;
53}examples/random_access.rs (line 18)
16async fn main() {
17 let mut client = SLMPClient::new(SLMP_PROPS);
18 client.connect().await.unwrap();
19
20 // Word data
21 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 // Bit data
57 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}Sourcepub async fn bulk_write<'a>(
&mut self,
start_device: Device,
data: &'a [TypedData],
) -> Result<()>
pub async fn bulk_write<'a>( &mut self, start_device: Device, data: &'a [TypedData], ) -> Result<()>
Examples found in repository?
examples/bulk_access.rs (line 33)
16async fn main() {
17 let mut client = SLMPClient::new(SLMP_PROPS);
18 client.connect().await.unwrap();
19
20 // Word data
21 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 // Bit data
42 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}Sourcepub async fn random_write<'a>(&mut self, data: &'a [DeviceData]) -> Result<()>
pub async fn random_write<'a>(&mut self, data: &'a [DeviceData]) -> Result<()>
Examples found in repository?
examples/random_access.rs (line 41)
16async fn main() {
17 let mut client = SLMPClient::new(SLMP_PROPS);
18 client.connect().await.unwrap();
19
20 // Word data
21 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 // Bit data
57 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}Sourcepub async fn block_write<'a>(
&mut self,
data: &'a [BlockedDeviceData<'a>],
) -> Result<()>
pub async fn block_write<'a>( &mut self, data: &'a [BlockedDeviceData<'a>], ) -> Result<()>
Examples found in repository?
examples/block_access.rs (line 37)
16async fn main() {
17 let mut client = SLMPClient::new(SLMP_PROPS);
18 client.connect().await.unwrap();
19
20 let data= [
21 BlockedDeviceData {
22 access_type: AccessType::Word,
23 start_device: Device{device_type: DeviceType::D, address: 10},
24 data: &[ TypedData::U16(10), TypedData::U16(20) ]
25 },
26 BlockedDeviceData {
27 access_type: AccessType::Word,
28 start_device: Device{device_type: DeviceType::D, address: 20},
29 data: &[ TypedData::U16(30), TypedData::U16(40) ]
30 },
31 BlockedDeviceData {
32 access_type: AccessType::Bit,
33 start_device: Device{device_type: DeviceType::M, address: 0},
34 data: &[ TypedData::Bool(true), TypedData::Bool(false), TypedData::Bool(true) ]
35 },
36 ];
37 client.block_write(&data).await.unwrap();
38
39 let device_blocks = [
40 DeviceBlock{ access_type: data[0].access_type, start_device: data[0].start_device, size: data[0].data.len()},
41 DeviceBlock{ access_type: data[1].access_type, start_device: data[1].start_device, size: data[1].data.len()},
42 DeviceBlock{ access_type: data[2].access_type, start_device: data[2].start_device, size: data[2].data.len()},
43 ];
44
45 let ret: Vec<DeviceData> = client.block_read(&device_blocks).await.unwrap();
46 println!("\nDevice & Bit access:");
47 for data in ret {
48 println!("{:?}", data);
49 }
50 println!();
51
52 client.close().await;
53}Sourcepub async fn bulk_read(
&mut self,
start_device: Device,
device_num: usize,
data_type: DataType,
) -> Result<Vec<DeviceData>>
pub async fn bulk_read( &mut self, start_device: Device, device_num: usize, data_type: DataType, ) -> Result<Vec<DeviceData>>
Examples found in repository?
examples/bulk_access.rs (line 35)
16async fn main() {
17 let mut client = SLMPClient::new(SLMP_PROPS);
18 client.connect().await.unwrap();
19
20 // Word data
21 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 // Bit data
42 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}More examples
examples/random_access.rs (line 76)
16async fn main() {
17 let mut client = SLMPClient::new(SLMP_PROPS);
18 client.connect().await.unwrap();
19
20 // Word data
21 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 // Bit data
57 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}Sourcepub async fn random_read(
&mut self,
devices: &[TypedDevice],
) -> Result<Vec<DeviceData>>
pub async fn random_read( &mut self, devices: &[TypedDevice], ) -> Result<Vec<DeviceData>>
Examples found in repository?
examples/random_access.rs (line 50)
16async fn main() {
17 let mut client = SLMPClient::new(SLMP_PROPS);
18 client.connect().await.unwrap();
19
20 // Word data
21 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 // Bit data
57 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}Sourcepub async fn block_read(
&mut self,
device_blocks: &[DeviceBlock],
) -> Result<Vec<DeviceData>>
pub async fn block_read( &mut self, device_blocks: &[DeviceBlock], ) -> Result<Vec<DeviceData>>
Examples found in repository?
examples/block_access.rs (line 45)
16async fn main() {
17 let mut client = SLMPClient::new(SLMP_PROPS);
18 client.connect().await.unwrap();
19
20 let data= [
21 BlockedDeviceData {
22 access_type: AccessType::Word,
23 start_device: Device{device_type: DeviceType::D, address: 10},
24 data: &[ TypedData::U16(10), TypedData::U16(20) ]
25 },
26 BlockedDeviceData {
27 access_type: AccessType::Word,
28 start_device: Device{device_type: DeviceType::D, address: 20},
29 data: &[ TypedData::U16(30), TypedData::U16(40) ]
30 },
31 BlockedDeviceData {
32 access_type: AccessType::Bit,
33 start_device: Device{device_type: DeviceType::M, address: 0},
34 data: &[ TypedData::Bool(true), TypedData::Bool(false), TypedData::Bool(true) ]
35 },
36 ];
37 client.block_write(&data).await.unwrap();
38
39 let device_blocks = [
40 DeviceBlock{ access_type: data[0].access_type, start_device: data[0].start_device, size: data[0].data.len()},
41 DeviceBlock{ access_type: data[1].access_type, start_device: data[1].start_device, size: data[1].data.len()},
42 DeviceBlock{ access_type: data[2].access_type, start_device: data[2].start_device, size: data[2].data.len()},
43 ];
44
45 let ret: Vec<DeviceData> = client.block_read(&device_blocks).await.unwrap();
46 println!("\nDevice & Bit access:");
47 for data in ret {
48 println!("{:?}", data);
49 }
50 println!();
51
52 client.close().await;
53}Trait Implementations§
Source§impl Clone for SLMPClient
impl Clone for SLMPClient
Source§fn clone(&self) -> SLMPClient
fn clone(&self) -> SLMPClient
Returns a duplicate of the value. Read more
1.0.0§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for SLMPClient
impl !RefUnwindSafe for SLMPClient
impl Send for SLMPClient
impl Sync for SLMPClient
impl Unpin for SLMPClient
impl !UnwindSafe for SLMPClient
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
🔬This is a nightly-only experimental API. (
clone_to_uninit)