Don't exit on max retries in updateRegisters, except on initial run
This commit is contained in:
parent
ea8ca1a6df
commit
28a555fa2b
|
@ -32,6 +32,7 @@ type Pingvin struct {
|
||||||
buslock *sync.Mutex
|
buslock *sync.Mutex
|
||||||
handler *modbus.RTUClientHandler
|
handler *modbus.RTUClientHandler
|
||||||
modbusclient modbus.Client
|
modbusclient modbus.Client
|
||||||
|
firstReadDone bool
|
||||||
Debug PingvinLogger
|
Debug PingvinLogger
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -310,13 +311,18 @@ func (p *Pingvin) updateRegisters() {
|
||||||
if len(results) > 0 {
|
if len(results) > 0 {
|
||||||
break
|
break
|
||||||
} else if retries == 4 {
|
} else if retries == 4 {
|
||||||
log.Printf("ERROR: updateRegisters: max retries reached, giving up. client.ReadHoldingRegisters: ", err)
|
log.Printf("ERROR: updateRegisters: max retries reached, giving up. client.ReadHoldingRegisters: %v", err)
|
||||||
|
log.Printf("ERROR: error occurred when reading registers %d - %d", k, k+r-1)
|
||||||
|
if !p.firstReadDone {
|
||||||
|
panic("FATAL: Error on initial read")
|
||||||
|
}
|
||||||
return
|
return
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
log.Printf("WARNING: updateRegisters: client.ReadHoldingRegisters attempt %d: %s", retries, err)
|
log.Printf("WARNING: updateRegisters: client.ReadHoldingRegisters attempt %d: %s", retries, err)
|
||||||
}
|
}
|
||||||
time.Sleep(200 * time.Millisecond)
|
time.Sleep(200 * time.Millisecond)
|
||||||
}
|
}
|
||||||
|
p.firstReadDone = true
|
||||||
// The values represent 16 bit integers, but modbus works with bytes
|
// The values represent 16 bit integers, but modbus works with bytes
|
||||||
// Each even byte of the returned []byte is the 8 MSBs of a new 16-bit
|
// Each even byte of the returned []byte is the 8 MSBs of a new 16-bit
|
||||||
// value, so for each even byte in the reponse slice we bitshift the byte
|
// value, so for each even byte in the reponse slice we bitshift the byte
|
||||||
|
|
Loading…
Reference in New Issue