pub struct SLMPConnectionManager {
pub connections: Arc<Mutex<HashMap<SocketAddr, Arc<SLMPWorker>>>>,
}Fields§
§connections: Arc<Mutex<HashMap<SocketAddr, Arc<SLMPWorker>>>>Implementations§
Source§impl SLMPConnectionManager
impl SLMPConnectionManager
Sourcepub fn new() -> Self
pub fn new() -> Self
Examples found in repository?
examples/cyclic_read.rs (line 19)
5async fn main() -> Result<(), Box<dyn std::error::Error>> {
6
7 let connection_props: SLMP4EConnectionProps = SLMP4EConnectionProps {
8 ip: String::from("192.168.3.10"),
9 port: 5007,
10 cpu: CPU::R,
11 serial_id: 0x0001,
12 network_id: 0x00,
13 pc_id: 0xff,
14 io_id: 0x03ff,
15 area_id: 0x00,
16 cpu_timer: 0x0010,
17 };
18
19 let manager = SLMPConnectionManager::new();
20
21 let cyclic_task = async |data| {
22 for x in data {
23 println!("{:?}", x);
24 }
25 println!();
26 Ok(())
27 };
28
29 manager.connect(&connection_props, cyclic_task).await?;
30
31 let target_devices = [
32 MonitorDevice {
33 interval: PollingInterval::Fast,
34 device: TypedDevice {
35 device: Device { device_type: DeviceType::D, address: 4001 },
36 data_type: DataType::U16
37 },
38 },
39 MonitorDevice {
40 interval: PollingInterval::Slow,
41 device: TypedDevice {
42 device: Device { device_type: DeviceType::D, address: 4005 },
43 data_type: DataType::U16
44 },
45 },
46 MonitorDevice {
47 interval: PollingInterval::Meduim,
48 device: TypedDevice {
49 device: Device { device_type: DeviceType::D, address: 4006 },
50 data_type: DataType::U16
51 },
52 },
53 MonitorDevice {
54 interval: PollingInterval::Meduim,
55 device: TypedDevice {
56 device: Device { device_type: DeviceType::D, address: 4007 },
57 data_type: DataType::U16
58 },
59 },
60 ];
61 manager.register_monitor_targets(&connection_props, &target_devices).await?;
62
63 tokio::time::sleep(tokio::time::Duration::from_secs(3)).await;
64
65 manager.disconnect(&connection_props).await?;
66
67 Ok(())
68}Sourcepub async fn connect<'a, T, F, Fut>(
&self,
connection_props: &'a SLMP4EConnectionProps,
cyclic_task: F,
) -> Result<()>
pub async fn connect<'a, T, F, Fut>( &self, connection_props: &'a SLMP4EConnectionProps, cyclic_task: F, ) -> Result<()>
Examples found in repository?
examples/cyclic_read.rs (line 29)
5async fn main() -> Result<(), Box<dyn std::error::Error>> {
6
7 let connection_props: SLMP4EConnectionProps = SLMP4EConnectionProps {
8 ip: String::from("192.168.3.10"),
9 port: 5007,
10 cpu: CPU::R,
11 serial_id: 0x0001,
12 network_id: 0x00,
13 pc_id: 0xff,
14 io_id: 0x03ff,
15 area_id: 0x00,
16 cpu_timer: 0x0010,
17 };
18
19 let manager = SLMPConnectionManager::new();
20
21 let cyclic_task = async |data| {
22 for x in data {
23 println!("{:?}", x);
24 }
25 println!();
26 Ok(())
27 };
28
29 manager.connect(&connection_props, cyclic_task).await?;
30
31 let target_devices = [
32 MonitorDevice {
33 interval: PollingInterval::Fast,
34 device: TypedDevice {
35 device: Device { device_type: DeviceType::D, address: 4001 },
36 data_type: DataType::U16
37 },
38 },
39 MonitorDevice {
40 interval: PollingInterval::Slow,
41 device: TypedDevice {
42 device: Device { device_type: DeviceType::D, address: 4005 },
43 data_type: DataType::U16
44 },
45 },
46 MonitorDevice {
47 interval: PollingInterval::Meduim,
48 device: TypedDevice {
49 device: Device { device_type: DeviceType::D, address: 4006 },
50 data_type: DataType::U16
51 },
52 },
53 MonitorDevice {
54 interval: PollingInterval::Meduim,
55 device: TypedDevice {
56 device: Device { device_type: DeviceType::D, address: 4007 },
57 data_type: DataType::U16
58 },
59 },
60 ];
61 manager.register_monitor_targets(&connection_props, &target_devices).await?;
62
63 tokio::time::sleep(tokio::time::Duration::from_secs(3)).await;
64
65 manager.disconnect(&connection_props).await?;
66
67 Ok(())
68}Sourcepub async fn disconnect<'a>(
&self,
connection_props: &'a SLMP4EConnectionProps,
) -> Result<bool>
pub async fn disconnect<'a>( &self, connection_props: &'a SLMP4EConnectionProps, ) -> Result<bool>
Examples found in repository?
examples/cyclic_read.rs (line 65)
5async fn main() -> Result<(), Box<dyn std::error::Error>> {
6
7 let connection_props: SLMP4EConnectionProps = SLMP4EConnectionProps {
8 ip: String::from("192.168.3.10"),
9 port: 5007,
10 cpu: CPU::R,
11 serial_id: 0x0001,
12 network_id: 0x00,
13 pc_id: 0xff,
14 io_id: 0x03ff,
15 area_id: 0x00,
16 cpu_timer: 0x0010,
17 };
18
19 let manager = SLMPConnectionManager::new();
20
21 let cyclic_task = async |data| {
22 for x in data {
23 println!("{:?}", x);
24 }
25 println!();
26 Ok(())
27 };
28
29 manager.connect(&connection_props, cyclic_task).await?;
30
31 let target_devices = [
32 MonitorDevice {
33 interval: PollingInterval::Fast,
34 device: TypedDevice {
35 device: Device { device_type: DeviceType::D, address: 4001 },
36 data_type: DataType::U16
37 },
38 },
39 MonitorDevice {
40 interval: PollingInterval::Slow,
41 device: TypedDevice {
42 device: Device { device_type: DeviceType::D, address: 4005 },
43 data_type: DataType::U16
44 },
45 },
46 MonitorDevice {
47 interval: PollingInterval::Meduim,
48 device: TypedDevice {
49 device: Device { device_type: DeviceType::D, address: 4006 },
50 data_type: DataType::U16
51 },
52 },
53 MonitorDevice {
54 interval: PollingInterval::Meduim,
55 device: TypedDevice {
56 device: Device { device_type: DeviceType::D, address: 4007 },
57 data_type: DataType::U16
58 },
59 },
60 ];
61 manager.register_monitor_targets(&connection_props, &target_devices).await?;
62
63 tokio::time::sleep(tokio::time::Duration::from_secs(3)).await;
64
65 manager.disconnect(&connection_props).await?;
66
67 Ok(())
68}pub async fn clear(&self)
Sourcepub async fn register_monitor_targets<'a>(
&self,
connection_props: &'a SLMP4EConnectionProps,
targets: &'a [MonitorDevice],
) -> Result<()>
pub async fn register_monitor_targets<'a>( &self, connection_props: &'a SLMP4EConnectionProps, targets: &'a [MonitorDevice], ) -> Result<()>
Examples found in repository?
examples/cyclic_read.rs (line 61)
5async fn main() -> Result<(), Box<dyn std::error::Error>> {
6
7 let connection_props: SLMP4EConnectionProps = SLMP4EConnectionProps {
8 ip: String::from("192.168.3.10"),
9 port: 5007,
10 cpu: CPU::R,
11 serial_id: 0x0001,
12 network_id: 0x00,
13 pc_id: 0xff,
14 io_id: 0x03ff,
15 area_id: 0x00,
16 cpu_timer: 0x0010,
17 };
18
19 let manager = SLMPConnectionManager::new();
20
21 let cyclic_task = async |data| {
22 for x in data {
23 println!("{:?}", x);
24 }
25 println!();
26 Ok(())
27 };
28
29 manager.connect(&connection_props, cyclic_task).await?;
30
31 let target_devices = [
32 MonitorDevice {
33 interval: PollingInterval::Fast,
34 device: TypedDevice {
35 device: Device { device_type: DeviceType::D, address: 4001 },
36 data_type: DataType::U16
37 },
38 },
39 MonitorDevice {
40 interval: PollingInterval::Slow,
41 device: TypedDevice {
42 device: Device { device_type: DeviceType::D, address: 4005 },
43 data_type: DataType::U16
44 },
45 },
46 MonitorDevice {
47 interval: PollingInterval::Meduim,
48 device: TypedDevice {
49 device: Device { device_type: DeviceType::D, address: 4006 },
50 data_type: DataType::U16
51 },
52 },
53 MonitorDevice {
54 interval: PollingInterval::Meduim,
55 device: TypedDevice {
56 device: Device { device_type: DeviceType::D, address: 4007 },
57 data_type: DataType::U16
58 },
59 },
60 ];
61 manager.register_monitor_targets(&connection_props, &target_devices).await?;
62
63 tokio::time::sleep(tokio::time::Duration::from_secs(3)).await;
64
65 manager.disconnect(&connection_props).await?;
66
67 Ok(())
68}