SLMPClient

Struct SLMPClient 

Source
pub struct SLMPClient { /* private fields */ }

Implementations§

Source§

impl SLMPClient

Source

pub fn new(connection_props: SLMP4EConnectionProps) -> Self

Examples found in repository?
examples/bulk_access.rs (line 18)
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    // Word data
22    let start_device: Device = Device{device_type: DeviceType::D, address: 4000};
23    let data = [
24        TypedData::U16(10),
25        TypedData::U16(20),
26        TypedData::U16(30),
27        TypedData::U16(40),
28        TypedData::U16(50),
29        TypedData::U16(60),
30        TypedData::U16(70),
31        TypedData::U16(80),
32    ];
33
34    client.bulk_write(start_device, &data).await.unwrap();
35
36    let ret: Vec<DeviceData> = client.bulk_read(start_device, data.len(), DataType::U16).await.unwrap();
37    println!("\nDevice access:");
38    for x in ret {
39        println!("{:?}", x);
40    }
41
42    // Bit data
43    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}
More examples
Hide additional examples
examples/block_access.rs (line 18)
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 data= [
22        BlockedDeviceData { 
23            access_type: AccessType::Word,
24            start_device: Device{device_type: DeviceType::D, address: 10},
25            data: &[ TypedData::U16(10), TypedData::U16(20) ]
26        },
27        BlockedDeviceData {
28            access_type: AccessType::Word,
29            start_device: Device{device_type: DeviceType::D, address: 20},
30            data: &[ TypedData::U16(30), TypedData::U16(40) ]
31        },
32        BlockedDeviceData {
33            access_type: AccessType::Bit,
34            start_device: Device{device_type: DeviceType::M, address: 0},
35            data: &[ TypedData::Bool(true), TypedData::Bool(false), TypedData::Bool(true) ]
36        },
37    ];
38    client.block_write(&data).await.unwrap();
39
40    let device_blocks = [
41        DeviceBlock{ access_type: data[0].access_type, start_device: data[0].start_device, size: data[0].data.len()},
42        DeviceBlock{ access_type: data[1].access_type, start_device: data[1].start_device, size: data[1].data.len()},
43        DeviceBlock{ access_type: data[2].access_type, start_device: data[2].start_device, size: data[2].data.len()},
44    ];
45
46    let ret: Vec<DeviceData> = client.block_read(&device_blocks).await.unwrap();
47    println!("\nDevice & Bit access:");
48    for data in ret {
49        println!("{:?}", data);
50    }
51    println!();
52
53    client.close().await;
54}
examples/random_access.rs (line 18)
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    // Word data
22    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    // Bit data
58    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}
Source

pub async fn close(&self)

Examples found in repository?
examples/bulk_access.rs (line 60)
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    // Word data
22    let start_device: Device = Device{device_type: DeviceType::D, address: 4000};
23    let data = [
24        TypedData::U16(10),
25        TypedData::U16(20),
26        TypedData::U16(30),
27        TypedData::U16(40),
28        TypedData::U16(50),
29        TypedData::U16(60),
30        TypedData::U16(70),
31        TypedData::U16(80),
32    ];
33
34    client.bulk_write(start_device, &data).await.unwrap();
35
36    let ret: Vec<DeviceData> = client.bulk_read(start_device, data.len(), DataType::U16).await.unwrap();
37    println!("\nDevice access:");
38    for x in ret {
39        println!("{:?}", x);
40    }
41
42    // Bit data
43    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}
More examples
Hide additional examples
examples/block_access.rs (line 53)
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 data= [
22        BlockedDeviceData { 
23            access_type: AccessType::Word,
24            start_device: Device{device_type: DeviceType::D, address: 10},
25            data: &[ TypedData::U16(10), TypedData::U16(20) ]
26        },
27        BlockedDeviceData {
28            access_type: AccessType::Word,
29            start_device: Device{device_type: DeviceType::D, address: 20},
30            data: &[ TypedData::U16(30), TypedData::U16(40) ]
31        },
32        BlockedDeviceData {
33            access_type: AccessType::Bit,
34            start_device: Device{device_type: DeviceType::M, address: 0},
35            data: &[ TypedData::Bool(true), TypedData::Bool(false), TypedData::Bool(true) ]
36        },
37    ];
38    client.block_write(&data).await.unwrap();
39
40    let device_blocks = [
41        DeviceBlock{ access_type: data[0].access_type, start_device: data[0].start_device, size: data[0].data.len()},
42        DeviceBlock{ access_type: data[1].access_type, start_device: data[1].start_device, size: data[1].data.len()},
43        DeviceBlock{ access_type: data[2].access_type, start_device: data[2].start_device, size: data[2].data.len()},
44    ];
45
46    let ret: Vec<DeviceData> = client.block_read(&device_blocks).await.unwrap();
47    println!("\nDevice & Bit access:");
48    for data in ret {
49        println!("{:?}", data);
50    }
51    println!();
52
53    client.close().await;
54}
examples/random_access.rs (line 84)
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    // Word data
22    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    // Bit data
58    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}
Source

