Beispiel #1
0
        public bool ConfigInit(ref string reStr)
        {
            nodeList      = new List <CtlNodeBaseModel>();
            threadList    = new List <ThreadBaseModel>();
            rfidList      = new List <IrfidRW>();
            barcodeRWList = new List <IBarcodeRW>();
            airDetectList = new List <IAirlossDetectDev>();
            printerList   = new List <IPrinterInfoDev>();
            plcRWList     = new List <IPlcRW>();
            IPlcRW          plcRW      = null;
            IPrinterInfoDev prienterRW = null;

            try
            {
                if (!PLProcessModel.SysCfgModel.LoadCfg(ref reStr))
                {
                    return(false);
                }
                string xmlCfgFile = System.AppDomain.CurrentDomain.BaseDirectory + @"data/DevConfigFTzj.xml";
                if (!File.Exists(xmlCfgFile))
                {
                    reStr = "系统配置文件:" + xmlCfgFile + " 不存在!";
                    return(false);
                }
                XElement root      = XElement.Load(xmlCfgFile);
                XElement runModeXE = root.Element("sysSet").Element("RunMode");
                string   simStr    = runModeXE.Attribute("sim").Value.ToString().ToUpper();
                if (simStr == "TRUE")
                {
                    NodeFactory.SimMode = true;
                    SysCfgModel.SimMode = true;
                }
                else
                {
                    NodeFactory.SimMode = false;
                    SysCfgModel.SimMode = false;
                }
                if (runModeXE.Attribute("mesTestMode") != null)
                {
                    if (runModeXE.Attribute("mesTestMode").Value.ToString().ToUpper() == "TRUE")
                    {
                        SysCfgModel.MesTestMode = true;
                    }
                    else
                    {
                        SysCfgModel.MesTestMode = false;
                    }
                }
                //1 解析结点信息
                XElement CtlnodeRoot = root.Element("CtlNodes");
                if (!ParseCtlnodes(CtlnodeRoot, ref reStr))
                {
                    return(false);
                }
                //2 解析通信设备信息
                if (NodeFactory.SimMode)
                {
                    plcRW = new PlcRWSim();
                    plcRWList.Add(plcRW);
                    prienterRW = new PrinterRWSim(1);
                    printerList.Add(prienterRW);
                    for (int i = 0; i < 13; i++)
                    {
                        int     rfidID = 0;// i + 1;
                        IrfidRW rfidRW = new rfidRWSim();
                        rfidRW.ReaderID = (byte)rfidID;
                        rfidList.Add(rfidRW);
                    }
                    for (int i = 0; i < 3; i++)
                    {
                        int        barcodeID  = i + 1;
                        IBarcodeRW barscanner = new BarcodeRWSim(barcodeID);
                        barcodeRWList.Add(barscanner);
                    }
                    for (int i = 0; i < 3; i++)
                    {
                        int airDetectID = i + 1;
                        IAirlossDetectDev airDetecter = new AirDetectRWSim(airDetectID);
                        airDetectList.Add(airDetecter);
                    }
                }
                else
                {
                    XElement commDevXERoot = root.Element("CommDevCfg");
                    if (!ParseCommDevCfg(commDevXERoot, ref reStr))
                    {
                        return(false);
                    }
                    plcRW = plcRWList[0];
                }

                //3 给节点分配设备读写接口对象

                for (int i = 0; i < nodeList.Count(); i++)
                {
                    CtlNodeBaseModel node = nodeList[i];
                    node.PlcRW   = plcRW;
                    node.SimMode = NodeFactory.SimMode;
                }
                for (int i = 0; i < nodeList.Count() - 1; i++)
                {
                    CtlNodeBaseModel node = nodeList[i];
                    node.RfidRW = rfidList[i];
                }
                prienterRW             = PrinterRWList[0];
                nodeList[0].BarcodeRW  = barcodeRWList[0];
                nodeList[12].BarcodeRW = barcodeRWList[1];
                nodeList[13].BarcodeRW = barcodeRWList[2];
                (nodeList[1] as NodeAirlossCheck).AirDetectRW = airDetectList[0];
                (nodeList[2] as NodeAirlossCheck).AirDetectRW = airDetectList[1];
                (nodeList[3] as NodeAirlossCheck).AirDetectRW = airDetectList[2];
                (nodeList[11] as NodeFaceCheck).PrienterRW    = prienterRW;



                //4 线程-结点分配
                XElement ThreadnodeRoot = root.Element("ThreadAlloc");
                if (!ParseTheadNodes(ThreadnodeRoot, ref reStr))
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                reStr = "加载系统配置文件出现异常:" + ex.ToString();
                return(false);
            }


            return(true);
        }
