diff --git a/Modbus.Net/src/Base.Common/PipeUnit.cs b/Modbus.Net/src/Base.Common/PipeUnit.cs index 9a92b3d..21a36c7 100644 --- a/Modbus.Net/src/Base.Common/PipeUnit.cs +++ b/Modbus.Net/src/Base.Common/PipeUnit.cs @@ -5,18 +5,38 @@ using System.Threading.Tasks; namespace Modbus.Net { + /// + /// 管道单元 + /// public class PipeUnit : PipeUnit, ProtocalUnit> { + /// + /// 构造函数 + /// + /// 连接器 public PipeUnit(IProtocalLinker protocalLinker) : base(protocalLinker) { } + /// + /// 构造函数 + /// + /// 连接器 + /// 协议单元 + /// 传递给输入结构的参数 + /// 上次的管道是否成功执行 protected PipeUnit(IProtocalLinker protocalLinker, ProtocalUnit protocalUnit, byte[] parameters, bool success) : base(protocalLinker, protocalUnit, parameters, success) { } + /// + /// 再次发送数据 + /// + /// 端格式 + /// 构造输入结构的函数 + /// 发送完成之后新的管道实例 public async Task SendReceiveAsync(Endian endian, Func inputStructCreator) { if (Success) @@ -30,11 +50,17 @@ namespace Modbus.Net return new PipeUnit(ProtocalLinker, null, ReturnParams, false); } - public async Task SendReceiveAsync( + /// + /// 再次发送数据 + /// + /// 协议单元 + /// 构造输入结构的函数 + /// 发送完成之后新的管道实例 + public new async Task SendReceiveAsync( ProtocalUnit unit, Func inputStructCreator) { - var receiveContent = await SendReceiveAsync1(unit, inputStructCreator); + var receiveContent = await SendReceiveAsyncParamOut(unit, inputStructCreator); if (receiveContent != null) return new PipeUnit(ProtocalLinker, unit, receiveContent, true); @@ -42,22 +68,44 @@ namespace Modbus.Net false); } + /// + /// 管道完成,返回最终结果 + /// + /// 最后的字节数组结构 public byte[] Unwrap() { return ReturnParams; } } + /// + /// 管道单元 + /// + /// 输入参数 + /// 输出参数 + /// 连接器 + /// 协议单元 public class PipeUnit where TProtocalUnit : class, IProtocalFormatting where TProtocalLinker : class, IProtocalLinker where TParamOut : class { + /// + /// 构造函数 + /// + /// 连接器 public PipeUnit(TProtocalLinker protocalLinker) : this(protocalLinker, null, null, true) { } + /// + /// 构造函数 + /// + /// 连接器 + /// 协议单元 + /// 输入参数 + /// 上一次管道结果是否成功 protected PipeUnit(TProtocalLinker protocalLinker, TProtocalUnit protocalUnit, TParamOut parameters, bool success) { ProtocalLinker = protocalLinker; @@ -66,15 +114,33 @@ namespace Modbus.Net Success = success; } + /// + /// 协议连接器 + /// protected TProtocalLinker ProtocalLinker { get; set; } + /// + /// 协议单元 + /// protected TProtocalUnit ProtocalUnit { get; set; } + /// + /// 输入结构传入的参数 + /// protected TParamOut ReturnParams { get; set; } + /// + /// 本次管道是否成功 + /// public bool Success { get; } - protected async Task SendReceiveAsync1(TProtocalUnit unit, + /// + /// 向设备发送数据,返回输出参数 + /// + /// 协议单元 + /// 输入参数生成函数 + /// 输出参数 + protected async Task SendReceiveAsyncParamOut(TProtocalUnit unit, Func inputStructCreator) { if (Success) @@ -95,11 +161,17 @@ namespace Modbus.Net return null; } + /// + /// 向设备发送数据,返回管道 + /// + /// 协议单元 + /// 输入参数生成函数 + /// 管道实体 public virtual async Task> SendReceiveAsync( TProtocalUnit unit, Func inputStructCreator) { - var receiveContent = await SendReceiveAsync1(unit, inputStructCreator); + var receiveContent = await SendReceiveAsyncParamOut(unit, inputStructCreator); if (receiveContent != null) return new PipeUnit(ProtocalLinker, unit, receiveContent, true); @@ -107,6 +179,11 @@ namespace Modbus.Net false); } + /// + /// 所有管道执行结束,输出结果 + /// + /// 输出的类型 + /// 输出结果 public T Unwrap() where T : class, IOutputStruct { var t = 0;