chore: log modbus timeouts

This commit is contained in:
andig 2024-08-10 11:07:39 +02:00
parent 3d401bd18f
commit baf15a62e8

View file

@ -1,6 +1,7 @@
package modbus
import (
"fmt"
"time"
"github.com/volkszaehler/mbmd/meters"
@ -40,11 +41,14 @@ func (c *Connection) Timeout(timeout time.Duration) {
}
func (c *Connection) exec(fun func() ([]byte, error)) ([]byte, error) {
time.Sleep(c.delay)
return c.WithLogger(c.logical, func() ([]byte, error) {
time.Sleep(c.delay)
start := time.Now()
b, err := fun()
if err != nil {
c.Connection.Close()
fmt.Println("!!", time.Since(start), err)
}
return b, err
})