Close modbus connection if operation fails to reestablish connection (#221)

This commit is contained in:
andig 2020-07-18 10:36:28 +02:00 • committed by GitHub
parent a94f822fe8
commit 173667a4de
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 2 deletions

View file

@ -105,7 +105,9 @@ func (m *Modbus) floatGetter(op modbus.Operation) (float64, error) {
}
}
if err == nil {
if err != nil {
m.conn.Close() // close connection in case of modbus error
} else {
m.log.TRACE.Printf("%+v", res)
}

View file

@ -124,6 +124,7 @@ func (m *Modbus) FloatGetter() (float64, error) {
}
if err != nil {
m.conn.Close() // close connection in case of modbus error
return 0, errors.Wrap(err, "read failed")
}
@ -144,7 +145,9 @@ func (m *Modbus) FloatGetter() (float64, error) {
}
}
if err == nil {
if err != nil {
m.conn.Close() // close connection in case of modbus error
} else {
m.log.TRACE.Printf("%+v", res)
}