Compare commits
1 commit
init-fixes
...
main
Author | SHA1 | Date | |
---|---|---|---|
Rahix | 4e271a01a9 |
BIN
succbone/panel.pdf
(Stored with Git LFS)
BIN
succbone/panel.pdf
(Stored with Git LFS)
Binary file not shown.
BIN
succbone/panel.qet
(Stored with Git LFS)
BIN
succbone/panel.qet
(Stored with Git LFS)
Binary file not shown.
|
@ -6,9 +6,7 @@ import (
|
|||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"time"
|
||||
|
||||
"github.com/simonvetter/modbus"
|
||||
"k8s.io/klog"
|
||||
)
|
||||
|
||||
|
@ -57,19 +55,9 @@ func main() {
|
|||
}
|
||||
d.adcPirani = adc
|
||||
|
||||
// Setup modbus client
|
||||
d.modbusClient, err = modbus.NewClient(&modbus.ClientConfiguration{
|
||||
URL: "tcp://10.250.241.20:8887",
|
||||
Timeout: 1 * time.Second,
|
||||
})
|
||||
err = d.modbusConnect()
|
||||
if err != nil {
|
||||
klog.Exitf("Failed to setup modbus client %v", err)
|
||||
}
|
||||
|
||||
// Connect to modbus client
|
||||
err = d.modbusClient.Open()
|
||||
if err != nil {
|
||||
klog.Warningf("Failed to connect to modbus TCP %v", err)
|
||||
klog.Exitf("Failed to connect to modbus %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,29 @@ func modbusValuesToFloat(v uint16) float32 {
|
|||
return float32(v) / 10.0
|
||||
}
|
||||
|
||||
func (d *daemon) modbusConnect() error {
|
||||
var err error
|
||||
|
||||
d.mu.Lock()
|
||||
defer d.mu.Unlock()
|
||||
|
||||
// Setup modbus client
|
||||
d.modbusClient, err = modbus.NewClient(&modbus.ClientConfiguration{
|
||||
URL: "tcp://10.250.241.20:8887",
|
||||
Timeout: 1 * time.Second,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Connect to modbus client
|
||||
err = d.modbusClient.Open()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *daemon) modbusRestart() error {
|
||||
d.modbusClient.Close()
|
||||
return d.modbusClient.Open()
|
||||
|
|
Loading…
Reference in a new issue