Beispiel #2
0
        public bool ProcessInit()
        {
            // nodeList = new List<CtlNodeBaseModel>();
            monitorNodeList     = new List <CtlNodeBaseModel>();
            this.nodeStatusList = new List <CtlNodeStatus>();
            //解析配置文件
            string reStr = "";
            //string xmlCfgFile = System.AppDomain.CurrentDomain.BaseDirectory + @"data/AcCfg.xml";


            string xmlCfgFile = System.AppDomain.CurrentDomain.BaseDirectory + @"data/AcCfg.xml";

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

            //1 通信设备创建、初始化
            hkAccessList = new List <IHKAccess>();
            if (SysCfg.SysCfgModel.SimMode)
            {
                plcRWs = new List <IPlcRW>();
                for (int i = 0; i < 4; 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;
            if (!asrsCtlPresenter.AsrsCommCfg())
            {
                return(false);
            }

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

            if (!re)
            {
                return(false);
            }
            return(true);
        }
Beispiel #3
0
        public bool ParseCommdev(XElement commDevRoot, ref string reStr)
        {
            try
            {
                //1 PLC
                plcRWs = new List <IPlcRW>();
                XElement plcRoot = commDevRoot.Element("PLCCfg");
                IEnumerable <XElement> plcXES = plcRoot.Elements("PLC");
                int plcSum = plcXES.Count();
                foreach (XElement plcXE in plcXES)
                {
                    string connStr = plcXE.Value.ToString();
                    int    db1Len = 100, db2Len = 100;
                    db1Len = int.Parse(plcXE.Attribute("db1Len").Value.ToString());
                    db2Len = int.Parse(plcXE.Attribute("db2Len").Value.ToString());
                    int         plcID   = int.Parse(plcXE.Attribute("id").Value.ToString());
                    EnumPlcCata plcCata = EnumPlcCata.FX5U;
                    if (plcXE.Attribute("cata") != null)
                    {
                        string strPlcCata = plcXE.Attribute("cata").Value.ToString();
                        plcCata = (EnumPlcCata)Enum.Parse(typeof(EnumPlcCata), strPlcCata);
                    }
                    if (SysCfg.SysCfgModel.SimMode)
                    {
                        PlcRWSim plcRW = new PlcRWSim();
                        plcRW.PlcID   = plcID;
                        plcRW.PlcRole = plcXE.Attribute("role").Value.ToString();
                        plcRWs.Add(plcRW);
                    }
                    else
                    {
                        PLCRwMCPro plcRW = new PLCRwMCPro(plcCata, db1Len, db2Len);
                        plcRW.PlcRole = plcXE.Attribute("role").Value.ToString();
                        // PLCRwMCPro2 plcRW = new PLCRwMCPro2(db1Len, db2Len);
                        plcRW.ConnStr = plcXE.Value.ToString();
                        plcRW.PlcID   = plcID;
                        plcRWs.Add(plcRW);
                    }
                }

                //2 rfid
                XElement rfidRootXE            = commDevRoot.Element("RfidCfg");
                IEnumerable <XElement> rfidXES = rfidRootXE.Elements("RFID");
                this.rfidRWs = new List <IrfidRW>();
                foreach (XElement rfidXE in rfidXES)
                {
                    byte     id           = byte.Parse(rfidXE.Attribute("id").Value.ToString());
                    string   addr         = rfidXE.Attribute("CommAddr").Value.ToString();
                    string[] strAddrArray = addr.Split(new string[] { ":" }, StringSplitOptions.RemoveEmptyEntries);
                    string   ip           = strAddrArray[0];
                    ushort   port         = ushort.Parse(strAddrArray[1]);
                    //WqwlRfidRW rfidRW = new WqwlRfidRW(EnumTag.TagEPCC1G2, id, ip, port);
                    WqRfidUdp rfidRW = new WqRfidUdp(EnumTag.TagEPCC1G2, id, ip, port, (uint)(9000 + id));


                    //SygoleHFReaderIF.HFReaderIF readerIF = new SygoleHFReaderIF.HFReaderIF();
                    //SgrfidRW rfidRW = new SgrfidRW(id);
                    //rfidRW.ReaderIF = readerIF;
                    //rfidRW.ReaderIF.ComPort = commPort;
                    rfidRWs.Add(rfidRW);
                }

                //3 条码枪
                XElement barcoderRootXE         = commDevRoot.Element("BarScannerCfg");
                IEnumerable <XElement> barcodes = barcoderRootXE.Elements("BarScanner");
                barcodeRWList = new List <IBarcodeRW>();
                foreach (XElement barcodeXE in barcodes)
                {
                    byte   id       = byte.Parse(barcodeXE.Attribute("id").Value.ToString());
                    string commPort = barcodeXE.Attribute("CommAddr").Value.ToString();
                    if (SysCfg.SysCfgModel.SimMode)
                    {
                        BarcodeRWSim barSim = new BarcodeRWSim(id);
                        barSim.Role = barcodeXE.Attribute("role").Value.ToString();
                        barcodeRWList.Add(barSim);
                    }
                    else
                    {
                        BarcodeRWHonevor barcodeReader = new BarcodeRWHonevor(id);
                        barcodeReader.TriggerMode = EnumTriggerMode.序命令触发;
                        barcodeReader.Role        = barcodeXE.Attribute("role").Value.ToString();
                        //System.IO.Ports.SerialPort comPort = new System.IO.Ports.SerialPort(commPort);
                        //comPort.BaudRate = 115200;
                        //comPort.DataBits = 8;
                        //comPort.StopBits = System.IO.Ports.StopBits.One;
                        //comPort.Parity = System.IO.Ports.Parity.None;
                        barcodeReader.ComPortObj.PortName = commPort;
                        barcodeReader.ComPortObj.BaudRate = 115200;
                        barcodeReader.ComPortObj.DataBits = 8;
                        barcodeReader.ComPortObj.StopBits = System.IO.Ports.StopBits.One;
                        barcodeReader.ComPortObj.Parity   = System.IO.Ports.Parity.None;
                        barcodeRWList.Add(barcodeReader);
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                reStr = "通信设备配置解析失败,发生系统异常:" + ex.ToString();
                return(false);
            }
        }