From 98fb172278ee50401de330fe7dcfb04e82a9223e Mon Sep 17 00:00:00 2001
From: basic <basic@localhost.localdomain>
Date: 星期二, 17 十月 2023 15:59:41 +0800
Subject: [PATCH] .gitignore
---
pkg/plc/modbusx/connection_manager.go | 7 ++++++-
1 files changed, 6 insertions(+), 1 deletions(-)
diff --git a/pkg/plc/modbusx/connection_manager.go b/pkg/plc/modbusx/connection_manager.go
index 0aef49b..ae0b377 100644
--- a/pkg/plc/modbusx/connection_manager.go
+++ b/pkg/plc/modbusx/connection_manager.go
@@ -12,6 +12,8 @@
mu sync.Mutex
}
+var handler *modbus.TCPClientHandler
+
func newPlcConnectionManager() *ConnectionManager {
return &ConnectionManager{
connections: make(map[string]modbus.Client),
@@ -58,10 +60,13 @@
return
}
connectionManager.RemoveConnection(ipAddr)
+ if handler != nil {
+ handler.Close()
+ }
}
func newGetModbusConnection(ipAddr string) modbus.Client {
- handler := modbus.NewTCPClientHandler(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