Skip to content

Commit

Permalink
Modbus: mimic mbmd
Browse files Browse the repository at this point in the history
  • Loading branch information
andig committed Aug 13, 2024
1 parent ab570eb commit 660f2c6
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion util/modbus/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package modbus

import (
"sync"
"time"

"github.com/grid-x/modbus"
"github.com/volkszaehler/mbmd/meters"
Expand All @@ -16,7 +17,12 @@ func (l *logger) WithLogger(logger modbus.Logger, fun func() ([]byte, error)) ([
l.mu.Lock()
defer l.mu.Unlock()

l.logger = logger
if l.logger != logger {
// small delay when switching logger/ slave id to mimic mbmd behavior
time.Sleep(10 * time.Millisecond)
l.logger = logger
}

return fun()
}

Expand Down

0 comments on commit 660f2c6

Please sign in to comment.