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 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}Sourcepub async fn connect<'a, T, F, Fut>(
&self,
connection_props: &'a SLMP4EConnectionProps,
cyclic_task: F,
cycle_ms: u64,
) -> Result<()>
pub async fn connect<'a, T, F, Fut>( &self, connection_props: &'a SLMP4EConnectionProps, cyclic_task: F, cycle_ms: u64, ) -> Result<()>
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}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 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}pub async fn clear(&self)
Sourcepub async fn register_monitor_targets<'a>(
&self,
targets: &'a [MonitorRequest<'a>],
) -> Result<Vec<MonitoredDevice>>
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}pub async fn get_connections_with_elapsed_time( &self, ) -> HashMap<SocketAddr, Duration>
pub async fn operate_worker<'a, T, F, Fut>( &self, connection_props: &'a SLMP4EConnectionProps, task: F, ) -> Result<T>
Auto Trait Implementations§
impl Freeze for SLMPConnectionManager
impl !RefUnwindSafe for SLMPConnectionManager
impl Send for SLMPConnectionManager
impl Sync for SLMPConnectionManager
impl Unpin for SLMPConnectionManager
impl !UnwindSafe for SLMPConnectionManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more