private bool UpdateSwitchLineMods(int switchLineNo, string[] mods) { PLNodesBll plnodeBll = new PLNodesBll(); PLNodesModel plNode = plnodeBll.GetModel("OPC001"); if (plNode == null) { MessageBox.Show("不存在的工位号:OPC001"); return(false); } string strMods = ""; for (int i = 0; i < mods.Count(); i++) { strMods += (mods[i] + ","); } if (switchLineNo == 1) { plNode.tag1 = strMods; } else if (switchLineNo == 2) { plNode.tag2 = strMods; } else if (switchLineNo == 3) { plNode.tag3 = strMods; } else { plNode.tag4 = strMods; } return(plnodeBll.Update(plNode)); }
private string[] GetSwitchLineMods(int switchLineNo) { PLNodesBll plnodeBll = new PLNodesBll(); PLNodesModel plNode = plnodeBll.GetModel("OPC001"); if (plNode == null) { MessageBox.Show("不存在的工位号:OPC001"); return(null); } string[] modExistArray = null; if (switchLineNo == 1) { modExistArray = plNode.tag1.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); } else if (switchLineNo == 2) { modExistArray = plNode.tag2.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); } else if (switchLineNo == 3) { modExistArray = plNode.tag3.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); } else { modExistArray = plNode.tag4.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); } return(modExistArray); }
private bool RefreshPlNodes(ref string reStr) { try { PLNodesBll plNodesBll = new PLNodesBll(); foreach (CtlNodeBaseModel ctlNode in nodeList) { ctlNode.plNodeModel = plNodesBll.GetModel(ctlNode.NodeID); } return(true); } catch (Exception ex) { reStr = ex.Message; return(false); } }
private bool UploadMesLogic(int swichDw, string barcode, ref bool isNG, ref string reStr) { PLNodesBll plNodesBll = new PLNodesBll(); plNodeModel = plNodesBll.GetModel(this.nodeID); isNG = false; string swichDwAll = ""; switch (swichDw) { case 1: { swichDwAll = plNodeModel.tag1.ToUpper(); break; } case 2: { swichDwAll = plNodeModel.tag2.ToUpper(); break; } case 3: { swichDwAll = plNodeModel.tag3.ToUpper(); break; } case 4: { swichDwAll = plNodeModel.tag4.ToUpper(); break; } default: break; } //在分档之前要判断打螺丝的码头数据上传MES是否成功 if (!swichDwAll.ToUpper().Contains(barcode.ToUpper()))//没有分档的 { Console.WriteLine(this.nodeName + "debug9"); int uploadStatus = UploadMesScrewData(this.rfidUID, barcode, ref reStr); if (uploadStatus == 0)//上报码头数据 { this.logRecorder.AddDebugLog(this.nodeName, "上传打螺丝数据成功!" + reStr); } else if (uploadStatus == 1) { this.logRecorder.AddDebugLog(this.nodeName, "上传打螺丝数据成功!,返回NG" + reStr); isNG = true; } else { Console.WriteLine(this.nodeName + ",上传打螺丝数据失败:" + reStr); return(false); } this.TxtLogRecorder.WriteLog("上传MES数据:工装板号:" + this.rfidUID + ",模块号:" + barcode); } return(true); }
protected override void ExeRfidBusinessAB() { if (this.rfidRWList == null || this.rfidRWList.Count() < 1) { return; } PLNodesBll plNodeBll = new PLNodesBll(); if (this.db2Vals[1] == 2) { //A通道 if (string.IsNullOrWhiteSpace(this.rfidUIDA)) { IrfidRW rw = null; if (SysCfgModel.SimMode) { this.rfidUIDA = this.SimRfidUID; } else if (this.rfidRWList.Count > 0) { rw = this.rfidRWList[0]; this.rfidUIDA = rw.ReadUID(); } if (string.IsNullOrWhiteSpace(this.rfidUIDA)) { //读RFID失败 if (this.db1ValsToSnd[0] != 3) { //logRecorder.AddDebugLog(nodeName, "读RFID失败"); db1ValsToSnd[0] = 3; } else { db1ValsToSnd[0] = 1; } Thread.Sleep(1000); this.currentStat.Status = EnumNodeStatus.无法识别; this.currentStat.StatDescribe = "读A通道RFID失败:" + db1ValsToSnd[0].ToString(); this.currentTaskDescribe = "读A通道RFID失败:" + db1ValsToSnd[0].ToString(); } else { this.plNodeModel.tag1 = this.rfidUIDA; plNodeBll.Update(this.plNodeModel); // logRecorder.AddDebugLog(nodeName, string.Format("A通道读到RFID:{0}", this.rfidUIDA)); if (this.nodeID == "OPA005") { if (IsEmptyPallet(this.rfidUIDA) == true) { this.db1ValsToSnd[0] = 4; } else { this.db1ValsToSnd[0] = 2; } } else { this.db1ValsToSnd[0] = 2; } } } else { // logRecorder.AddDebugLog(nodeName, string.Format("A通道读到RFID:{0}", this.rfidUIDA)); if (this.nodeID == "OPA005") { if (IsEmptyPallet(this.rfidUIDA) == true) { this.db1ValsToSnd[0] = 4; } else { this.db1ValsToSnd[0] = 2; } } else { this.db1ValsToSnd[0] = 2; } } } else if (this.db2Vals[1] == 1) { this.db1ValsToSnd[0] = 1; this.plNodeModel.tag1 = ""; plNodeBll.Update(this.plNodeModel); } if (this.db2Vals[2] == 2) { //B通道 IrfidRW rw = null; if (string.IsNullOrWhiteSpace(this.rfidUIDB)) { if (SysCfgModel.SimMode) { this.rfidUIDB = this.SimRfidUID; } else if (this.rfidRWList.Count > 1) { rw = this.rfidRWList[1]; this.rfidUIDB = rw.ReadUID(); } if (string.IsNullOrWhiteSpace(this.rfidUIDB)) { if (this.db1ValsToSnd[1] != 3) { //logRecorder.AddDebugLog(nodeName, "读RFID失败"); db1ValsToSnd[1] = 3; } else { db1ValsToSnd[1] = 1; } Thread.Sleep(1000); this.currentStat.Status = EnumNodeStatus.无法识别; this.currentStat.StatDescribe = "读B通道RFID失败:" + db1ValsToSnd[1].ToString(); this.currentTaskDescribe = "读B通道RFID失败:" + db1ValsToSnd[1].ToString(); } else { this.plNodeModel.tag2 = this.rfidUIDB; plNodeBll.Update(this.plNodeModel); // logRecorder.AddDebugLog(nodeName, string.Format("B通道读到RFID:{0}", this.rfidUIDB)); // logRecorder.AddDebugLog(nodeName, string.Format("A通道读到RFID:{0}", this.rfidUIDA)); if (this.nodeID == "OPA005") { if (IsEmptyPallet(this.rfidUIDB) == true) { this.db1ValsToSnd[1] = 4; } else { this.db1ValsToSnd[1] = 2; } } else { this.db1ValsToSnd[1] = 2; } } } else { // logRecorder.AddDebugLog(nodeName, string.Format("A通道读到RFID:{0}", this.rfidUIDA)); if (this.nodeID == "OPA005") { if (IsEmptyPallet(this.rfidUIDB) == true) { this.db1ValsToSnd[1] = 4; } else { this.db1ValsToSnd[1] = 2; } } else { this.db1ValsToSnd[1] = 2; } } } else if (this.db2Vals[2] == 1) { this.db1ValsToSnd[1] = 1; this.plNodeModel.tag2 = ""; plNodeBll.Update(this.plNodeModel); } }
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); } }
protected override void ExeRfidBusinessAB() { if (this.rfidRWList == null || this.rfidRWList.Count() < 1) { return; } PLNodesBll plNodeBll = new PLNodesBll(); if (this.db2Vals[1] == 2) { //A通道 if (string.IsNullOrWhiteSpace(this.rfidUIDA)) { IrfidRW rw = null; if (SysCfgModel.SimMode) { this.rfidUIDA = this.SimRfidUID; } else if (this.rfidRWList.Count > 0) { rw = this.rfidRWList[0]; this.rfidUIDA = rw.ReadUID(); } if (string.IsNullOrWhiteSpace(this.rfidUIDA)) { //读RFID失败 if (this.db1ValsToSnd[0] != 3) { //logRecorder.AddDebugLog(nodeName, "读RFID失败"); db1ValsToSnd[0] = 3; } else { db1ValsToSnd[0] = 1; } Thread.Sleep(1000); this.currentStat.Status = EnumNodeStatus.无法识别; this.currentStat.StatDescribe = "读A通道RFID失败"; this.currentTaskDescribe = "读A通道RFID失败"; } else { this.plNodeModel.tag1 = this.rfidUIDA; plNodeBll.Update(this.plNodeModel); if (this.db1ValsToSnd[0] != 2) { //if (WriteProductsToWelder(1, rfidUIDA)) //{ // logRecorder.AddDebugLog(nodeName, string.Format("A通道读到RFID:{0}", this.rfidUIDA)); // Thread.Sleep(5000); // this.db1ValsToSnd[0] = 2; //} //else //{ // this.db1ValsToSnd[0] = 2; //} this.db1ValsToSnd[0] = 2; } //if (!SysCfgModel.SimMode) //{ // (rw as DevAccess.RfidCF).ClearBufUID(); //} } } else { this.db1ValsToSnd[0] = 2; } } else if (this.db2Vals[1] == 1) { this.rfidUIDA = ""; this.db1ValsToSnd[0] = 1; this.plNodeModel.tag1 = ""; plNodeBll.Update(this.plNodeModel); } if (this.db2Vals[2] == 2) { //B通道 IrfidRW rw = null; if (string.IsNullOrWhiteSpace(this.rfidUIDB)) { if (SysCfgModel.SimMode) { this.rfidUIDB = this.SimRfidUID; } else if (this.rfidRWList.Count > 1) { rw = this.rfidRWList[1]; this.rfidUIDB = rw.ReadUID(); } if (string.IsNullOrWhiteSpace(this.rfidUIDB)) { if (this.db1ValsToSnd[1] != 3) { //logRecorder.AddDebugLog(nodeName, "读RFID失败"); db1ValsToSnd[1] = 3; } else { db1ValsToSnd[1] = 1; } Thread.Sleep(1000); this.currentStat.Status = EnumNodeStatus.无法识别; this.currentStat.StatDescribe = "读B通道RFID失败"; this.currentTaskDescribe = "读B通道RFID失败"; } else { this.plNodeModel.tag2 = this.rfidUIDB; plNodeBll.Update(this.plNodeModel); if (this.db1ValsToSnd[1] != 2) { if (WriteProductsToWelder(2, rfidUIDB)) { logRecorder.AddDebugLog(nodeName, string.Format("B通道读到RFID:{0}", this.rfidUIDB)); Thread.Sleep(5000); this.db1ValsToSnd[1] = 2; } else { //rfidUIDB = ""; this.db1ValsToSnd[1] = 2; } } //if (!SysCfgModel.SimMode) //{ // (rw as DevAccess.RfidCF).ClearBufUID(); //} } } else { this.db1ValsToSnd[1] = 2; } } else if (this.db2Vals[2] == 1) { this.rfidUIDB = ""; this.db1ValsToSnd[1] = 1; this.plNodeModel.tag2 = ""; plNodeBll.Update(this.plNodeModel); } }