/// <summary> /// CreateResponse /// </summary> /// <param name="responcedata"></param> /// <returns></returns> /// <remarks></remarks> public static CommandBase_RM CreateResponseData(byte[] responcedata) { CommandBase_RM ret = new CommandBase_RM(); //レスポンスの埋め込み ret.CommandData_RM.SetCommand(responcedata); return ret; }
/// <summary> /// コマンド受信(現状は処理なし) /// </summary> /// <param name="commandData"></param> public void ExcuteCommand(CommandBase_RM commandData) { }
/// <summary> /// CreateSendData /// </summary> /// <returns></returns> /// <remarks></remarks> public static CommandBase_RM CreateSendData() { CommandBase_RM ret = new CommandBase_RM(); return ret; }
/// <summary> /// レスポンス検索 /// </summary> /// <param name="command">レスポンス対象となったSendCommand</param> /// <returns></returns> /// <remarks></remarks> private bool searchResponse(CommandBase_RM command ) { if (_ResponseCommandList.Count == 0) return false; return _ResponseCommandList.Exists((x) => (x != null && (x.Command == command.Command && x.SubCommand == command.SubCommand && x.Address == command.Address && x.Channel == x.Channel))); }
/// <summary> /// レスポンス取得 /// </summary> /// <param name="command">レスポンス対象となったSendCommand</param> /// <returns></returns> /// <remarks></remarks> private CommandBase_RM GetResponse(CommandBase_RM command) { int Index = _ResponseCommandList.FindIndex((x) => (x.Command == command.Command && x.SubCommand == command.SubCommand && x.Address == command.Address && x.Channel == x.Channel)); if (Index == -1) return null; CommandBase_RM ret = (CommandBase_RM)_ResponseCommandList[Index]; _ResponseCommandList.RemoveAt(Index); return ret; }
/// <summary> /// コマンドのSend /// </summary> /// <param name="commandData"></param> /// <returns></returns> /// <remarks></remarks> public bool SendCommandWithReset(CommandBase_RM commandData) { //データバッファのクリア DataBuffer.Clear(); byte[] sendbyte = commandData.GetCommandToByte(); log.WriteLog(String.Format("Send --> {0}", commandData.ToString()), System.Drawing.Color.Blue); return base.SendCommandWithReset(sendbyte); }
/// <summary> /// コマンドのSend /// </summary> /// <param name="commandData"></param> /// <returns></returns> /// <remarks></remarks> public bool SendCommand(CommandBase_RM commandData) { byte[] sendbyte = commandData.GetCommandToByte(); log.WriteLog(String.Format("Send --> {0}", commandData.ToString()), System.Drawing.Color.Blue); return base.SendCommand(sendbyte); }
/// <summary> /// コマンド送信~レスポンス取得まで /// </summary> /// <param name="command">SendCommand</param> /// <returns>レスポンス Response or Nothing</returns> /// <remarks>Null 時はTimeOut</remarks> public CommandBase_RM SendAndWaitResponseWithReset(CommandBase_RM command, int TimeOutmsec) { if (TimeOutmsec == -1) TimeOutmsec = CommuCommon.SENDTORESPONSE_TIMEOUT; System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); bool bTimeout = false; //responseデータをクリア _ResponseCommandList.Clear(); //コマンドの実行 this.SendCommandWithReset(command); //レスポンス待ち sw.Reset(); sw.Start(); while (!searchResponse(command)) { System.Threading.Thread.Sleep(10); //Application.DoEvents(); //タイムアウト if (sw.ElapsedMilliseconds >= TimeOutmsec) { bTimeout = true; break; } } if (bTimeout) //失敗 return null; else //レスポンス格納 return GetResponse(command); }