From 082c08e5f9c2deda1c7290499fbeaa07a024e7e1 Mon Sep 17 00:00:00 2001 From: Kimdiego2098 <2248356998@qq.com> Date: Sun, 27 Aug 2023 16:15:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0dlt645,=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=9C=B0=E5=9D=80/=E6=8E=A7=E5=88=B6=E7=A0=81=E7=9A=84?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DLT645/DLT645_2007DataHandleAdapter.cs | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/framework/ThingsGateway.Plugin/Foundataion/ThingsGateway.Foundation.Adapter.DLT645/DLT645/DLT645_2007DataHandleAdapter.cs b/framework/ThingsGateway.Plugin/Foundataion/ThingsGateway.Foundation.Adapter.DLT645/DLT645/DLT645_2007DataHandleAdapter.cs index 8009a37ce..1d0a3a2a4 100644 --- a/framework/ThingsGateway.Plugin/Foundataion/ThingsGateway.Foundation.Adapter.DLT645/DLT645/DLT645_2007DataHandleAdapter.cs +++ b/framework/ThingsGateway.Plugin/Foundataion/ThingsGateway.Foundation.Adapter.DLT645/DLT645/DLT645_2007DataHandleAdapter.cs @@ -62,6 +62,18 @@ public class DLT645_2007DataHandleAdapter : ReadWriteDevicesTcpDataHandleAdapter } } } + int sendHeadCodeIndex = 0; + if (send != null) + { + for (int index = 0; index < send.Length; index++) + { + if (send[index] == 0x68) + { + sendHeadCodeIndex = index; + break; + } + } + } //帧起始符 地址域 帧起始符 控制码 数据域长度共10个字节 if (headCodeIndex < 0 || headCodeIndex + 10 > response.Length) @@ -88,6 +100,47 @@ public class DLT645_2007DataHandleAdapter : ReadWriteDevicesTcpDataHandleAdapter request.ResultCode = ResultCode.Fail; return FilterResult.Success; } + + if ( + (response[headCodeIndex + 1] != send[sendHeadCodeIndex + 1]) || + (response[headCodeIndex + 2] != send[sendHeadCodeIndex + 2]) || + (response[headCodeIndex + 3] != send[sendHeadCodeIndex + 3]) || + (response[headCodeIndex + 4] != send[sendHeadCodeIndex + 4]) || + (response[headCodeIndex + 5] != send[sendHeadCodeIndex + 5]) || + (response[headCodeIndex + 6] != send[sendHeadCodeIndex + 6]) + )//设备地址不符合时,返回错误 + { + + if ( + (response[headCodeIndex + 1] == 0xAA) && + (response[headCodeIndex + 2] == 0xAA) && + (response[headCodeIndex + 3] == 0xAA) && + (response[headCodeIndex + 4] == 0xAA) && + (response[headCodeIndex + 5] == 0xAA) && + (response[headCodeIndex + 6] == 0xAA) + )//读写通讯地址例外 + { + + } + else + { + request.Message = "返回地址不符合规则"; + request.ResultCode = ResultCode.Fail; + return FilterResult.Success; + } + + } + + + + if ((response[headCodeIndex + 8] != send[sendHeadCodeIndex + 8] + 0x80))//控制码不符合时,返回错误 + { + request.Message = "返回控制码:" + $"0x{response[headCodeIndex + 8]:X2},请求控制码:" + $"0x{send[sendHeadCodeIndex + 8]:X2},不符合规则"; + request.ResultCode = ResultCode.Fail; + return FilterResult.Success; + } + + if ((response[headCodeIndex + 8] & 0x40) == 0x40)//控制码bit6为1时,返回错误 { byte byte1 = (byte)(response[headCodeIndex + 10] - 0x33);