From 83b652cd2f1be2375d33a67366a7c359cf6e22c0 Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期一, 18 九月 2023 14:56:09 +0800 Subject: [PATCH] 支持几个配置,支持按配置选择plc驱动包 --- 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 3757d34..0aef49b 100644 --- a/pkg/plc/modbusx/connection_manager.go +++ b/pkg/plc/modbusx/connection_manager.go @@ -1,8 +1,10 @@ package modbusx import ( + "apsClient/conf" "github.com/goburrow/modbus" "sync" + "time" ) type ConnectionManager struct { @@ -59,5 +61,8 @@ } 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