SLMPConnectionManager

Struct SLMPConnectionManager 

Source
pub struct SLMPConnectionManager {
    pub connections: Arc<Mutex<HashMap<SocketAddr, Arc<SLMPWorker>>>>,
}

Fields§

§connections: Arc<Mutex<HashMap<SocketAddr, Arc<SLMPWorker>>>>

Implementations§

Source§

impl SLMPConnectionManager

Source

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}
Source

pub async fn connect<T, F, Fut>( &self, connection_props: SLMP4EConnectionProps, cyclic_task: F, ) -> Result<()>
where F: Fn(Vec<PLCData>) -> Fut + Send + 'static, Fut: Future<Output = Result<T>> + Send,

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}
Source

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}
Source

pub async fn clear(&self)

Source

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}
Source

pub async fn get_connections_with_elapsed_time( &self, ) -> HashMap<SocketAddr, Duration>

Source

pub async fn operate_worker<T, F, Fut>( &self, connection_props: SLMP4EConnectionProps, task: F, ) -> Result<T>
where F: FnOnce(Arc<Mutex<SLMPClient>>) -> Fut, Fut: Future<Output = Result<T>>,

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> 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, 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.