/// <summary> /// RGV任务调度 /// </summary> /// <param name="ctlTaskList"></param> /// <param name="reStr"></param> /// <returns></returns> private CtlDBAccess.Model.ControlTaskModel RgvTasksndAllocate(TransDevModel.NodeRGV rgv, ref string reStr) { CtlDBAccess.Model.ControlTaskModel ctlTask = null; List <CtlDBAccess.Model.ControlTaskModel> taskList = ctlTaskBll.GetTaskToRunList((int)SysCfg.EnumAsrsTaskType.RGV上下料, SysCfg.EnumTaskStatus.待执行.ToString(), rgv.NodeID, true); foreach (CtlDBAccess.Model.ControlTaskModel taskModel in taskList) { if (0 != TaskLockCheck(rgv, taskModel, ref reStr)) { continue; } string devSt = taskModel.StDevice; string devTarget = taskModel.EndDevice; FlowCtlBaseModel.CtlNodeBaseModel stNode = NodeManager.GetNodeByID(devSt); FlowCtlBaseModel.CtlNodeBaseModel targetNode = NodeManager.GetNodeByID(devTarget); if (stNode == null || stNode.DevCata != "站台") { continue; } if (targetNode == null || targetNode.DevCata != "站台") { continue; } //起点有板,终点空闲,无板 if (stNode.Db2Vals[0] == 2 && targetNode.Db2Vals[0] == 1) { ctlTask = taskModel; break; } } return(ctlTask); }
/// <summary> /// 设备执行任务之前,检查是否路径被锁定,防止上下架冲突 /// </summary> /// <param name="curNode"></param> /// <param name="curTask"></param> /// <param name="reStr">若可用,返回0,1:路径被锁定,不可用,2:其它错误,-1:系统异常</param> /// <returns></returns> public int TaskLockCheck(FlowCtlBaseModel.CtlNodeBaseModel curNode, CtlDBAccess.Model.ControlTaskModel curTask, ref string reStr) { try { lock (pathCheckLock) { if (curTask == null) { reStr = "任务为空"; return(2); } CtlDBAccess.Model.MainControlTaskModel mainTask = mainCtlTaskBll.GetModel(curTask.MainTaskID); if (!wcsPathMap.Keys.Contains(mainTask.FlowPathKey)) { reStr = "不存在的路径:" + mainTask.FlowPathKey; return(2); } FlowCtlBaseModel.WCSFlowPathModel wcsPath = wcsPathMap[mainTask.FlowPathKey]; if (wcsPath.PathCata == "上架") { // List<CtlDBAccess.Model.MainControlTaskModel> lockedMaintaskList = GetLockedTaskList(curNode, "下架"); if (!NodeLockedBytask(curNode, "下架")) { return(0); } else { return(1); } } else if (wcsPath.PathCata == "下架") { //List<CtlDBAccess.Model.MainControlTaskModel> lockedMaintaskList = GetLockedTaskList(curNode, "上架"); if (!NodeLockedBytask(curNode, "上架")) { return(0); } else { return(1); } } else { return(0); } } } catch (Exception ex) { reStr = ex.ToString(); return(-1); } }
public bool BuildFlowPath(XElement root, ref string reStr) { try { IEnumerable <XElement> pathXES = root.Elements("Path"); foreach (XElement pathXE in pathXES) { FlowCtlBaseModel.WCSFlowPathModel wcsPath = new FlowCtlBaseModel.WCSFlowPathModel(); if (!wcsPath.BuildPath(pathXE, ref reStr)) { return(false); } foreach (FlowCtlBaseModel.WCSPathNodeModel wcsNode in wcsPath.NodeList) { FlowCtlBaseModel.CtlNodeBaseModel node = NodeManager.GetNodeByID(wcsNode.NodeID); if (node.DevCata == "堆垛机") { wcsNode.DevCata = "库房"; } else { wcsNode.DevCata = node.DevCata; } if (wcsNode.NodeFlag == "起点") { if (wcsNode.DevCata == "站台") { wcsPath.PathCata = "上架"; } else { wcsPath.PathCata = "下架"; } } } wcsPathMap[wcsPath.PathKey] = wcsPath; } return(true); } catch (Exception ex) { reStr = ex.ToString(); return(false); } }
private bool NodeLockedBytask(FlowCtlBaseModel.CtlNodeBaseModel curNode, string mainTaskCata) { foreach (string pathKey in wcsPathMap.Keys) { FlowCtlBaseModel.WCSFlowPathModel wcsPath = wcsPathMap[pathKey]; if (wcsPath.PathCata != mainTaskCata) { continue; } if (!wcsPath.ContainNode(curNode.NodeID)) { continue; } List <CtlDBAccess.Model.MainControlTaskModel> taskList = mainCtlTaskBll.GetModelList(string.Format("FlowPathKey ='{0}' and TaskStatus='执行中'", pathKey)); if (taskList != null && taskList.Count() > 0) { return(true); } } return(false); }
private void MainForm_Load(object sender, EventArgs e) { try { this.WindowState = FormWindowState.Maximized; this.btnPause.Enabled = false; this.labelVersion.Text = this.version; #region 数据库配置 string dbSrc = ConfigurationManager.AppSettings["DBSource"]; //CtlDBAccess.DBUtility.PubConstant.ConnectionString = string.Format(@"{0}Initial Catalog=ACEcams;User ID=sa;Password=123456;", dbSrc); string dbConn1 = string.Format(@"{0}Initial Catalog=AoyouEcams;User ID=sa;Password=123456;", dbSrc); CtlDBAccess.DBUtility.DbHelperSQL.SetConnstr(dbConn1); string dbConn2 = string.Format(@"{0}Initial Catalog=AoyouLocalMes;User ID=sa;Password=123456;", dbSrc); MesDBAccess.DBUtility.DbHelperSQL.SetConnstr(dbConn2); AsrsStorDBAcc.DbHelperSQL.SetConnstr(string.Format(@"{0}Initial Catalog=AoyouWMSDB;User ID=sa;Password=123456;", dbSrc)); #endregion string mesAddr = ConfigurationManager.AppSettings["MesSvcAddr"]; PrcsCtlModelsAoyou.WShelper.url = mesAddr; presenter = new MainPresenter(this); childList = new List <string>(); childViews = new List <BaseChildView>(); Console.SetOut(new TextBoxWriter(this.richTextBoxLog)); // corePresenter = new CtlcorePresenter(); this.labelUser.Text = "当前用户:" + this.userName; this.MainTabControl.DrawMode = TabDrawMode.OwnerDrawFixed; this.MainTabControl.Padding = new System.Drawing.Point(CLOSE_SIZE, CLOSE_SIZE); this.MainTabControl.DrawItem += new DrawItemEventHandler(this.tabControlMain_DrawItem); this.MainTabControl.MouseDown += new System.Windows.Forms.MouseEventHandler(this.tabControlMain_MouseDown); if (!presenter.SysCtlInit()) { return; } if (!LoadModules())//加载子模块 { MessageBox.Show("子模块加载错误"); return; } this.configView.BatteryCfgView.dlgtSndPalletCfg = presenter.SendDevlinePalletCfg; this.configView.BatteryCfgView.dlgtGetPalletCfg = presenter.ReadPalletCfgFromPlc; List <string> logSrcs = new List <string>(); logSrcs.AddRange(presenter.GetLogSrcList()); List <string> storLogSrcs = storageView.GetLogsrcList(); if (storLogSrcs != null) { logSrcs.AddRange(storLogSrcs); } logView.SetLogsrcList(logSrcs); presenter.SetLogRecorder(logView.GetLogrecorder()); AllocateModuleInface(); nodeMonitorView.Init(); this.nodeMonitorView.InitDevDic(presenter.DevCommManager.GetPLCConnStatDic()); this.nodeMonitorView.DevMonitorView.devCommMonitor = presenter.DevCommManager; string[] taskNodeIDS = new string[] { "1001", "1002", "1003", "1004", "1005", "1006", "6001", "6002", "6003" }; IDictionary <string, string> taskNodeMap = new Dictionary <string, string>(); foreach (string nodeID in taskNodeIDS) { FlowCtlBaseModel.CtlNodeBaseModel node = presenter.CtlNodeManager.GetNodeByID(nodeID); if (node != null) { taskNodeMap[nodeID] = node.NodeName; } } asrsCtlView.SetTaskNodeNames(taskNodeMap); string licenseFile = AppDomain.CurrentDomain.BaseDirectory + @"\NBSSLicense.lic"; this.licenseMonitor = new LicenseMonitor(this, 60000, licenseFile, "zzkeyFT1"); if (!this.licenseMonitor.StartMonitor()) { throw new Exception("license 监控失败"); } string reStr = ""; if (!this.licenseMonitor.IslicenseValid(ref reStr)) { MessageBox.Show(reStr); return; } presenter.LoadAsrsExtSvc(); //宿主状态监控服务 PublicMonitorSvc(); Console.WriteLine("系统初始化完成!"); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
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); } }