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

pub async fn connect<'a, T, F, Fut>( &self, connection_props: &'a 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 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}
Source

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

pub async fn clear(&self)

Source

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

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

Source

pub async fn operate_worker<'a, T, F, Fut>( &self, connection_props: &'a 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.