Skip to content

Commit

Permalink
sun2000: add a missing timeout for reading Device Description attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
manio committed Dec 29, 2021
1 parent 29144a3 commit a0ebd21
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions src/sun2000.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!("<i>{}</>: Result for function {} is '{:?}'", self.name, f, rsp);
let _ = self.attribute_parser(rsp);
}
_ => {
error!("<i>{}</>: 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!("<i>{}</>: Result for function {} is '{:?}'", self.name, f, rsp);
let _ = self.attribute_parser(rsp);
}
_ => {
error!("<i>{}</>: unexpected Reading Device Identifiers (0x2B) result", self.name);
}
},
Err(e) => {
warn!("<i>{}</i>: read error during <green><i>Reading Device Identifiers (0x2B)</>, error: <b>{}</>", self.name, e);
}
},
Err(e) => {
warn!("<i>{}</i>: read timeout during <green><i>Reading Device Identifiers (0x2B)</>, error: <b>{}</>", self.name, e);
}
}

Expand Down

0 comments on commit a0ebd21

Please sign in to comment.