Ejemplo n.º 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);
        }