/// <summary> /// 系统启动后,先回复设备运行状态 /// </summary> /// <param name="errStr"></param> /// <returns></returns> public override bool DevStatusRestore() { if (!base.DevStatusRestore()) { return(false); } string strWhere = string.Format("(TaskStatus='执行中' or TaskStatus='超时') and DeviceID='{0}' order by CreateTime ", this.nodeID); this.currentTask = ctlTaskBll.GetFirstRequiredTask(strWhere); if (this.currentTask != null) { this.currentTaskPhase = this.currentTask.TaskPhase; this.taskParamModel = new AsrsTaskParamModel(); string reStr = ""; if (!taskParamModel.ParseParam((SysCfg.EnumAsrsTaskType) this.CurrentTask.TaskType, this.CurrentTask.TaskParam, ref reStr)) { ThrowErrorStat(reStr, EnumNodeStatus.设备故障); taskParamModel = null; //logRecorder.AddDebugLog(nodeName, reStr); return(false); } } devStatusRestore = true; return(true); }
public void DelTask(List <string> taskIDs) { foreach (string taskID in taskIDs) { CtlDBAccess.Model.ControlTaskModel taskModel = taskBll.GetModel(taskID); if (taskModel == null) { continue; } if (taskModel.TaskStatus == SysCfg.EnumTaskStatus.执行中.ToString() || taskModel.TaskStatus == SysCfg.EnumTaskStatus.超时.ToString()) { continue; } if (taskModel.TaskType > 5) { taskBll.Delete(taskID); } else { AsrsTaskParamModel paramModel = new AsrsTaskParamModel(); string reStr = ""; // if (!paramModel.ParseParam((SysCfg.EnumAsrsTaskType)taskModel.TaskType, taskModel.TaskParam, ref reStr)) if (!paramModel.ParseParam(taskModel, ref reStr)) { Console.WriteLine(string.Format("任务ID:{0},参数解析失败,无法删除"), taskModel.TaskID); continue; } if (taskModel.TaskStatus == SysCfg.EnumTaskStatus.待执行.ToString()) { if (!asrsResourceManage.UpdateGsTaskStatus(taskModel.tag1, paramModel.CellPos1, EnumGSTaskStatus.完成, ref reStr)) { Console.WriteLine(string.Format("任务ID:{0},删除失败,因为更新{1}:{2}-{3}-{4}状态失败", taskModel.TaskID, taskModel.tag1, paramModel.CellPos1.Row, paramModel.CellPos1.Col, paramModel.CellPos1.Layer)); continue; } if (taskModel.TaskType == (int)SysCfg.EnumAsrsTaskType.移库) { if (!asrsResourceManage.UpdateGsTaskStatus(taskModel.tag1, paramModel.CellPos2, EnumGSTaskStatus.完成, ref reStr)) { Console.WriteLine(string.Format("任务ID:{0},删除失败,因为更新{1}:{2}-{3}-{4}状态失败", taskModel.TaskID, taskModel.tag1, paramModel.CellPos2.Row, paramModel.CellPos2.Col, paramModel.CellPos2.Layer)); continue; } } } taskBll.Delete(taskID); } } QueryTask(); }
private bool AsrsOutTaskBusiness(AsrsControl.AsrsPortalModel outPort, AsrsControl.AsrsTaskParamModel taskParam, ref string reStr) { try { outPort.Db1ValsToSnd[1] = (short)taskParam.CellPos1.Row; if (!outPort.NodeCmdCommit(true, ref reStr)) { reStr = string.Format("出库站台{0}状态'出库完成'提交失败", outPort.PortSeq); return(false); } System.Threading.Thread.Sleep(500); return(true); } catch (Exception ex) { reStr = ex.ToString(); return(false); } }
/// <summary> /// 执行 /// </summary> /// <param name="reStr"></param> /// <returns></returns> public override bool ExeBusiness(ref string reStr) { //if(this.currentStat.Status == EnumNodeStatus.设备故障) //{ // return false; //} if (this.db2Vals[0] != 0 && (this.db2Vals[0] != this.db2ValsLast[0])) { int errCode = this.db2Vals[0]; string errDesc = "未定义的故障码"; if (SysCfg.SysCfgModel.StackerErrcodeMap.Keys.Contains(errCode)) { errDesc = SysCfg.SysCfgModel.StackerErrcodeMap[errCode]; } string errInfo = string.Format("发生故障,故障码:{0},信息:{1}", this.db2Vals[0], errDesc); ThrowErrorStat(errInfo, EnumNodeStatus.设备故障); } if (this.db2Vals[1] != this.db2ValsLast[1]) { if (this.db2ValsLast[1] == 4 && (this.db2Vals[1] == 1 || this.db2Vals[1] == 2)) { logRecorder.AddDebugLog(nodeName, "切换到自动模式"); } else if (this.db2Vals[1] == 3) { logRecorder.AddDebugLog(nodeName, "处于故障状态"); } else if (this.db2Vals[1] == 4) { logRecorder.AddDebugLog(nodeName, "切换到手动模式"); } } if (!nodeEnabled) { return(true); } if (!devStatusRestore) { devStatusRestore = DevStatusRestore(); } if (!devStatusRestore) { return(false); } //任务撤销 if (db2Vals[2] == 3 && db1ValsToSnd[1] != 3) { TaskReback(); return(true); } if (db1ValsToSnd[1] == 3 && db2Vals[2] == 1) { //任务撤销命令复位,应答也复位 db1ValsToSnd[1] = 1; } if (currentTask != null) { this.currentStat.Status = EnumNodeStatus.设备使用中; } else { this.currentStat.Status = EnumNodeStatus.设备空闲; } if (this.db2Vals[0] != 0) { this.db1ValsToSnd[11] = 1; currentTaskDescribe = "设备故障"; return(true); } switch (currentTaskPhase) { case 0: { currentTaskDescribe = "等待新的任务"; if (currentTask == null) { break; } currentTaskDescribe = "即将开始任务通信"; this.taskParamModel = new AsrsTaskParamModel(); if (!taskParamModel.ParseParam((SysCfg.EnumAsrsTaskType) this.CurrentTask.TaskType, this.CurrentTask.TaskParam, ref reStr)) { ThrowErrorStat(reStr, EnumNodeStatus.设备故障); taskParamModel = null; //logRecorder.AddDebugLog(nodeName, reStr); return(false); } currentTaskDescribe = "等待设备空闲状态"; if (this.db2Vals[1] == 1) //设备处于空闲状态,可以 接受新的任务 { //写入参数 string logInfo = string.Format("开始执行任务:{0},{1}-{2}-{3},{4}", ((SysCfg.EnumAsrsTaskType)currentTask.TaskType).ToString(), taskParamModel.CellPos1.Row, taskParamModel.CellPos1.Col, taskParamModel.CellPos1.Layer, currentTask.TaskParam); logRecorder.AddDebugLog(nodeName, logInfo); // logRecorder.AddDebugLog(nodeName, "开始执行任务:" + ((EnumAsrsTaskType)currentTask.TaskType).ToString()); this.currentTask.FinishTime = DateTime.Now; if (WriteTaskParam(this.currentTask)) { this.currentTaskPhase++; this.currentTask.TaskStatus = SysCfg.EnumTaskStatus.执行中.ToString(); this.currentTask.TaskPhase = currentTaskPhase; ctlTaskBll.Update(currentTask); } } break; } case 1: { //参数写入完成 currentTaskDescribe = "开始发送参数"; this.db1ValsToSnd[0] = 2; if (!NodeCmdCommit(true, ref reStr)) { Console.WriteLine("发送参数失败"); break; } currentTask.TaskPhase = currentTaskPhase; logRecorder.AddDebugLog(nodeName, "参数发送完成"); this.currentTaskPhase++; this.currentTask.TaskPhase = currentTaskPhase; ctlTaskBll.Update(currentTask); break; } case 2: { //等待任务完成 currentTaskDescribe = "等待设备进入工作状态"; if (db2Vals[1] != 2) { //必须进入工作状态 break; } if (this.dlgtAsrsPnPCompleted != null) { if (!dlgtAsrsPnPCompleted(this.taskParamModel, this.currentTask, this.db2Vals[3])) { logRecorder.AddDebugLog(nodeName, "取放货完成后处理失败!"); break; } } db1ValsToSnd[0] = 1; currentTaskDescribe = "等待任务完成"; if (db2Vals[2] == 2) { for (int i = 3; i < db1ValsToSnd.Count(); i++) { db1ValsToSnd[i] = 0; } //处理任务 if (dlgtTaskCompleted != null) { if (!dlgtTaskCompleted(this.taskParamModel, this.currentTask)) { logRecorder.AddDebugLog(nodeName, "任务完成后处理失败!"); break; } } //if (!TaskCompletedProcess(this.taskParamModel, this.currentTask)) //{ // logRecorder.AddDebugLog(nodeName, "任务完成后处理失败!"); // break; //} db1ValsToSnd[1] = 2; if (!NodeCmdCommit(true, ref reStr)) { Console.WriteLine("发送任务处理完成状态失败"); break; } // string debugLog = string.Format("任务ID:{0},{1}完成!", currentTask.TaskID, currentTask.Remark); string debugLog = string.Format("任务:{0},{1}-{2}-{3}完成,{4}", ((SysCfg.EnumAsrsTaskType)currentTask.TaskType).ToString(), taskParamModel.CellPos1.Row, taskParamModel.CellPos1.Col, taskParamModel.CellPos1.Layer, currentTask.TaskParam); logRecorder.AddDebugLog(nodeName, debugLog); currentTaskDescribe = "任务完成"; this.currentTaskPhase++; } currentTask.TaskStatus = SysCfg.EnumTaskStatus.已完成.ToString(); currentTask.TaskPhase = currentTaskPhase; ctlTaskBll.Update(currentTask); break; } case 3: { if (this.currentTask.tag5 != "1") //非紧急出库 { if (this.dlgtAsrsPnPCompleted != null) { if (!dlgtAsrsPnPCompleted(this.taskParamModel, this.currentTask, this.db2Vals[3])) { logRecorder.AddDebugLog(nodeName, "取放货完成后处理失败!"); break; } } } currentTaskDescribe = "等待任务完成信号复位"; if (db2Vals[2] != 1) { break; } Array.Clear(this.db1ValsToSnd, 0, this.db1ValsToSnd.Count()); this.db1ValsToSnd[0] = 1; this.db1ValsToSnd[1] = 1; currentTask.TaskStatus = SysCfg.EnumTaskStatus.已完成.ToString(); currentTask.TaskPhase = currentTaskPhase; TimeSpan ts = DateTime.Now - (DateTime)currentTask.FinishTime; currentTask.FinishTime = System.DateTime.Now; currentTask.tag3 = ts.TotalSeconds.ToString("f2"); currentTask.FinishTime = DateTime.Now; string debugLog = string.Format("任务:{0},{1}-{2}-{3}耗时,{4}秒", ((SysCfg.EnumAsrsTaskType)currentTask.TaskType).ToString(), taskParamModel.CellPos1.Row, taskParamModel.CellPos1.Col, taskParamModel.CellPos1.Layer, currentTask.tag3); logRecorder.AddDebugLog(nodeName, debugLog); if (!ctlTaskBll.Update(currentTask)) { Console.WriteLine("更新任务{0}状态失败", currentTask.TaskID); break; } currentTask = null; currentTaskPhase = 0; currentTaskDescribe = "等待执行下一个任务"; logRecorder.AddDebugLog(nodeName, currentTaskDescribe); break; } default: break; } return(true); }
/// <summary> /// 执行 /// </summary> /// <param name="reStr"></param> /// <returns></returns> public override bool ExeBusiness(ref string reStr) { //if(this.currentStat.Status == EnumNodeStatus.设备故障) //{ // return false; //} if (!nodeEnabled) { return(true); } if (!devStatusRestore) { devStatusRestore = DevStatusRestore(); } if (!devStatusRestore) { return(false); } //任务撤销 if (db2Vals[2] == 3 && db1ValsToSnd[1] != 3) { TaskReback(); return(true); } if (db1ValsToSnd[1] == 3 && db2Vals[2] == 1) { //任务撤销命令复位,应答也复位 db1ValsToSnd[1] = 1; } if (currentTask != null) { this.currentStat.Status = EnumNodeStatus.设备使用中; } else { this.currentStat.Status = EnumNodeStatus.设备空闲; } if (this.db2Vals[0] != 0) { this.db1ValsToSnd[11] = 1; currentTaskDescribe = "设备故障"; return(true); } switch (currentTaskPhase) { case 0: { currentTaskDescribe = "等待新的任务"; if (currentTask == null) { break; } currentTaskDescribe = "即将开始任务通信"; this.taskParamModel = new AsrsTaskParamModel(); if (!taskParamModel.ParseParam((SysCfg.EnumAsrsTaskType) this.CurrentTask.TaskType, this.CurrentTask.TaskParam, houseName, ref reStr)) { ThrowErrorStat(reStr, EnumNodeStatus.设备故障); taskParamModel = null; //logRecorder.AddDebugLog(nodeName, reStr); return(false); } currentTaskDescribe = "等待设备空闲状态"; if (this.db2Vals[1] == 1) //设备处于空闲状态,可以 接受新的任务 { string logInfo = ""; //写入参数 if (currentTask.TaskType == 5) //移库 { logInfo = string.Format("开始执行任务:{0},{1}-{2}-{3}至{4}-{5}-{6}", ((SysCfg.EnumAsrsTaskType)currentTask.TaskType).ToString() , taskParamModel.CellPos1.Row, taskParamModel.CellPos1.Col, taskParamModel.CellPos1.Layer, taskParamModel.CellPos2.Row, taskParamModel.CellPos2.Col, taskParamModel.CellPos2.Layer); } else { logInfo = string.Format("开始执行任务:{0},{1}-{2}-{3}", ((SysCfg.EnumAsrsTaskType)currentTask.TaskType).ToString(), taskParamModel.CellPos1.Row, taskParamModel.CellPos1.Col, taskParamModel.CellPos1.Layer); } logRecorder.AddDebugLog(nodeName, logInfo); // logRecorder.AddDebugLog(nodeName, "开始执行任务:" + ((EnumAsrsTaskType)currentTask.TaskType).ToString()); if (WriteTaskParam(this.currentTask)) { this.currentTaskPhase++; this.currentTask.TaskStatus = SysCfg.EnumTaskStatus.执行中.ToString(); this.currentTask.TaskPhase = currentTaskPhase; ctlTaskBll.Update(currentTask); } } break; } case 1: { //参数写入完成 currentTaskDescribe = "开始发送参数"; this.db1ValsToSnd[0] = 2; if (!NodeCmdCommit(true, ref reStr)) { Console.WriteLine("发送参数失败"); break; } currentTask.TaskPhase = currentTaskPhase; logRecorder.AddDebugLog(nodeName, "参数发送完成"); this.currentTaskPhase++; this.currentTask.TaskPhase = currentTaskPhase; ctlTaskBll.Update(currentTask); break; } case 2: { //等待任务完成 currentTaskDescribe = "等待设备进入工作状态"; if (db2Vals[1] != 2) { //必须进入工作状态 break; } db1ValsToSnd[0] = 1; currentTaskDescribe = "等待任务完成"; if (db2Vals[2] == 2) { for (int i = 3; i < db1ValsToSnd.Count(); i++) { db1ValsToSnd[i] = 0; } //处理任务 if (dlgtTaskCompleted != null) { if (!dlgtTaskCompleted(this.taskParamModel, this.currentTask)) { logRecorder.AddDebugLog(nodeName, "任务完成后处理失败!"); break; } } //if (!TaskCompletedProcess(this.taskParamModel, this.currentTask)) //{ // logRecorder.AddDebugLog(nodeName, "任务完成后处理失败!"); // break; //} db1ValsToSnd[1] = 2; if (!NodeCmdCommit(true, ref reStr)) { Console.WriteLine("发送任务处理完成状态失败"); break; } // string debugLog = string.Format("任务ID:{0},{1}完成!", currentTask.TaskID, currentTask.Remark); string debugLog = ""; if (currentTask.TaskType == 5) //移库 { debugLog = string.Format("任务:{0},{1}-{2}-{3}至{4}-{5}-{6}完成", ((SysCfg.EnumAsrsTaskType)currentTask.TaskType).ToString(), taskParamModel.CellPos1.Row, taskParamModel.CellPos1.Col, taskParamModel.CellPos1.Layer , taskParamModel.CellPos2.Row, taskParamModel.CellPos2.Col, taskParamModel.CellPos2.Layer); } else { debugLog = string.Format("任务:{0},{1}-{2}-{3}完成", ((SysCfg.EnumAsrsTaskType)currentTask.TaskType).ToString(), taskParamModel.CellPos1.Row, taskParamModel.CellPos1.Col, taskParamModel.CellPos1.Layer); } logRecorder.AddDebugLog(nodeName, debugLog); currentTaskDescribe = "任务完成"; this.currentTaskPhase++; } currentTask.TaskPhase = currentTaskPhase; ctlTaskBll.Update(currentTask); break; } case 3: { currentTaskDescribe = "等待任务完成信号复位"; if (db2Vals[2] != 1) { break; } DevCmdReset(); currentTask = null; currentTaskPhase = 0; currentTaskDescribe = "等待执行下一个任务"; logRecorder.AddDebugLog(nodeName, currentTaskDescribe); break; } default: break; } return(true); }