From a769578e846206da641b6ff301b26f4cde4374ac Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期六, 07 十月 2023 15:00:35 +0800
Subject: [PATCH] 注释掉暂时没用到的
---
pkg/plc/modbusx/connection_manager.go | 12 +++++++++++-
1 files changed, 11 insertions(+), 1 deletions(-)
diff --git a/pkg/plc/modbusx/connection_manager.go b/pkg/plc/modbusx/connection_manager.go
index 3757d34..ae0b377 100644
--- a/pkg/plc/modbusx/connection_manager.go
+++ b/pkg/plc/modbusx/connection_manager.go
@@ -1,14 +1,18 @@
package modbusx
import (
+ "apsClient/conf"
"github.com/goburrow/modbus"
"sync"
+ "time"
)
type ConnectionManager struct {
connections map[string]modbus.Client
mu sync.Mutex
}
+
+var handler *modbus.TCPClientHandler
func newPlcConnectionManager() *ConnectionManager {
return &ConnectionManager{
@@ -56,8 +60,14 @@
return
}
connectionManager.RemoveConnection(ipAddr)
+ if handler != nil {
+ handler.Close()
+ }
}
func newGetModbusConnection(ipAddr string) modbus.Client {
- return modbus.TCPClient(ipAddr)
+ handler = modbus.NewTCPClientHandler(ipAddr)
+ handler.Timeout = 10 * time.Second
+ handler.SlaveId = byte(conf.Conf.PLC.SlaveId)
+ return modbus.NewClient(handler)
}
--
Gitblit v1.8.0