Skip to content

Commit

Permalink
Close modbus connection if operation fails to reestablish connection (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
andig committed Jul 18, 2020
1 parent a94f822 commit 173667a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 3 additions & 1 deletion meter/modbus.go
Expand Up @@ -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)
}

Expand Down
5 changes: 4 additions & 1 deletion provider/modbus.go
Expand Up @@ -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")
}

Expand All @@ -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)
}

Expand Down

0 comments on commit 173667a

Please sign in to comment.