public void CommDevConnect()
        {
            try
            {
                view.WelcomePopup();
                //DelegateDevConn dlgt = new DelegateDevConn(AsyCommDevConnect);
                //IAsyncResult ar = dlgt.BeginInvoke(CallbackDevConnFinished,dlgt);
                AsyCommDevConnect();

                view.WelcomeClose();
            }
            catch (Exception ex)
            {
                view.PopupMes(ex.ToString());
            }
        }
        public bool Init(ref string reStr)
        {
            try
            {
                localMesBasebll   = new LOCAL_MES_STEP_INFOBll();
                localMesDetailbll = new LOCAL_MES_STEP_INFO_DETAILBll();
                productCfgBll     = new ProductSizeCfgBll();
                LineNodes.NodeFactory nodeFactory = new LineNodes.NodeFactory();


                if (!nodeFactory.ConfigInit(ref reStr))
                {
                    return(false);
                }
                this.plcRWs       = nodeFactory.PlcRWList;
                this.rfidRWs      = nodeFactory.RfidRWList;
                this.barcodeRWs   = nodeFactory.BarcodeRWList;
                this.airDetectRWs = nodeFactory.AirDetectRWList;
                this.printerRWs   = nodeFactory.PrinterRWList;
                this.nodeList     = nodeFactory.GetNodes(ref reStr);
                this.threadList   = nodeFactory.GetThreadAlloc(ref reStr);
                foreach (ThreadBaseModel threadObj in this.threadList)
                {
                    threadObj.LogRecorder = logRecorder;
                }
                //  this.threadList = new List<ThreadRunModel>();

                ////线程1
                //ThreadRunModel threadObj = new ThreadRunModel(1, "线程1:" );
                //threadObj.LoopInterval = 100;
                //threadObj.LogRecorder = logRecorder;
                //threadObj.AddNode(node);
                //if (!threadObj.TaskInit(ref reStr))
                //{
                //    Console.WriteLine(reStr);
                //}
                //this.threadList.Add(threadObj);

                //线程2

                //for (int i = 0; i < nodeList.Count(); i++)
                //{
                //    CtlNodeBaseModel node = nodeList[i];

                //    ThreadRunModel threadObj = new ThreadRunModel(i + 1, "线程:" + node.NodeName);
                //    threadObj.LoopInterval = 100;

                //    threadObj.LogRecorder = logRecorder;
                //    threadObj.AddNode(node);
                //    if (!threadObj.TaskInit(ref reStr))
                //    {
                //        Console.WriteLine(reStr);
                //    }
                //    this.threadList.Add(threadObj);
                //}

                //for (int i = 0; i < nodeList.Count(); i++)
                //{
                //    CtlNodeBaseModel node = nodeList[i];
                //    node.PlcRW = this.plcRWs[0];
                //    node.SimMode = NodeFactory.SimMode;
                //}

                if (!NodeFactory.SimMode)
                {
                    CommDevConnect();//通信设备连接
                }

                this.nodeStatusList = new List <CtlNodeStatus>();
                svcNodeStatusList   = new List <MonitorSvcNodeStatus>();
                foreach (CtlNodeBaseModel node in this.nodeList)
                {
                    this.nodeStatusList.Add(node.CurrentStat);
                    node.LogRecorder = logRecorder;
                    MonitorSvcNodeStatus svcStat = new MonitorSvcNodeStatus();
                    svcStat.NodeName       = node.NodeName;
                    svcStat.ProductBarcode = node.CurrentStat.ProductBarcode;
                    svcStat.StatDescribe   = node.CurrentStat.StatDescribe;
                    svcStat.Status         = node.CurrentStat.Status.ToString();
                    svcNodeStatusList.Add(svcStat);
                }

                mainThread = new ThreadBaseModel(1, "业务线程");
                mainThread.LoopInterval = 10;
                mainThread.SetThreadRoutine(new DelegateThreadRoutine(BusinessLoop));
                if (!mainThread.TaskInit(ref reStr))
                {
                    logRecorder.AddLog(new LogModel(objectName, reStr, EnumLoglevel.错误));

                    return(false);
                }


                historyDataClearThread = new ThreadBaseModel(2, "日志清理线程");
                historyDataClearThread.LoopInterval = 60000;//1分钟清理一次
                historyDataClearThread.SetThreadRoutine(ClearLogLoop);
                if (!historyDataClearThread.TaskInit(ref reStr))
                {
                    logRecorder.AddLog(new LogModel(objectName, reStr, EnumLoglevel.错误));
                }
                printerLoopThread = new ThreadBaseModel(3, "贴标队列处理线程");
                printerLoopThread.LoopInterval = 500;//500
                printerLoopThread.SetThreadRoutine(PrinterQueueLoop);
                printerLoopThread.TaskInit(ref reStr);
                //   Console.WriteLine("P1");

                view.InitNodeMonitorview(this.nodeList);
                //   Console.WriteLine("P2");
                //宿主WCF服务
                Uri                 _baseAddress = new Uri("http://localhost:8733/ZZ/LineNodes/NodeMonitorSvc/");
                EndpointAddress     _Address     = new EndpointAddress(_baseAddress);
                BasicHttpBinding    _Binding     = new BasicHttpBinding();
                ContractDescription _Contract    = ContractDescription.GetContract(typeof(LineNodes.INodeMonitorSvc));
                ServiceEndpoint     endpoint     = new ServiceEndpoint(_Contract, _Binding, _Address);
                NodeMonitorSvc      monitorSvc   = new NodeMonitorSvc();

                monitorSvc.dlgtNodeStatus += GetSvcNodeStatus;
                monitorSvc.dlgtRunningDev += GetRunningDetectdevs;

                ServiceHost host = new ServiceHost(monitorSvc, _baseAddress);
                //添加终结点ABC
                host.Description.Endpoints.Add(endpoint);
                //启用元数据交换
                ServiceMetadataBehavior meta = new ServiceMetadataBehavior();

                meta.HttpGetEnabled = true;
                host.Description.Behaviors.Add(meta);
                host.Open();
                //  Console.WriteLine("P3");
                return(true);
            }
            catch (Exception ex)
            {
                view.PopupMes(ex.ToString());
                return(false);
            }
        }