/// <summary> /// 协议连接断开 /// </summary> /// <returns></returns> public virtual bool Disconnect() { if (ProtocalLinker != null) { return(ProtocalLinker.Disconnect()); } return(false); }
/// <summary> /// 发送协议内容并接收,一般方法 /// </summary> /// <param name="content">写入的内容,使用对象数组描述</param> /// <returns>从设备获取的字节流</returns> public virtual async Task <byte[]> SendReceiveAsync(params object[] content) { if (ProtocalLinker == null || !ProtocalLinker.IsConnected) { await ConnectAsync(); } if (ProtocalLinker != null) { return(await ProtocalLinker.SendReceiveAsync(ProtocalUnit.TranslateContent(Endian, content))); } return(null); }
/// <summary> /// 发送协议,通过传入需要使用的协议内容和输入结构 /// </summary> /// <param name="unit">协议的实例</param> /// <param name="content">输入信息的结构化描述</param> /// <returns>输出信息的结构化描述</returns> public virtual async Task <IOutputStruct> SendReceiveAsync(ProtocalUnit unit, IInputStruct content) { var t = 0; var formatContent = unit.Format(content); if (formatContent != null) { byte[] receiveContent; //如果为特别处理协议的话,跳过协议扩展收缩 if (unit is ISpecialProtocalUnit) { receiveContent = await ProtocalLinker.SendReceiveWithoutExtAndDecAsync(formatContent); } else { receiveContent = await ProtocalLinker.SendReceiveAsync(formatContent); } if (receiveContent != null) { return(unit.Unformat(receiveContent, ref t)); } } return(null); }