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 cycle_ms: u64 = 100;
22    let cyclic_task = async |data| {
23        for x in data {
24            println!("{:?}", x);
25        }
26        println!();
27        Ok(())
28    };
29
30    manager.connect(&connection_props, cyclic_task, cycle_ms).await?;
31
32    let target_devices = [
33        MonitorRequest {
34            connection_props: &connection_props,
35            monitor_device: TypedDevice {
36                device: Device { device_type: DeviceType::D, address: 4001 },
37                data_type: DataType::U16
38            }
39        },
40        MonitorRequest {
41            connection_props: &connection_props,
42            monitor_device: TypedDevice {
43                device: Device { device_type: DeviceType::D, address: 4002 },
44                data_type: DataType::U16
45            }
46        },
47        MonitorRequest {
48            connection_props: &connection_props,
49            monitor_device: TypedDevice {
50                device: Device { device_type: DeviceType::D, address: 4003 },
51                data_type: DataType::U16
52            }
53        },
54    ];
55    manager.register_monitor_targets(&target_devices).await?;
56
57    tokio::time::sleep(tokio::time::Duration::from_secs(3)).await;
58
59    manager.disconnect(&connection_props).await?;
60
61    Ok(())
62}
Source

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

Examples found in repository?
examples/cyclic_read.rs (line 30)
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 cycle_ms: u64 = 100;
22    let cyclic_task = async |data| {
23        for x in data {
24            println!("{:?}", x);
25        }
26        println!();
27        Ok(())
28    };
29
30    manager.connect(&connection_props, cyclic_task, cycle_ms).await?;
31
32    let target_devices = [
33        MonitorRequest {
34            connection_props: &connection_props,
35            monitor_device: TypedDevice {
36                device: Device { device_type: DeviceType::D, address: 4001 },
37                data_type: DataType::U16
38            }
39        },
40        MonitorRequest {
41            connection_props: &connection_props,
42            monitor_device: TypedDevice {
43                device: Device { device_type: DeviceType::D, address: 4002 },
44                data_type: DataType::U16
45            }
46        },
47        MonitorRequest {
48            connection_props: &connection_props,
49            monitor_device: TypedDevice {
50                device: Device { device_type: DeviceType::D, address: 4003 },
51                data_type: DataType::U16
52            }
53        },
54    ];
55    manager.register_monitor_targets(&target_devices).await?;
56
57    tokio::time::sleep(tokio::time::Duration::from_secs(3)).await;
58
59    manager.disconnect(&connection_props).await?;
60
61    Ok(())
62}
Source

pub async fn disconnect<'a>( &self, connection_props: &'a SLMP4EConnectionProps, ) -> Result<bool>

Examples found in repository?
examples/cyclic_read.rs (line 59)
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 cycle_ms: u64 = 100;
22    let cyclic_task = async |data| {
23        for x in data {
24            println!("{:?}", x);
25        }
26        println!();
27        Ok(())
28    };
29
30    manager.connect(&connection_props, cyclic_task, cycle_ms).await?;
31
32    let target_devices = [
33        MonitorRequest {
34            connection_props: &connection_props,
35            monitor_device: TypedDevice {
36                device: Device { device_type: DeviceType::D, address: 4001 },
37                data_type: DataType::U16
38            }
39        },
40        MonitorRequest {
41            connection_props: &connection_props,
42            monitor_device: TypedDevice {
43                device: Device { device_type: DeviceType::D, address: 4002 },
44                data_type: DataType::U16
45            }
46        },
47        MonitorRequest {
48            connection_props: &connection_props,
49            monitor_device: TypedDevice {
50                device: Device { device_type: DeviceType::D, address: 4003 },
51                data_type: DataType::U16
52            }
53        },
54    ];
55    manager.register_monitor_targets(&target_devices).await?;
56
57    tokio::time::sleep(tokio::time::Duration::from_secs(3)).await;
58
59    manager.disconnect(&connection_props).await?;
60
61    Ok(())
62}
Source

pub async fn clear(&self)

Source

pub async fn register_monitor_targets<'a>( &self, targets: &'a [MonitorRequest<'a>], ) -> Result<Vec<MonitoredDevice>>

Examples found in repository?
examples/cyclic_read.rs (line 55)
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 cycle_ms: u64 = 100;
22    let cyclic_task = async |data| {
23        for x in data {
24            println!("{:?}", x);
25        }
26        println!();
27        Ok(())
28    };
29
30    manager.connect(&connection_props, cyclic_task, cycle_ms).await?;
31
32    let target_devices = [
33        MonitorRequest {
34            connection_props: &connection_props,
35            monitor_device: TypedDevice {
36                device: Device { device_type: DeviceType::D, address: 4001 },
37                data_type: DataType::U16
38            }
39        },
40        MonitorRequest {
41            connection_props: &connection_props,
42            monitor_device: TypedDevice {
43                device: Device { device_type: DeviceType::D, address: 4002 },
44                data_type: DataType::U16
45            }
46        },
47        MonitorRequest {
48            connection_props: &connection_props,
49            monitor_device: TypedDevice {
50                device: Device { device_type: DeviceType::D, address: 4003 },
51                data_type: DataType::U16
52            }
53        },
54    ];
55    manager.register_monitor_targets(&target_devices).await?;
56
57    tokio::time::sleep(tokio::time::Duration::from_secs(3)).await;
58
59    manager.disconnect(&connection_props).await?;
60
61    Ok(())
62}
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§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

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

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.