Modbus: guard against panic (#3907)
This commit is contained in:
parent
595a2ca8b2
commit
5e0ac24c70
1 changed files with 8 additions and 3 deletions
|
|
@ -152,9 +152,14 @@ func (m *Modbus) bytesGetter() ([]byte, error) {
|
|||
return nil, errors.New("expected rtu reading")
|
||||
}
|
||||
|
||||
func (m *Modbus) floatGetter() (float64, error) {
|
||||
func (m *Modbus) floatGetter() (f float64, err error) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
err = fmt.Errorf("panic: %v", r)
|
||||
}
|
||||
}()
|
||||
|
||||
var res meters.MeasurementResult
|
||||
var err error
|
||||
|
||||
// if funccode is configured, execute the read directly
|
||||
if op := m.op.MBMD; op.FuncCode != 0 {
|
||||
|
|
@ -201,7 +206,7 @@ func (m *Modbus) floatGetter() (float64, error) {
|
|||
}
|
||||
|
||||
// FloatGetter executes configured modbus read operation and implements func() (float64, error)
|
||||
func (m *Modbus) FloatGetter() func() (float64, error) {
|
||||
func (m *Modbus) FloatGetter() func() (f float64, err error) {
|
||||
return m.floatGetter
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue