Close modbus connection if operation fails to reestablish connection (#221)
This commit is contained in:
parent
a94f822fe8
commit
173667a4de
2 changed files with 7 additions and 2 deletions
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue