From 755d0ed25d6ee2f03742b06c01e3cd086623187c Mon Sep 17 00:00:00 2001 From: Uwe Klotz Date: Thu, 9 Mar 2023 11:20:25 +0100 Subject: [PATCH] sync: Fix timeout when establishing serial RTU connections --- CHANGELOG.md | 1 + src/client/sync/rtu.rs | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index af9d6021..5fb64081 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ - TCP Server: Stabilize "tcp-server" feature - TCP Client: Allow to attach a generic transport layer, e.g. for TLS support - RTU Server: Remove `NewService` trait and pass instance directly +- Fix (sync): No timeout while establishing serial RTU connections ### Breaking Changes diff --git a/src/client/sync/rtu.rs b/src/client/sync/rtu.rs index 570fa008..2b6cbda7 100644 --- a/src/client/sync/rtu.rs +++ b/src/client/sync/rtu.rs @@ -7,7 +7,6 @@ use super::{block_on_with_timeout, Context}; use tokio_serial::{SerialPortBuilder, SerialStream}; -use crate::client::rtu::connect_slave as async_connect_slave; use crate::slave::Slave; /// Connect to no particular Modbus slave device for sending @@ -41,8 +40,10 @@ pub fn connect_slave_with_timeout( .enable_time() .build()?; // SerialStream::open requires a runtime at least on cfg(unix). - let serial = runtime.block_on(async { SerialStream::open(builder) })?; - let async_ctx = block_on_with_timeout(&runtime, timeout, async_connect_slave(serial, slave))?; + let serial = block_on_with_timeout(&runtime, timeout, async { + SerialStream::open(builder).map_err(Into::into) + })?; + let async_ctx = crate::client::rtu::attach_slave(serial, slave); let sync_ctx = Context { runtime, async_ctx,