pub fn set_send_timeout(&mut self, dur: Duration)

Source

pub fn set_recv_timeout(&mut self, dur: Duration)

Source

pub async fn connect(&self) -> Result<()>

Examples found in repository?
examples/bulk_access.rs (line 19)
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    // Word data
22    let start_device: Device = Device{device_type: DeviceType::D, address: 4000};
23    let data = [
24        TypedData::U16(10),
25        TypedData::U16(20),
26        TypedData::U16(30),
27        TypedData::U16(40),
28        TypedData::U16(50),
29        TypedData::U16(60),
30        TypedData::U16(70),
31        TypedData::U16(80),
32    ];
33
34    client.bulk_write(start_device, &data).await.unwrap();
35
36    let ret: Vec<DeviceData> = client.bulk_read(start_device, data.len(), DataType::U16).await.unwrap();
37    println!("\nDevice access:");
38    for x in ret {
39        println!("{:?}", x);
40    }
41
42    // Bit data
43    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}
More examples
Hide additional examples
examples/block_access.rs (line 19)
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 data= [
22        BlockedDeviceData { 
23            access_type: AccessType::Word,
24            start_device: Device{device_type: DeviceType::D, address: 10},
25            data: &[ TypedData::U16(10), TypedData::U16(20) ]
26        },
27        BlockedDeviceData {
28            access_type: AccessType::Word,
29            start_device: Device{device_type: DeviceType::D, address: 20},
30            data: &[ TypedData::U16(30), TypedData::U16(40) ]
31        },
32        BlockedDeviceData {
33            access_type: AccessType::Bit,
34            start_device: Device{device_type: DeviceType::M, address: 0},
35            data: &[ TypedData::Bool(true), TypedData::Bool(false), TypedData::Bool(true) ]
36        },
37    ];
38    client.block_write(&data).await.unwrap();
39
40    let device_blocks = [
41        DeviceBlock{ access_type: data[0].access_type, start_device: data[0].start_device, size: data[0].data.len()},
42        DeviceBlock{ access_type: data[1].access_type, start_device: data[1].start_device, size: data[1].data.len()},
43        DeviceBlock{ access_type: data[2].access_type, start_device: data[2].start_device, size: data[2].data.len()},
44    ];
45
46    let ret: Vec<DeviceData> = client.block_read(&device_blocks).await.unwrap();
47    println!("\nDevice & Bit access:");
48    for data in ret {
49        println!("{:?}", data);
50    }
51    println!();
52
53    client.close().await;
54}
examples/random_access.rs (line 19)
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    // Word data
22    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    // Bit data
58    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}
Source

pub async fn bulk_write<'a>( &mut self, start_device: Device, data: &'a [TypedData], ) -> Result<()>

Examples found in repository?
examples/bulk_access.rs (line 34)
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    // Word data
22    let start_device: Device = Device{device_type: DeviceType::D, address: 4000};
23    let data = [
24        TypedData::U16(10),
25        TypedData::U16(20),
26        TypedData::U16(30),
27        TypedData::U16(40),
28        TypedData::U16(50),
29        TypedData::U16(60),
30        TypedData::U16(70),
31        TypedData::U16(80),
32    ];
33
34    client.bulk_write(start_device, &data).await.unwrap();
35
36    let ret: Vec<DeviceData> = client.bulk_read(start_device, data.len(), DataType::U16).await.unwrap();
37    println!("\nDevice access:");
38    for x in ret {
39        println!("{:?}", x);
40    }
41
42    // Bit data
43    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}
Source

pub async fn random_write<'a>(&mut self, data: &'a [DeviceData]) -> Result<()>

Examples found in repository?
examples/random_access.rs (line 42)
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    // Word data
22    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    // Bit data
58    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}
Source

