From 60786eec5aea892fdc6fbff18857c14cceb3e2a6 Mon Sep 17 00:00:00 2001 From: parallelbgls Date: Wed, 3 May 2017 17:16:32 +0800 Subject: [PATCH] Fix 1 Add Methods in Opc. --- .../Modbus.Net.OPC/OpcProtocalLinker.cs | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/Modbus.Net/Modbus.Net.OPC/OpcProtocalLinker.cs b/Modbus.Net/Modbus.Net.OPC/OpcProtocalLinker.cs index 352e534..c042357 100644 --- a/Modbus.Net/Modbus.Net.OPC/OpcProtocalLinker.cs +++ b/Modbus.Net/Modbus.Net.OPC/OpcProtocalLinker.cs @@ -11,6 +11,42 @@ namespace Modbus.Net.OPC /// public abstract class OpcProtocalLinker : ProtocalLinker { + /// + /// 发送并接收数据 + /// + /// 发送协议的内容 + /// 接收协议的内容 + public override async Task SendReceiveAsync(OpcParamIn content) + { + var extBytes = BytesExtend(content); + var receiveBytes = await SendReceiveWithoutExtAndDecAsync(extBytes); + return receiveBytes == null + ? null + : receiveBytes.Value.Length == 0 ? receiveBytes : BytesDecact(receiveBytes); + } + + /// + /// 发送并接收数据,不进行协议扩展和收缩,用于特殊协议 + /// + /// 发送协议的内容 + /// 接收协议的内容 + public override async Task SendReceiveWithoutExtAndDecAsync(OpcParamIn content) + { + //发送数据 + var receiveBytes = await BaseConnector.SendMsgAsync(content); + //容错处理 + var checkRight = CheckRight(receiveBytes); + return checkRight == null + ? new OpcParamOut {Success = false, Value = new byte[0]} + : (!checkRight.Value ? null : receiveBytes); + //返回字符 + } + + /// + /// 检查接收的数据是否正确 + /// + /// 接收协议的内容 + /// 协议是否是正确的 public override bool? CheckRight(OpcParamOut content) { if (content == null || !content.Success) return false;