From a0ebd21eeda0a2fd56bfa0d372e0a0383003c729 Mon Sep 17 00:00:00 2001 From: Mariusz Bialonczyk Date: Wed, 29 Dec 2021 10:14:58 +0100 Subject: [PATCH] sun2000: add a missing timeout for reading Device Description attributes --- src/sun2000.rs | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/sun2000.rs b/src/sun2000.rs index fff08d1..02dbfe3 100644 --- a/src/sun2000.rs +++ b/src/sun2000.rs @@ -1334,14 +1334,24 @@ impl Sun2000 { // obtain Device Description Definition use tokio_modbus::prelude::*; - let rsp = ctx.call(Request::Custom(0x2b, vec![0x0e, 0x03, 0x87])).await?; - match rsp { - Response::Custom(f, rsp) => { - debug!("{}: Result for function {} is '{:?}'", self.name, f, rsp); - let _ = self.attribute_parser(rsp); - } - _ => { - error!("{}: unexpected Reading Device Identifiers (0x2B) result", self.name); + let retval = ctx.call(Request::Custom(0x2b, vec![0x0e, 0x03, 0x87])); + match timeout(Duration::from_secs_f32(5.0), retval).await { + Ok(res) => match res { + Ok(rsp) => match rsp { + Response::Custom(f, rsp) => { + debug!("{}: Result for function {} is '{:?}'", self.name, f, rsp); + let _ = self.attribute_parser(rsp); + } + _ => { + error!("{}: unexpected Reading Device Identifiers (0x2B) result", self.name); + } + }, + Err(e) => { + warn!("{}: read error during Reading Device Identifiers (0x2B), error: {}", self.name, e); + } + }, + Err(e) => { + warn!("{}: read timeout during Reading Device Identifiers (0x2B), error: {}", self.name, e); } }