Modbus: handle NaN values (#31011)
This commit is contained in:
parent
2a86cc44b1
commit
cc6bef6b82
4 changed files with 26 additions and 9 deletions
|
|
@ -9,6 +9,7 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/evcc-io/evcc/api"
|
||||
"github.com/evcc-io/evcc/util"
|
||||
"github.com/evcc-io/evcc/util/modbus"
|
||||
gridx "github.com/grid-x/modbus"
|
||||
|
|
@ -156,7 +157,12 @@ func (m *Modbus) FloatGetter() (func() (f float64, err error), error) {
|
|||
return 0, fmt.Errorf("read failed: %w", err)
|
||||
}
|
||||
|
||||
return m.scale * decode(bytes), nil
|
||||
// a "*nan" sentinel decodes to NaN - the device reports no valid value
|
||||
if res := m.scale * decode(bytes); !math.IsNaN(res) {
|
||||
return res, nil
|
||||
}
|
||||
|
||||
return 0, api.ErrNotAvailable
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue