public void AddProductCfg(ProductSizeCfgModel m) { if (productCfgBll.Exists(m.productCataCode)) { view.ShowPopupMes("已经存在" + m.productCataCode); return; } if (!productCfgBll.Add(m)) { LogModel log = new LogModel("产品型号配置", "添加型号配置失败", EnumLoglevel.错误); logRecorder.AddLog(log); } else { DataTable dt = productCfgBll.GetAllList().Tables[0]; view.DispProductCfgList(dt); } }
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); }
public bool ProcessInit(ref string reStr) { try { this.devList = new List <CtlDevBaseModel>(); this.nodeList = new List <CtlNodeBaseModel>(); this.nodeStatusList = new List <CtlNodeStatus>(); threadList = new List <ThreadBaseModel>(); this.rfidRWs = new List <IrfidRW>(); this.barcodeRWs = new List <IBarcodeRW>(); //this.printerRWs = new List<IPrinterInfoDev>(); this.plcRWs = new List <IPlcRW>(); this.ccdRWs = new List <MingmeiDeviceAcc>(); string xmlCfgFile = System.AppDomain.CurrentDomain.BaseDirectory + @"data/PLConfig.xml"; if (!File.Exists(xmlCfgFile)) { reStr = "系统配置文件:" + xmlCfgFile + " 不存在!"; return(false); } if (!PLProcessModel.SysCfgModel.LoadCfg(xmlCfgFile, ref reStr)) { return(false); } XElement root = XElement.Load(xmlCfgFile); //1 解析通信设备信息 XElement commDevXERoot = root.Element("CommDevCfg"); if (!ParseCommDevCfg(commDevXERoot, ref reStr)) { // return false; } //2 解析结点信息 XElement lineRoot = root.Element("LineCfg"); if (!ParsePLines(lineRoot, ref reStr)) { return(false); } foreach (CtlLineBaseModel line in lineList) { if (!line.AllocCommObj(rfidRWs, barcodeRWs, plcRWs, ccdRWs, ref reStr)) { return(false); } } if (lineList != null && lineList.Count() > 0) { foreach (CtlLineBaseModel line in lineList) { nodeList.AddRange(line.NodeList); devList.AddRange(line.DevList); } } PLNodesBll plNodeBll = new PLNodesBll(); foreach (CtlDevBaseModel dev in this.devList) { dev.LogRecorder = logRecorder; } foreach (CtlNodeBaseModel node in this.nodeList) { this.nodeStatusList.Add(node.CurrentStat); node.LogRecorder = logRecorder; if (!plNodeBll.Exists(node.NodeID)) { PLNodesModel plNode = new PLNodesModel(); plNode.nodeID = node.NodeID; plNode.nodeName = node.NodeName; plNode.enableRun = true; plNode.checkRequired = true; plNode.tag1 = ""; plNode.tag2 = ""; plNode.tag3 = ""; plNode.tag4 = ""; plNode.tag5 = ""; plNodeBll.Add(plNode); node.plNodeModel = plNode; } else { PLNodesModel plNode = plNodeBll.GetModel(node.NodeID); node.plNodeModel = plNode; } } //3 给节点分配设备读写接口对象 //for (int i = 0; i < nodeList.Count(); i++) //{ // CtlNodeBaseModel node = nodeList[i]; // node.SimMode = SysCfgModel.SimMode; //} // prienterRW = this.printerRWs[0]; //(GetNodeByID("8001") as NodePack).PrienterRW = prienterRW; //4 线程-结点分配 XElement ThreadnodeRoot = root.Element("ThreadAlloc"); if (!ParseTheadNodes(ThreadnodeRoot, ref reStr)) { return(false); } foreach (ThreadBaseModel threadObj in this.threadList) { threadObj.LogRecorder = logRecorder; } if (!SysCfgModel.SimMode) { CommDevConnect();//通信设备连接 } foreach (CtlNodeBaseModel node in nodeList) { if (!node.DevStatusRestore()) { reStr = "恢复投产位状态失败"; //logRecorder.AddLog(new LogModel(objectName, reStr, EnumLoglevel.错误)); logRecorder.AddDebugLog(node.NodeName, reStr); //return false; } } SetMesconnStat(); mainThread = new ThreadBaseModel(1, "业务线程"); mainThread.LoopInterval = 100; 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 = 5000;//5秒清理一次 historyDataClearThread.SetThreadRoutine(ClearLogLoop); if (!historyDataClearThread.TaskInit(ref reStr)) { logRecorder.AddLog(new LogModel(objectName, reStr, EnumLoglevel.错误)); } devWarnMonitorThread = new ThreadBaseModel(3, "设备报警数据采集线程"); devWarnMonitorThread.LoopInterval = 1000; devWarnMonitorThread.SetThreadRoutine(DevMonitorLoop); devWarnMonitorThread.TaskInit(ref reStr); //mesTopMonitorThread = new ThreadBaseModel(4,"mes停机监控"); //mesTopMonitorThread.LoopInterval = 1000; //mesTopMonitorThread.SetThreadRoutine(MesStopstatMonitor); //mesTopMonitorThread.TaskInit(ref reStr); for (int i = 0; i < lineList.Count(); i++) { view.InitLineMonitor(i + 1, lineList[i]); } this.fxjDataUploadThread = new ThreadBaseModel(4, "分选机上报MES线程"); if (SysCfgModel.SimMode == true) { this.fxjDataUploadThread.LoopInterval = 1000 * 5;//测试5秒 } else { this.fxjDataUploadThread.LoopInterval = 1000 * 60 * 5;//5分钟上报一次 //this.fxjDataUploadThread.LoopInterval = 1000 * 10;//5分钟上报一次 } this.fxjDataUploadThread.SetThreadRoutine(FXJDataUploadToMesHandler); if (!this.fxjDataUploadThread.TaskInit(ref reStr)) { logRecorder.AddLog(new LogModel(objectName, "分选机线程初始化失败:" + reStr, EnumLoglevel.错误)); } offlineDataUploadThread = new ThreadBaseModel(5, "离线数据上报MES线程"); if (SysCfgModel.SimMode == true) { this.offlineDataUploadThread.LoopInterval = 1000 * 5;//测试5秒 } else { this.offlineDataUploadThread.LoopInterval = 1000 * 60 * 5;//5分钟上报间隔 } this.offlineDataUploadThread.SetThreadRoutine(OfflineDataUploadMesHandler); if (!this.offlineDataUploadThread.TaskInit(ref reStr)) { logRecorder.AddLog(new LogModel(objectName, "离线数据上报MES线程:" + reStr, EnumLoglevel.错误)); } return(true); } catch (Exception ex) { reStr = ex.ToString(); return(false); } }
public bool CtlInit() { // batModbll = new BatteryModuleBll(); //1 通信设备初始化PLC, asrsCtls = new List <AsrsCtlModel>(); this.asrsPorts = new List <AsrsPortalModel>(); //2 控制节点初始化 //解析配置文件 string reStr = ""; //string xmlCfgFile = System.AppDomain.CurrentDomain.BaseDirectory + @"data/AcCfg.xml"; //if (!File.Exists(xmlCfgFile)) //{ // reStr = "系统配置文件:" + xmlCfgFile + " 不存在!"; // logRecorder.AddLog(new LogModel(objectName, reStr, EnumLoglevel.错误)); // return false; //} XElement root = null; if (!SysCfg.SysCfgModel.LoadCfg(ref root, ref reStr)) { Console.WriteLine("系统配置解析错误,{0}", reStr); return(false); } // XElement root = XElement.Load(xmlCfgFile); XElement CtlnodeRoot = root.Element("AsrsNodes"); if (!ParseCtlnodes(CtlnodeRoot, ref reStr)) { Console.WriteLine(reStr); return(false); } //3 分配通信对象 foreach (AsrsCtlModel asrs in asrsCtls) { if (!asrs.Init()) { logRecorder.AddLog(new LogModel(objectName, asrs.NodeName + "初始化错误", EnumLoglevel.错误)); return(false); } this.asrsPorts.AddRange(asrs.Ports.ToArray()); asrs.SetLogrecorder(logRecorder); if (asrs.HouseName == EnumStoreHouse.B1库房.ToString()) { asrs.FillTaskTyps(new List <SysCfg.EnumAsrsTaskType> { SysCfg.EnumAsrsTaskType.产品入库, SysCfg.EnumAsrsTaskType.产品出库, SysCfg.EnumAsrsTaskType.移库 }); } else { asrs.FillTaskTyps(new List <SysCfg.EnumAsrsTaskType> { SysCfg.EnumAsrsTaskType.产品入库, SysCfg.EnumAsrsTaskType.产品出库, SysCfg.EnumAsrsTaskType.移库, SysCfg.EnumAsrsTaskType.空框入库, SysCfg.EnumAsrsTaskType.空框出库 }); } } return(true); }
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); } }