Example #1
0
        public void SetAsrsResManage(IAsrsManageToCtl asrsResManage)
        {
            this.asrsResourceManage = asrsResManage;
            NodeSwitch nodeSwitch = GetNodeByID("7001") as NodeSwitch;

            nodeSwitch.AsrsResManage = asrsResManage;
        }
Example #2
0
        public bool ProcessInit()
        {
            // nodeList = new List<CtlNodeBaseModel>();
            MesAcc = new YHMesWrapper();

            monitorNodeList     = new List <CtlNodeBaseModel>();
            this.nodeStatusList = new List <CtlNodeStatus>();
            //解析配置文件
            string reStr = "";
            //string xmlCfgFile = System.AppDomain.CurrentDomain.BaseDirectory + @"data/AcCfg.xml";
            XElement root = null;

            if (!SysCfg.SysCfgModel.LoadCfg(ref root, ref reStr))
            {
                Console.WriteLine("系统配置解析错误,{0}", reStr);
                return(false);
            }


            //1 通信设备创建、初始化
            hkAccessList = new List <IHKAccess>();
            if (SysCfg.SysCfgModel.SimMode)
            {
                plcRWs = new List <IPlcRW>();
                for (int i = 0; i < 5; i++)
                {
                    IPlcRW plcRW = new PlcRWSim();
                    plcRW.PlcID = i + 1;
                    plcRWs.Add(plcRW);
                }
                rfidRWs = new List <IrfidRW>();
                for (int i = 0; i < 13; i++)
                {
                    int     rfidID = i + 1;
                    IrfidRW rfidRW = new rfidRWSim();
                    rfidRW.ReaderID = (byte)rfidID;
                    rfidRWs.Add(rfidRW);
                }
                HKAccess hk = new HKAccess(1, "127.0.0.1", 13535);
                hkAccessList.Add(hk);
                hk = new HKAccess(2, "127.0.0.1", 13535);
                hkAccessList.Add(hk);
                if (!hk.Conn(ref reStr))
                {
                    Console.WriteLine(reStr);
                }
                string ocvDBConn = "Data Source = 192.168.100.20;Initial Catalog=SRANCH;User ID=L_Guest;Password=Guest@123;";;  //
                ocvAccess = new OcvAccess(ocvDBConn, 36);
            }
            else
            {
                XElement commDevXERoot = root.Element("CommDevCfg");
                if (!ParseCommDevCfg(commDevXERoot, ref reStr))
                {
                    //logRecorder.AddLog(new LogModel(objectName, "PLC初始化错误,"+reStr, EnumLoglevel.错误));
                    Console.WriteLine("通信设备错误," + reStr);
                    return(false);
                }
            }

            //2 控制节点初始化
            XElement CtlnodeRoot = root.Element("CtlNodes");

            if (!ParseCtlnodes(CtlnodeRoot, ref reStr))
            {
                logRecorder.AddLog(new LogModel(objectName, "节点初始化错误," + reStr, EnumLoglevel.错误));
                return(false);
            }
            foreach (AsrsCtlModel asrsModel in asrsCtlPresenter.AsrsCtls)
            {
                monitorNodeList.Add(asrsModel.StackDevice);
                monitorNodeList.AddRange(asrsModel.Ports.ToArray());
            }

            //3 工位控制线程初始化
            this.threadList = new List <ThreadRunModel>();
            XElement ThreadnodeRoot = root.Element("ThreadAlloc");

            if (!ParseTheadNodes(ThreadnodeRoot, ref reStr))
            {
                logRecorder.AddLog(new LogModel(objectName, "任务分配错误," + reStr, EnumLoglevel.错误));
                return(false);
            }
            NodeSwitch switchNode = GetNodeByID("7001") as NodeSwitch;
            List <AsrsControl.AsrsPortalModel> targetPorts = new List <AsrsPortalModel>();

            foreach (string portID in switchNode.TargetPortIDs)
            {
                AsrsPortalModel portObj = GetNodeByID(portID) as AsrsControl.AsrsPortalModel;
                targetPorts.Add(portObj);
            }
            switchNode.TargetPorts = targetPorts;

            foreach (ThreadRunModel threadObj in threadList)
            {
                threadObj.LogRecorder = logRecorder;
            }

            for (int i = 0; i < this.monitorNodeList.Count(); i++)
            {
                CtlNodeBaseModel node = this.monitorNodeList[i];
                node.LogRecorder = this.logRecorder;
                this.nodeStatusList.Add(node.CurrentStat);
            }

            //ThreadRunModel palletBindThread = new ThreadRunModel("工装板绑定");
            //palletBindThread.TaskInit();
            //CtlNodeBaseModel palletBindNode = GetNodeByID("6001");
            //if(palletBindNode != null && palletBindNode.NodeEnabled)
            //{
            //    palletBindThread.AddNode(palletBindNode);
            //}
            //this.threadList.Add(palletBindThread);

            //4 plc通信线程初始化

            //5 历史数据清理线程
            historyDataClearThread = new ThreadBaseModel("历史数据集清理");

            historyDataClearThread.SetThreadRoutine(ClearHistoryLoop);
            historyDataClearThread.LoopInterval = 60000;
            historyDataClearThread.TaskInit();


            //5 通信对象分配
            asrsCtlPresenter.PlcRWs     = this.plcRWs;
            asrsCtlPresenter.RfidRWs    = this.rfidRWs;
            asrsCtlPresenter.BarcodeRWs = this.barcodeRWList;
            foreach (AsrsCtlModel asrsCtl in asrsCtlPresenter.AsrsCtls)
            {
                asrsCtl.MesAcc = this.MesAcc;
                if (asrsCtl.HouseName == AsrsModel.EnumStoreHouse.A1库房.ToString())
                {
                    asrsCtl.dlgtGetTaskTorun = GetCheckoutOfA1;
                }
            }
            if (!asrsCtlPresenter.AsrsCommCfg())
            {
                return(false);
            }

            //view.InitNodeMonitorview();
            bool re = asrsCtlPresenter.DevStatusRestore();

            if (!re)
            {
                return(false);
            }
            return(true);
        }
