Skip to content

Commit

Permalink
sync: Fix timeout when establishing serial RTU connections
Browse files Browse the repository at this point in the history
  • Loading branch information
uklotzde authored and flosse committed Mar 9, 2023
1 parent d4f07b3 commit 755d0ed
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 4 additions & 3 deletions src/client/sync/rtu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 755d0ed

Please sign in to comment.