pub async fn block_write<'a>( &mut self, data: &'a [BlockedDeviceData<'a>], ) -> Result<()>

Examples found in repository?
examples/block_access.rs (line 38)
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 data= [
22        BlockedDeviceData { 
23            access_type: AccessType::Word,
24            start_device: Device{device_type: DeviceType::D, address: 10},
25            data: &[ TypedData::U16(10), TypedData::U16(20) ]
26        },
27        BlockedDeviceData {
28            access_type: AccessType::Word,
29            start_device: Device{device_type: DeviceType::D, address: 20},
30            data: &[ TypedData::U16(30), TypedData::U16(40) ]
31        },
32        BlockedDeviceData {
33            access_type: AccessType::Bit,
34            start_device: Device{device_type: DeviceType::M, address: 0},
35            data: &[ TypedData::Bool(true), TypedData::Bool(false), TypedData::Bool(true) ]
36        },
37    ];
38    client.block_write(&data).await.unwrap();
39
40    let device_blocks = [
41        DeviceBlock{ access_type: data[0].access_type, start_device: data[0].start_device, size: data[0].data.len()},
42        DeviceBlock{ access_type: data[1].access_type, start_device: data[1].start_device, size: data[1].data.len()},
43        DeviceBlock{ access_type: data[2].access_type, start_device: data[2].start_device, size: data[2].data.len()},
44    ];
45
46    let ret: Vec<DeviceData> = client.block_read(&device_blocks).await.unwrap();
47    println!("\nDevice & Bit access:");
48    for data in ret {
49        println!("{:?}", data);
50    }
51    println!();
52
53    client.close().await;
54}
Source

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 36)
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    // Word data
22    let start_device: Device = Device{device_type: DeviceType::D, address: 4000};
23    let data = [
24        TypedData::U16(10),
25        TypedData::U16(20),
26        TypedData::U16(30),
27        TypedData::U16(40),
28        TypedData::U16(50),
29        TypedData::U16(60),
30        TypedData::U16(70),
31        TypedData::U16(80),
32    ];
33
34    client.bulk_write(start_device, &data).await.unwrap();
35
36    let ret: Vec<DeviceData> = client.bulk_read(start_device, data.len(), DataType::U16).await.unwrap();
37    println!("\nDevice access:");
38    for x in ret {
39        println!("{:?}", x);
40    }
41
42    // Bit data
43    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}
More examples
Hide additional examples
examples/random_access.rs (line 77)
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    // Word data
22    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    // Bit data
58    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}
Source

pub async fn random_read( &mut self, devices: &[TypedDevice], ) -> Result<Vec<DeviceData>>

Examples found in repository?
examples/random_access.rs (line 51)
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    // Word data
22    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    // Bit data
58    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}
Source

pub async fn block_read( &mut self, device_blocks: &[DeviceBlock], ) -> Result<Vec<DeviceData>>

Examples found in repository?
examples/block_access.rs (line 46)
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 data= [
22        BlockedDeviceData { 
23            access_type: AccessType::Word,
24            start_device: Device{device_type: DeviceType::D, address: 10},
25            data: &[ TypedData::U16(10), TypedData::U16(20) ]
26        },
27        BlockedDeviceData {
28            access_type: AccessType::Word,
29            start_device: Device{device_type: DeviceType::D, address: 20},
30            data: &[ TypedData::U16(30), TypedData::U16(40) ]
31        },
32        BlockedDeviceData {
33            access_type: AccessType::Bit,
34            start_device: Device{device_type: DeviceType::M, address: 0},
35            data: &[ TypedData::Bool(true), TypedData::Bool(false), TypedData::Bool(true) ]
36        },
37    ];
38    client.block_write(&data).await.unwrap();
39
40    let device_blocks = [
41        DeviceBlock{ access_type: data[0].access_type, start_device: data[0].start_device, size: data[0].data.len()},
42        DeviceBlock{ access_type: data[1].access_type, start_device: data[1].start_device, size: data[1].data.len()},
43        DeviceBlock{ access_type: data[2].access_type, start_device: data[2].start_device, size: data[2].data.len()},
44    ];
45
46    let ret: Vec<DeviceData> = client.block_read(&device_blocks).await.unwrap();
47    println!("\nDevice & Bit access:");
48    for data in ret {
49        println!("{:?}", data);
50    }
51    println!();
52
53    client.close().await;
54}

Trait Implementations§

Source§

impl Clone for SLMPClient

Source§

fn clone(&self) -> SLMPClient

Returns a duplicate of the value. Read more
1.0.0§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> CloneToUninit for T
where T: Clone,

§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.