private void WMSTaskMonitorProc() { foreach (TaskDeviceModel stDev in wmsStDevList) { List <ManageTaskModel> wmsTasks = new List <ManageTaskModel>(); ResposeData res = WmsSvc.GetWaittingToRunTaskList(stDev, ref wmsTasks); if (!res.Status) { Console.WriteLine("获取{0}待执行管理任务失败{1}", stDev.DeviceCode, res.Describe); continue; } foreach (ManageTaskModel wmsTask in wmsTasks) { if (mainCtlTaskBll.Exists(wmsTask.TaskID)) { continue; } CtlDBAccess.Model.MainControlTaskModel mainCtlTask = new CtlDBAccess.Model.MainControlTaskModel(); mainCtlTask.WMSTaskID = wmsTask.TaskID; mainCtlTask.MainTaskID = wmsTask.TaskID; mainCtlTask.FlowPathKey = wmsTask.StartDevice.DeviceCode + "-" + wmsTask.TargetDevice.DeviceCode; mainCtlTask.PalletCode = wmsTask.PalletCode; mainCtlTask.TaskStatus = "待启动"; //if(wmsTask.Type == "下架") //{ // mainCtlTask.TaskType = "产品出库"; //} //else if(wmsTask.Type=="上架") //{ // mainCtlTask.TaskType = "产品入库"; //} //else //{ // mainCtlTask.TaskType = wmsTask.Type; //} mainCtlTask.TaskType = wmsTask.Type; mainCtlTask.StDevice = wmsTask.StartDevice.DeviceCode; mainCtlTask.StDeviceCata = wmsTask.StartDevice.DeviceType; mainCtlTask.EndDevice = wmsTask.TargetDevice.DeviceCode; mainCtlTask.EndDeviceCata = wmsTask.TargetDevice.DeviceType; if (wmsTask.StartDevice.DeviceType == "货位") { mainCtlTask.StDeviceParam = wmsTask.StartDevice.ExtParam; } if (wmsTask.TargetDevice.DeviceType == "货位") { mainCtlTask.EndDeviceParam = wmsTask.TargetDevice.ExtParam; } mainCtlTask.CreateTime = System.DateTime.Now; mainCtlTask.CreateMode = "自动"; mainCtlTaskBll.Add(mainCtlTask); } } string reStr = ""; //分解主控制任务 List <CtlDBAccess.Model.MainControlTaskModel> mainTasks = mainCtlTaskBll.GetModelList("TaskStatus = '待启动'"); foreach (CtlDBAccess.Model.MainControlTaskModel mainTask in mainTasks) { string pathKey = mainTask.FlowPathKey; if (!wcsPathMap.Keys.Contains(pathKey)) { Console.WriteLine("不存在的路径配置:{0}", pathKey); continue; } FlowCtlBaseModel.WCSFlowPathModel wcsPath = wcsPathMap[pathKey]; if (wcsPath.NodeList.Count() < 1) { continue; } FlowCtlBaseModel.WCSPathNodeModel stNode = wcsPath.NodeList[0]; if (stNode.NodeFlag != "起点") { continue; } string nodeID = stNode.NodeID; FlowCtlBaseModel.CtlNodeBaseModel node = NodeManager.GetNodeByID(nodeID); if (node == null) { continue; } if (node.DevCata == "站台") { if (node.Db2Vals[0] != 2) { continue; } } if (!node.WCSMainTaskStart(mainTask, wcsPath, ref reStr)) { Console.WriteLine("{0} 启动任务:{1}失败,{2}", node.NodeName, mainTask.WMSTaskID, reStr); } else { WmsSvc.UpdateManageTaskStatus(mainTask.WMSTaskID, "执行中"); Console.WriteLine("主控制任务{0},{1}->{2}准备启动", mainTask.MainTaskID, mainTask.StDevice, mainTask.EndDevice); } } /* * foreach(string pathKey in wcsPathMap.Keys) * { * FlowCtlBaseModel.WCSFlowPathModel wcsPath = wcsPathMap[pathKey]; * if(wcsPath.NodeList.Count()<1) * { * continue; * } * * FlowCtlBaseModel.WCSPathNodeModel stNode= wcsPath.NodeList[0]; * if(stNode.NodeFlag !="起点") * { * continue; * } * string nodeID = stNode.NodeID; * FlowCtlBaseModel.CtlNodeBaseModel node = NodeManager.GetNodeByID(nodeID); * if(node == null) * { * continue; * } * //生成第一个控制任务 * List<CtlDBAccess.Model.MainControlTaskModel> mainTasks= mainCtlTaskBll.GetModelList(string.Format("TaskStatus = '待执行' and StDevice='{0}'", nodeID)); * foreach(CtlDBAccess.Model.MainControlTaskModel mainTask in mainTasks) * { * if(!node.WCSMainTaskStart(mainTask, wcsPath, ref reStr)) * { * Console.WriteLine("{0} 启动任务:{1}失败,{2}", node.NodeName, mainTask.WMSTaskID,reStr); * } * else * { * WmsSvc.UpdateManageTaskStatus(mainTask.WMSTaskID, "执行中"); * } * } * }*/ }
public bool CreateNodeNextTask(FlowCtlBaseModel.CtlNodeBaseModel curNode, CtlDBAccess.Model.ControlTaskModel curTask, ref string reStr) { try { CtlDBAccess.Model.MainControlTaskModel mainTask = mainCtlTaskBll.GetModel(curTask.MainTaskID); if (mainTask == null) { reStr = "主任务为空,不存在的主任务ID:" + curTask.MainTaskID; return(false); } FlowCtlBaseModel.WCSFlowPathModel wcsPath = null; if (wcsPathMap.Keys.Contains(mainTask.FlowPathKey)) { wcsPath = wcsPathMap[mainTask.FlowPathKey]; } else { reStr = "路径不存在:" + mainTask.FlowPathKey; return(false); } FlowCtlBaseModel.WCSPathNodeModel wcsNode = wcsPath.GetNodeByID(curNode.NodeID); if (wcsNode.NodeFlag == "终点") { //管理任务完成 WMS_Interface.ResposeData res = WmsSvc.UpdateManageTaskStatus(mainTask.WMSTaskID, "已完成"); if (!res.Status) { reStr = string.Format("更新WMS任务:{0}状态失败,{1}", mainTask.WMSTaskID, res.Describe); return(false); } mainTask.TaskStatus = "已完成"; mainTask.FinishTime = System.DateTime.Now; if (!mainCtlTaskBll.Update(mainTask)) { reStr = string.Format("更新主控制任务:{0}状态失败", mainTask.MainTaskID); return(false); } return(true); } FlowCtlBaseModel.CtlNodeBaseModel nextNode = NodeManager.GetNodeByID(wcsNode.NextNodeID); if (curNode.DevCata == "站台") { if (nextNode.DevCata == "站台") { CtlDBAccess.Model.ControlTaskModel nextCtlTask = CreateConveyorTask(curTask.TaskIndex + 1, mainTask.MainTaskID, curNode as TransDevModel.NodeTransStation, nextNode as TransDevModel.NodeTransStation, curTask.PalletCode, ref reStr); if (nextCtlTask == null) { return(false); } return(ctlTaskBll.Add(nextCtlTask)); } else if (nextNode.DevCata == "RGV") { FlowCtlBaseModel.WCSPathNodeModel rgvTargetWcsNode = wcsPath.GetNodeByID(wcsNode.NextNodeID); FlowCtlBaseModel.CtlNodeBaseModel nextNode2 = NodeManager.GetNodeByID(rgvTargetWcsNode.NextNodeID); if (nextNode2 == null) { reStr = "不存在的设备号:" + wcsNode.NextNodeID; return(false); } FlowCtlBaseModel.WCSPathNodeModel nextWcsNode = wcsPath.GetNodeByID(nextNode2.NodeID); if (nextWcsNode == null) { reStr = "路径配置,RGV路径缺少下料站台"; return(false); } CtlDBAccess.Model.ControlTaskModel nextCtlTask = CreateRGVTask(curTask.TaskIndex + 1, mainTask.MainTaskID, nextNode as TransDevModel.NodeRGV, curNode as TransDevModel.NodeTransStation, nextNode2 as TransDevModel.NodeTransStation, curTask.PalletCode, ref reStr); if (nextCtlTask == null) { return(false); } return(ctlTaskBll.Add(nextCtlTask)); } else if (nextNode.DevCata == "堆垛机") { CtlDBAccess.Model.ControlTaskModel nextCtlTask = CreateStackerTask(curTask.TaskIndex + 1, mainTask, nextNode.NodeID, curNode as TransDevModel.NodeTransStation, curTask.PalletCode, ref reStr); if (nextCtlTask == null) { return(false); } return(ctlTaskBll.Add(nextCtlTask)); } } else if (curNode.DevCata == "RGV") { if (nextNode.DevCata != "站台") { reStr = "RGV目标设备应该为站台"; return(false); } FlowCtlBaseModel.WCSPathNodeModel rgvTargetWcsNode = wcsPath.GetNodeByID(wcsNode.NextNodeID); if (rgvTargetWcsNode.NodeFlag == "终点") { //管理任务完成 WMS_Interface.ResposeData res = WmsSvc.UpdateManageTaskStatus(mainTask.WMSTaskID, "已完成"); if (!res.Status) { reStr = string.Format("更新WMS任务:{0}状态失败,{1}", mainTask.WMSTaskID, res.Describe); return(false); } mainTask.TaskStatus = "已完成"; mainTask.FinishTime = System.DateTime.Now; if (!mainCtlTaskBll.Update(mainTask)) { reStr = string.Format("更新主控制任务:{0}状态失败", mainTask.MainTaskID); return(false); } return(true); } FlowCtlBaseModel.CtlNodeBaseModel rgvTargetNode = NodeManager.GetNodeByID(rgvTargetWcsNode.NodeID); FlowCtlBaseModel.CtlNodeBaseModel nextNode2 = NodeManager.GetNodeByID(rgvTargetWcsNode.NextNodeID); if (nextNode2.DevCata == "站台") { CtlDBAccess.Model.ControlTaskModel nextCtlTask = CreateConveyorTask(curTask.TaskIndex + 1, mainTask.MainTaskID, rgvTargetNode as TransDevModel.NodeTransStation, nextNode2 as TransDevModel.NodeTransStation, curTask.PalletCode, ref reStr); if (nextCtlTask == null) { return(false); } return(ctlTaskBll.Add(nextCtlTask)); } else if (nextNode2.DevCata == "堆垛机") { CtlDBAccess.Model.ControlTaskModel nextCtlTask = CreateStackerTask(curTask.TaskIndex + 1, mainTask, nextNode2.NodeID, rgvTargetNode as TransDevModel.NodeTransStation, curTask.PalletCode, ref reStr); if (nextCtlTask == null) { return(false); } return(ctlTaskBll.Add(nextCtlTask)); } else { reStr = "错误的路径配置,两台RGV不允许共用一个接驳站台"; return(false); } } else if (curNode.DevCata == "堆垛机") { if (nextNode.DevCata != "站台") { reStr = "堆垛机目标设备应该为站台"; return(false); } FlowCtlBaseModel.WCSPathNodeModel targetWcsNode = wcsPath.GetNodeByID(wcsNode.NextNodeID); if (targetWcsNode.NodeFlag == "终点") { //管理任务完成 WMS_Interface.ResposeData res = WmsSvc.UpdateManageTaskStatus(mainTask.WMSTaskID, "已完成"); if (!res.Status) { reStr = string.Format("更新WMS任务:{0}状态失败,{1}", mainTask.WMSTaskID, res.Describe); return(false); } mainTask.TaskStatus = "已完成"; mainTask.FinishTime = System.DateTime.Now; if (!mainCtlTaskBll.Update(mainTask)) { reStr = string.Format("更新主控制任务:{0}状态失败", mainTask.MainTaskID); return(false); } return(true); } FlowCtlBaseModel.CtlNodeBaseModel nextNode2 = NodeManager.GetNodeByID(targetWcsNode.NextNodeID); if (nextNode2.DevCata == "站台") { CtlDBAccess.Model.ControlTaskModel nextCtlTask = CreateConveyorTask(curTask.TaskIndex + 1, mainTask.MainTaskID, nextNode as TransDevModel.NodeTransStation, nextNode2 as TransDevModel.NodeTransStation, curTask.PalletCode, ref reStr); if (nextCtlTask == null) { return(false); } return(ctlTaskBll.Add(nextCtlTask)); } else if (nextNode2.DevCata == "RGV") { FlowCtlBaseModel.WCSPathNodeModel targetWcsNode2 = wcsPath.GetNodeByID(nextNode2.NodeID); FlowCtlBaseModel.CtlNodeBaseModel nextNode3 = NodeManager.GetNodeByID(targetWcsNode2.NextNodeID); if (nextNode3 == null) { return(false); } CtlDBAccess.Model.ControlTaskModel nextCtlTask = CreateRGVTask(curTask.TaskIndex + 1, mainTask.MainTaskID, nextNode2 as TransDevModel.NodeRGV, nextNode as TransDevModel.NodeTransStation, nextNode3 as TransDevModel.NodeTransStation, curTask.PalletCode, ref reStr); if (nextCtlTask == null) { return(false); } return(ctlTaskBll.Add(nextCtlTask)); } } return(true); } catch (Exception ex) { reStr = ex.ToString(); Console.WriteLine(ex.ToString()); return(false); } }