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 18)
16async fn main() -> Result<(), Box<dyn std::error::Error>> {
17
18 let manager = SLMPConnectionManager::new();
19
20 let cyclic_task = async |data| {
21 for x in data {
22 println!("{:?}", x);
23 }
24 println!();
25 Ok(())
26 };
27
28 manager.connect(SLMP_PROPS, cyclic_task).await?;
29
30 let target_devices = [
31 MonitorDevice {
32 inverval: PollingInterval::Fast,
33 device: TypedDevice {
34 device: Device { device_type: DeviceType::D, address: 4001 },
35 data_type: DataType::U16
36 },
37 },
38 MonitorDevice {
39 inverval: PollingInterval::Slow,
40 device: TypedDevice {
41 device: Device { device_type: DeviceType::D, address: 4005 },
42 data_type: DataType::U16
43 },
44 },
45 MonitorDevice {
46 inverval: PollingInterval::Meduim,
47 device: TypedDevice {
48 device: Device { device_type: DeviceType::D, address: 4006 },
49 data_type: DataType::U16
50 },
51 },
52 MonitorDevice {
53 inverval: PollingInterval::Meduim,
54 device: TypedDevice {
55 device: Device { device_type: DeviceType::D, address: 4007 },
56 data_type: DataType::U16
57 },
58 },
59 ];
60 manager.register_monitor_targets(SLMP_PROPS, &target_devices).await?;
61
62 tokio::time::sleep(tokio::time::Duration::from_secs(3)).await;
63
64 manager.disconnect(SLMP_PROPS).await?;
65
66 Ok(())
67}Sourcepub async fn connect<T, F, Fut>(
&self,
connection_props: SLMP4EConnectionProps,
cyclic_task: F,
) -> Result<()>
pub async fn connect<T, F, Fut>( &self, connection_props: SLMP4EConnectionProps, cyclic_task: F, ) -> Result<()>
Examples found in repository?
examples/cyclic_read.rs (line 28)
16async fn main() -> Result<(), Box<dyn std::error::Error>> {
17
18 let manager = SLMPConnectionManager::new();
19
20 let cyclic_task = async |data| {
21 for x in data {
22 println!("{:?}", x);
23 }
24 println!();
25 Ok(())
26 };
27
28 manager.connect(SLMP_PROPS, cyclic_task).await?;
29
30 let target_devices = [
31 MonitorDevice {
32 inverval: PollingInterval::Fast,
33 device: TypedDevice {
34 device: Device { device_type: DeviceType::D, address: 4001 },
35 data_type: DataType::U16
36 },
37 },
38 MonitorDevice {
39 inverval: PollingInterval::Slow,
40 device: TypedDevice {
41 device: Device { device_type: DeviceType::D, address: 4005 },
42 data_type: DataType::U16
43 },
44 },
45 MonitorDevice {
46 inverval: PollingInterval::Meduim,
47 device: TypedDevice {
48 device: Device { device_type: DeviceType::D, address: 4006 },
49 data_type: DataType::U16
50 },
51 },
52 MonitorDevice {
53 inverval: PollingInterval::Meduim,
54 device: TypedDevice {
55 device: Device { device_type: DeviceType::D, address: 4007 },
56 data_type: DataType::U16
57 },
58 },
59 ];
60 manager.register_monitor_targets(SLMP_PROPS, &target_devices).await?;
61
62 tokio::time::sleep(tokio::time::Duration::from_secs(3)).await;
63
64 manager.disconnect(SLMP_PROPS).await?;
65
66 Ok(())
67}Sourcepub async fn disconnect(
&self,
connection_props: SLMP4EConnectionProps,
) -> Result<()>
pub async fn disconnect( &self, connection_props: SLMP4EConnectionProps, ) -> Result<()>
Examples found in repository?
examples/cyclic_read.rs (line 64)
16async fn main() -> Result<(), Box<dyn std::error::Error>> {
17
18 let manager = SLMPConnectionManager::new();
19
20 let cyclic_task = async |data| {
21 for x in data {
22 println!("{:?}", x);
23 }
24 println!();
25 Ok(())
26 };
27
28 manager.connect(SLMP_PROPS, cyclic_task).await?;
29
30 let target_devices = [
31 MonitorDevice {
32 inverval: PollingInterval::Fast,
33 device: TypedDevice {
34 device: Device { device_type: DeviceType::D, address: 4001 },
35 data_type: DataType::U16
36 },
37 },
38 MonitorDevice {
39 inverval: PollingInterval::Slow,
40 device: TypedDevice {
41 device: Device { device_type: DeviceType::D, address: 4005 },
42 data_type: DataType::U16
43 },
44 },
45 MonitorDevice {
46 inverval: PollingInterval::Meduim,
47 device: TypedDevice {
48 device: Device { device_type: DeviceType::D, address: 4006 },
49 data_type: DataType::U16
50 },
51 },
52 MonitorDevice {
53 inverval: PollingInterval::Meduim,
54 device: TypedDevice {
55 device: Device { device_type: DeviceType::D, address: 4007 },
56 data_type: DataType::U16
57 },
58 },
59 ];
60 manager.register_monitor_targets(SLMP_PROPS, &target_devices).await?;
61
62 tokio::time::sleep(tokio::time::Duration::from_secs(3)).await;
63
64 manager.disconnect(SLMP_PROPS).await?;
65
66 Ok(())
67}pub async fn clear(&self)
Sourcepub async fn register_monitor_targets<'a>(
&self,
connection_props: SLMP4EConnectionProps,
targets: &'a [MonitorDevice],
) -> Result<()>
pub async fn register_monitor_targets<'a>( &self, connection_props: SLMP4EConnectionProps, targets: &'a [MonitorDevice], ) -> Result<()>
Examples found in repository?
examples/cyclic_read.rs (line 60)
16async fn main() -> Result<(), Box<dyn std::error::Error>> {
17
18 let manager = SLMPConnectionManager::new();
19
20 let cyclic_task = async |data| {
21 for x in data {
22 println!("{:?}", x);
23 }
24 println!();
25 Ok(())
26 };
27
28 manager.connect(SLMP_PROPS, cyclic_task).await?;
29
30 let target_devices = [
31 MonitorDevice {
32 inverval: PollingInterval::Fast,
33 device: TypedDevice {
34 device: Device { device_type: DeviceType::D, address: 4001 },
35 data_type: DataType::U16
36 },
37 },
38 MonitorDevice {
39 inverval: PollingInterval::Slow,
40 device: TypedDevice {
41 device: Device { device_type: DeviceType::D, address: 4005 },
42 data_type: DataType::U16
43 },
44 },
45 MonitorDevice {
46 inverval: PollingInterval::Meduim,
47 device: TypedDevice {
48 device: Device { device_type: DeviceType::D, address: 4006 },
49 data_type: DataType::U16
50 },
51 },
52 MonitorDevice {
53 inverval: PollingInterval::Meduim,
54 device: TypedDevice {
55 device: Device { device_type: DeviceType::D, address: 4007 },
56 data_type: DataType::U16
57 },
58 },
59 ];
60 manager.register_monitor_targets(SLMP_PROPS, &target_devices).await?;
61
62 tokio::time::sleep(tokio::time::Duration::from_secs(3)).await;
63
64 manager.disconnect(SLMP_PROPS).await?;
65
66 Ok(())
67}