From 24991928e6b6123751c05f166678883a89e4bf0a Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期五, 03 十一月 2023 16:19:41 +0800 Subject: [PATCH] fix --- service/plc.go | 18 +++--------------- 1 files changed, 3 insertions(+), 15 deletions(-) diff --git a/service/plc.go b/service/plc.go index 68258b8..386c8d3 100644 --- a/service/plc.go +++ b/service/plc.go @@ -119,21 +119,13 @@ func ReadByModbusTCP(ipAddr string, address, length int) ([]byte, error) { if conf.Conf.PLC.Package == constvar.PlcPackageApache { - newLength := length / 2 - if newLength == 0 { - newLength = 1 - } - return apacheplc4x.ReadHoldingRegister(ipAddr, address, newLength) + return apacheplc4x.ReadHoldingRegister(ipAddr, address, length) } else if conf.Conf.PLC.Package == constvar.PlcPackageApacheLongConnection { conn, err := plc.GetModbusConnection(ipAddr) if err != nil { return nil, err } - newLength := length / 2 - if newLength == 0 { - newLength = 1 - } - return plc.ReadHoldingRegister(conn, address, newLength) + return plc.ReadHoldingRegister(conn, address, length) } else { return modbusx.Read(ipAddr, uint16(address), uint16(length)) } @@ -164,11 +156,7 @@ Parity: plcConfig.Parity, } if conf.Conf.PLC.Package == constvar.PlcPackageApache { - newLength := length / 2 - if newLength == 0 { - newLength = 1 - } - return apacheplc4x.ReadHoldingRegisterByRTU(rtuConfig, address, newLength) + return apacheplc4x.ReadHoldingRegisterByRTU(rtuConfig, address, length) } else { return modbusx.ReadByRTU(rtuConfig, uint16(address), uint16(length)) } -- Gitblit v1.8.0