Example #3
0
        private bool ParseCtlnodes(XElement CtlnodeRoot, ref string reStr)
        {
            if (CtlnodeRoot == null)
            {
                reStr = "系统配置文件错误,不存在CtlNodes节点";
                return(false);
            }
            try
            {
                IEnumerable <XElement> nodeXEList =
                    from el in CtlnodeRoot.Elements()
                    where el.Name == "Node"
                    select el;
                foreach (XElement el in nodeXEList)
                {
                    string           className = (string)el.Attribute("className");
                    CtlNodeBaseModel ctlNode   = null;
                    switch (className)
                    {
                    case "NbProcessCtl.NodePalletBind":
                    {
                        ctlNode = new NodePalletBind();

                        break;
                    }

                    case "NbProcessCtl.NodeOcv":
                    {
                        ctlNode = new NodeOcv();
                        break;
                    }

                    case "NbProcessCtl.NodeGrasp":
                    {
                        NodeGrasp graspNode = new NodeGrasp();
                        // graspNode.MesAcc = this.mesAcc;
                        ctlNode = graspNode;
                        break;
                    }

                    case "NbProcessCtl.NodeVirStation":
                    {
                        ctlNode = new NodeVirStation();
                        break;
                    }

                    case "NbProcessCtl.NodeSwitch":
                    {
                        ctlNode = new NodeSwitch();
                        break;
                    }

                    default:
                        break;
                    }
                    if (ctlNode != null)
                    {
                        ctlNode.MesAcc = this.MesAcc;
                        if (!ctlNode.BuildCfg(el, ref reStr))
                        {
                            return(false);
                        }
                        if (className == "NbProcessCtl.NodePalletBind")
                        {
                            NodePalletBind bndNode = ctlNode as NodePalletBind;
                            bndNode.hkAccess = GetHKAccessByID(bndNode.HkServerID);
                        }
                        if (className == "NbProcessCtl.NodeGrasp")
                        {
                            NodeGrasp graspNode = ctlNode as NodeGrasp;
                            graspNode.OcvAccess = ocvAccess;
                        }
                        if (className == "NbProcessCtl.NodeSwitch")
                        {
                            NodeSwitch switchNode = ctlNode as NodeSwitch;
                            switchNode.OcvAccess = ocvAccess;
                        }
                        ctlNode.PlcRW = GetPlcByID(ctlNode.PlcID); // this.plcRWs[2];
                        if (ctlNode.RfidID > 0)
                        {
                            ctlNode.RfidRW = GetRfidByID(ctlNode.RfidID);
                        }
                        if (!SysCfg.SysCfgModel.SimMode)
                        {
                            //ctlNode.RfidRW = GetRfidByID((byte)ctlNode.RfidID);
                            if (ctlNode.BarcodeID > 0)
                            {
                                ctlNode.BarcodeRW = GetBarcoderRWByID(ctlNode.BarcodeID);
                            }
                        }

                        //Console.WriteLine(ctlNode.NodeName + ",ID:" + ctlNode.NodeID + "创建成功!");
                        this.monitorNodeList.Add(ctlNode);
                    }
                }
            }
            catch (Exception ex)
            {
                reStr = ex.ToString();
                return(false);
            }

            return(true);
        }