Skip to content

Commit

Permalink
Work around devices without end model.
Browse files Browse the repository at this point in the history
Some devices like SMA STP10.0-3SE-40 do not have an end model and discovery fails. Work around that by pretending an end model was found when an IllegalDataAddress error occurs and at least one valid model has been found before.
  • Loading branch information
mger1 authored and bikeshedder committed Dec 10, 2024
1 parent b189532 commit 713bbc9
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/client/async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,28 @@ async fn discover_models(

let mut models = Models::default();
let mut unknown_models: Vec<UnknownModel> = vec![];
let mut model_count = 0;

loop {
let [model_id, len] = apply_timeout(
read_holding_registers_array::<2>(client, addr),
read_timeout,
)
.await?;
let res = apply_timeout(read_holding_registers_array::<2>(client, addr), read_timeout).await;
let [model_id, len] = match res {
Ok(d) => d,
Err(ModbusError::IllegalDataAddress) => {
if model_count > 0 {
[0xFFFF, 0] //simulate end for devices without end model
} else {
return Err(DiscoveryError::ModbusError(ModbusError::IllegalDataAddress));
}
}
Err(e) => return Err(DiscoveryError::ModbusError(e)),
};

if model_id == 0xFFFF {
break;
}

model_count += 1;

addr = addr.checked_add(2).ok_or(DiscoveryError::AddressOverflow)?;
if !models.set_addr(model_id, addr, len) {
unknown_models.push(UnknownModel {
Expand Down

0 comments on commit 713bbc9

Please sign in to comment.