protected bool ExeBindC(ref string reStr) { if (!ExeBusinessC(ref reStr)) { return(false); } switch (currentTaskPhase) { case 1: { if (!RfidReadC()) { break; } LogRecorder.AddDebugLog(nodeName, string.Format("RFID:{0}", this.rfidUID)); currentTaskPhase++; this.TxtLogRecorder.WriteLog("读取工装板号成功:" + this.rfidUID); break; } case 2: { db1ValsToSnd[2] = 2; currentTaskDescribe = "流程完成"; this.currentTask.TaskPhase = this.currentTaskPhase; this.ctlTaskBll.Update(this.currentTask); this.currentTask.TaskStatus = EnumTaskStatus.已完成.ToString(); this.TxtLogRecorder.WriteLog("此工位加工处理完成!"); break; } default: break; } return(true); }
private bool ExeBusinessPLC3(ref string reStr) { //if(!plcRW2.ReadMultiDB("D9000", 2, ref barcodeDb2)) //{ // Console.WriteLine("{0}打码交互,读DB2数据区失败",nodeName); // return false; //} if (this.db2Vals[0] == 1) { // barcodeTaskPhase = 1; currentTaskPhase = 1; M_SN = ""; this.db1ValsToSnd[0] = 1; this.db1ValsToSnd[1] = 1; } switch (currentTaskPhase) { case 1: { Console.WriteLine("{0}开始从MES申请模块码", nodeName); this.currentTaskDescribe = string.Format("{0}开始从MES申请模块码", nodeName); if (!ModuleCodeRequire(ref M_SN, ref reStr)) { Console.WriteLine(this.nodeName + "请求模块二维码失败!" + reStr); //LogRecorder.AddDebugLog(nodeName, "ModuleCodeRequire FALSE" + "," + reStr); this.db1ValsToSnd[0] = 3; this.currentTaskDescribe = "申请模块码失败" + reStr; break; } else { this.logRecorder.AddDebugLog(this.nodeName, "请求模块二维码成功!" + reStr); } if (!plcRW.WriteDB("D9000", 0)) { Console.WriteLine("复位D9000 失败"); plcRW.CloseConnect(); plcRW.ConnectPLC(ref reStr); break; } LogRecorder.AddDebugLog(nodeName, "申请到模块码:" + M_SN); this.TxtLogRecorder.WriteLog("工位申请到模块条码成功:" + M_SN); this.currentTaskDescribe = "申请到模块码:" + M_SN; currentTaskPhase++; break; } case 2: { if (this.db2Vals[1] != 0) { break; } this.db1ValsToSnd[1] = 1; //写条码到文件 string modCodeFile = ""; modCodeFile = string.Format(@"\\{0}\打标文件\加工文件\打码内容.txt", machionIP); if (!System.IO.File.Exists(modCodeFile)) { this.currentTaskDescribe = string.Format("打码内容文件:{0}不存在", modCodeFile); LogRecorder.AddDebugLog(nodeName, string.Format("打码内容文件:{0}不存在", modCodeFile)); break; } System.IO.StreamWriter writter = new System.IO.StreamWriter(modCodeFile, false); StringBuilder strBuild = new StringBuilder(); strBuild.AppendLine(M_SN); writter.Write(strBuild.ToString()); writter.Flush(); writter.Close(); this.db1ValsToSnd[0] = 2; LogRecorder.AddDebugLog(nodeName, string.Format("模块码{0}写到打码内容文本中", M_SN)); this.TxtLogRecorder.WriteLog("工位下发打码内容到设备种成功,条码:" + M_SN); this.currentTaskDescribe = string.Format("模块码{0}写到打码内容文本中", M_SN); currentTaskPhase++; break; } case 3: { //等待扫码结果 this.currentTaskDescribe = "等待扫码结果"; string checkResult = ""; if (this.db2Vals[1] == 1) { checkResult = "OK:"; } else if (this.db2Vals[1] == 2) { checkResult = "NG:"; } else { break; } this.db1ValsToSnd[0] = 1; //复位 string modCodeFile = ""; modCodeFile = string.Format(@"\\{0}\打标文件\加工文件\打码内容.txt", machionIP); /* * if (!System.IO.File.Exists(modCodeFile)) * { * * LogRecorder.AddDebugLog(nodeName, string.Format("打码内容文件:{0}不存在", modCodeFile)); * break; * } * System.IO.StreamReader reader = new System.IO.StreamReader(modCodeFile, Encoding.Default); * string modCode = reader.ReadLine();*/ //上传Mes int M_FLAG = 3; string M_AREA = "Y001"; string M_WORKSTATION_SN = "Y00100101"; string M_DEVICE_SN = ""; // string M_SN = modCode; string M_UNION_SN = ""; string M_CONTAINER_SN = ""; string M_LEVEL = ""; string M_ITEMVALUE = "扫码结果:" + checkResult; RootObject rObj = new RootObject(); string barcode = M_SN; string strJson = ""; if (this.db2Vals[1] == 1) { barcode = M_SN; M_FLAG = 3; rObj = DevDataUpload(M_FLAG, M_DEVICE_SN, M_WORKSTATION_SN, barcode, M_UNION_SN, M_CONTAINER_SN, M_LEVEL, M_ITEMVALUE, ref strJson); } else if (this.db2Vals[1] == 2) { barcode = ""; M_FLAG = 6; rObj = ProcParamUpload(M_AREA, M_DEVICE_SN, M_WORKSTATION_SN, "", M_UNION_SN, M_CONTAINER_SN, M_LEVEL, M_ITEMVALUE, ref strJson); } // LogRecorder.AddDebugLog(nodeName, rObj.RES); logRecorder.AddDebugLog(nodeName, string.Format("打码结果{0}上传MES,返回{1}", checkResult, rObj.RES)); this.TxtLogRecorder.WriteLog(string.Format("打码结果{0}上传MES", checkResult)); this.currentTaskDescribe = string.Format("打码结果{0}上传MES,返回{1}", checkResult, rObj.RES); //清空文件 System.IO.StreamWriter writter = new System.IO.StreamWriter(modCodeFile, false); StringBuilder strBuild = new StringBuilder(); strBuild.AppendLine(""); writter.Write(strBuild.ToString()); writter.Flush(); writter.Close(); LogRecorder.AddDebugLog(nodeName, "打码内容文件清空"); this.db1ValsToSnd[1] = 2; if (this.db2Vals[1] == 2) { currentTaskPhase = 2; } else { currentTaskPhase = 0; this.TxtLogRecorder.WriteLog("此工位流程处理完成!"); } break; } default: break; } //if(!plcRW2.WriteMultiDB("D9100", 2, barcodeDb1)) //{ // Console.WriteLine("{0}打码交互,写DB1数据区失败", nodeName); // return false; //} return(true); }
private bool ScanCodeIsSuccess(ref string reStr) { int val = 0; if (!plcRW2.ReadDB("D9001", ref val)) { plcRW2.CloseConnect(); plcRW2.ConnectPLC(ref reStr); return(false); } string checkResult = ""; if (val == 1) { checkResult = "OK:"; } else if (val == 2) { checkResult = "NG:"; } else { return(false); } // LogRecorder.AddDebugLog(nodeName, "D9001 = " + val.ToString()); //读模组条码文件 string modCodeFile = ""; modCodeFile = string.Format(@"\\{0}\打标文件\加工文件\打码内容.txt", machionIP); if (!System.IO.File.Exists(modCodeFile)) { LogRecorder.AddDebugLog(nodeName, string.Format("打码内容文件:{0}不存在", modCodeFile)); return(false); } System.IO.StreamReader reader = new System.IO.StreamReader(modCodeFile, Encoding.Default); string modCode = reader.ReadLine(); //上传Mes int M_FLAG = 3; string M_WORKSTATION_SN = "Y00100101"; string M_DEVICE_SN = ""; string M_SN = modCode; string M_UNION_SN = ""; string M_CONTAINER_SN = ""; string M_LEVEL = ""; string M_ITEMVALUE = "扫码结果:" + checkResult; RootObject rObj = new RootObject(); string strJson = ""; rObj = DevDataUpload(M_FLAG, M_DEVICE_SN, M_WORKSTATION_SN, M_SN, M_UNION_SN, M_CONTAINER_SN, M_LEVEL, M_ITEMVALUE, ref strJson); LogRecorder.AddDebugLog(nodeName, rObj.RES); //if (rObj.RES.Contains("NG")) //{ // return false; //} logRecorder.AddDebugLog(nodeName, string.Format("打码结果{0}上传MES", checkResult)); if (plcRW2.WriteDB("D9101", 2)) { plcRW2.CloseConnect(); plcRW2.ConnectPLC(ref reStr); return(false); } //清空文件 System.IO.StreamWriter writter = new System.IO.StreamWriter(modCodeFile, false); StringBuilder strBuild = new StringBuilder(); strBuild.AppendLine(""); writter.Write(strBuild.ToString()); writter.Flush(); writter.Close(); LogRecorder.AddDebugLog(nodeName, "打码内容文件清空"); if (plcRW2.WriteDB("D9100", 1)) { plcRW2.CloseConnect(); plcRW2.ConnectPLC(ref reStr); return(false); } // LogRecorder.AddDebugLog(nodeName, "D9100 = 1"); return(true); }
private bool RequireModCode(ref string reStr) { int val = 0; if (!plcRW2.ReadDB("D9000", ref val)) { Console.WriteLine(nodeName + "读设备PLC失败,PLC地址:" + (plcRW2 as DevAccess.OmlPlcRW).PLCIP); plcRW2.CloseConnect(); plcRW2.ConnectPLC(ref reStr); return(false); } if (val != 1) { // LogRecorder.AddDebugLog(nodeName, "D9000 = 0"); return(false); } if (!plcRW2.WriteDB("D9101", 1)) { Console.WriteLine(nodeName + "复位D9101失败"); return(false); } // LogRecorder.AddDebugLog(nodeName, "D9000 = 1"); Console.WriteLine("{0}开始从MES申请模块码", nodeName); string M_SN = ""; if (!ModuleCodeRequire(ref M_SN, ref reStr)) { LogRecorder.AddDebugLog(nodeName, "ModuleCodeRequire FALSE" + "," + reStr); if (plcRW2.WriteDB("D9100", 3)) { plcRW2.CloseConnect(); plcRW2.ConnectPLC(ref reStr); return(false); } return(false); } LogRecorder.AddDebugLog(nodeName, "从MES申请到模块码:" + M_SN); this.TxtLogRecorder.WriteLog("从MES申请到模块码:" + M_SN); //写条码到文件 string modCodeFile = ""; modCodeFile = string.Format(@"\\{0}\打标文件\加工文件\打码内容.txt", machionIP); if (!System.IO.File.Exists(modCodeFile)) { LogRecorder.AddDebugLog(nodeName, string.Format("打码内容文件:{0}不存在", modCodeFile)); return(false); } System.IO.StreamWriter writter = new System.IO.StreamWriter(modCodeFile, false); StringBuilder strBuild = new StringBuilder(); strBuild.AppendLine(M_SN); writter.Write(strBuild.ToString()); writter.Flush(); writter.Close(); if (!plcRW2.WriteDB("D9000", 0)) { reStr = "复位D9000 失败"; return(false); } if (!plcRW2.WriteDB("D9100", 2)) { plcRW2.CloseConnect(); plcRW2.ConnectPLC(ref reStr); return(false); } LogRecorder.AddDebugLog(nodeName, "模块条码写到打码内容文本中"); return(true); }
private void ExeSwitch() { string reStr = ""; if (db2Vals[0] == 0) { this.db1ValsToSnd[0] = 0; this.db1ValsToSnd[1] = 0; } if (db2Vals[0] != 1) { return; } //扫码请求 string barcode = ""; if (SysCfgModel.SimMode) { barcode = this.SimBarcode; this.swithBarcode = barcode; } else { barcode = barcodeRW.ReadBarcode(); this.swithBarcode = barcode; } if (string.IsNullOrWhiteSpace(barcode)) { if (this.db1ValsToSnd[0] != 2) { logRecorder.AddDebugLog(nodeName, "读条码失败"); } this.db1ValsToSnd[0] = 2; return; } else { Console.WriteLine(this.nodeName + "读取条码成功:" + barcode); this.TxtLogRecorder.WriteLog("读取条码成功:" + barcode); } DBAccess.Model.BatteryModuleModel mod = modBll.GetModel(barcode); if (mod == null) { if (this.db1ValsToSnd[0] != 3) { LogRecorder.AddDebugLog(nodeName, string.Format("条码{0},产品信息不存在", barcode)); } this.db1ValsToSnd[0] = 3; return; } //分档信息不为数字为字符串,目前测试AAA为1档位 //string pattern = @"^[0-9]*$"; //数字正则 //if (!System.Text.RegularExpressions.Regex.IsMatch(mod.tag1, pattern)) //{ // if (this.db1ValsToSnd[1]!=0) // { // logRecorder.AddDebugLog(nodeName, string.Format("分档字符串:{0}错误,要求为数字,", mod.tag1)); // } // this.db1ValsToSnd[1] = 0; // return; //} //PLNodesBll plNodesBll = new PLNodesBll(); //plNodeModel = plNodesBll.GetModel(this.nodeID); short groupSeq = 0; if (short.TryParse(mod.tag5, out groupSeq) == false) { Console.WriteLine(this.nodeName + "分档信息有误:" + mod.tag5 + ",无法转换为数字!"); return; } //short groupSeq = 1;//测试默认为1档位 bool isNg = false; if (switchUploadMes == false)//保证只传一次 { if (UploadMesLogic(groupSeq, barcode, ref isNg, ref reStr) == false) { return; } switchUploadMes = true; } if (isNg == true)//NG处理 { if (this.plcRW.WriteDB("D9000", 2) == false) { return; } if (this.plcRW2.WriteDB("D9000", 2) == false) { return; } if (!NodeDB2Commit(0, 2, ref reStr))//流程结束 { logRecorder.AddDebugLog(nodeName, "发送PLC数据失败"); } LogRecorder.AddDebugLog(nodeName, "模块二维码:" + barcode + ",MES分析NG,线体服务器流程处理结束!"); return; } else { if (this.plcRW.WriteDB("D9000", 1) == false) { return; } if (this.plcRW2.WriteDB("D9000", 1) == false) { return; } } this.db1ValsToSnd[0] = 1; this.db1ValsToSnd[1] = groupSeq; Console.WriteLine(this.nodeName, 11); switch (groupSeq) { case 1: { string[] modExistArray = plNodeModel.tag1.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); if (modExistArray != null && modExistArray.Count() > modPalletMax) { this.db1ValsToSnd[0] = 4; this.currentTaskDescribe = string.Format("档位{0}已满,最大允许数量,目前数量{1}", groupSeq, modPalletMax); return; } if (!plNodeModel.tag1.ToUpper().Contains(barcode.ToUpper())) { plNodeModel.tag1 = plNodeModel.tag1 + barcode + ","; LogRecorder.AddDebugLog(nodeName, string.Format("模块:{0}分档完成,档位:{1}", barcode, mod.tag1)); this.TxtLogRecorder.WriteLog(string.Format("模块:{0}分档完成,档位:{1}", barcode, mod.tag1)); } else { LogRecorder.AddDebugLog(nodeName, string.Format("模块:{0}分档缓存数据已经存在,分档完成,档位:{1}", barcode, mod.tag1)); } break; } case 2: { string[] modExistArray = plNodeModel.tag2.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); if (modExistArray != null && modExistArray.Count() > modPalletMax) { this.db1ValsToSnd[0] = 4; this.currentTaskDescribe = string.Format("档位{0}已满,最大允许数量,目前数量{1}", groupSeq, modPalletMax); return; } if (!plNodeModel.tag2.ToUpper().Contains(barcode.ToUpper())) { plNodeModel.tag2 = plNodeModel.tag2 + barcode + ","; LogRecorder.AddDebugLog(nodeName, string.Format("模块:{0}分档完成,档位:{1}", barcode, mod.tag1)); this.TxtLogRecorder.WriteLog(string.Format("模块:{0}分档完成,档位:{1}", barcode, mod.tag1)); } else { LogRecorder.AddDebugLog(nodeName, string.Format("模块:{0}分档缓存数据已经存在,分档完成,档位:{1}", barcode, mod.tag1)); } break; } case 3: { string[] modExistArray = plNodeModel.tag3.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); if (modExistArray != null && modExistArray.Count() > modPalletMax) { this.db1ValsToSnd[0] = 4; this.currentTaskDescribe = string.Format("档位{0}已满,最大允许数量,目前数量{1}", groupSeq, modPalletMax); return; } if (!plNodeModel.tag3.ToUpper().Contains(barcode.ToUpper())) { plNodeModel.tag3 = plNodeModel.tag3 + barcode + ","; LogRecorder.AddDebugLog(nodeName, string.Format("模块:{0}分档完成,档位:{1}", barcode, mod.tag1)); this.TxtLogRecorder.WriteLog(string.Format("模块:{0}分档完成,档位:{1}", barcode, mod.tag1)); } else { LogRecorder.AddDebugLog(nodeName, string.Format("模块:{0}分档缓存数据已经存在,分档完成,档位:{1}", barcode, mod.tag1)); } break; } case 4: { string[] modExistArray = plNodeModel.tag4.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); if (modExistArray != null && modExistArray.Count() > modPalletMax) { this.db1ValsToSnd[0] = 4; this.currentTaskDescribe = string.Format("档位{0}已满,最大允许数量,目前数量{1}", groupSeq, modPalletMax); return; } if (!plNodeModel.tag4.ToUpper().Contains(barcode.ToUpper())) { plNodeModel.tag4 = plNodeModel.tag4 + barcode + ","; LogRecorder.AddDebugLog(nodeName, string.Format("模块:{0}分档完成,档位:{1}", barcode, mod.tag1)); this.TxtLogRecorder.WriteLog(string.Format("模块:{0}分档完成,档位:{1}", barcode, mod.tag1)); } else { LogRecorder.AddDebugLog(nodeName, string.Format("模块:{0}分档缓存数据已经存在,分档完成,档位:{1}", barcode, mod.tag1)); } break; } default: break; } plNodeBll.Update(plNodeModel); if (!NodeDB2Commit(0, 2, ref reStr)) { logRecorder.AddDebugLog(nodeName, "发送PLC数据失败"); } switchUploadMes = false; //else //{ // Console.WriteLine("扫码完成信号写入2"); //} }
protected bool ExeBindA(ref string reStr) { if (!ExeBusinessAB(ref reStr)) { return(false); } switch (currentTaskPhase) { case 1: if (!RfidReadAB()) { break; } bool needReparid = false; if (this.repairProcess.GetNeedRepairALine(this.rfidUID, this.NodeID, ref needReparid, ref reStr) == false) { this.logRecorder.AddDebugLog(this.nodeName, "获取返修状态失败:" + reStr); break; } if (needReparid == false) { currentTaskPhase = 3; //直接放行 this.repairProcess.ReportToMesByProcessStationID(this.nodeID, this.rfidUID); this.TxtLogRecorder.WriteLog("当前工艺此工位不需要加工,直接放行,工装板号:" + this.rfidUID); break; } if (!ProductTraceRecord()) { break; } LogRecorder.AddDebugLog(nodeName, string.Format("RFID:{0}", this.rfidUID)); currentTaskPhase++; this.currentTask.TaskPhase = this.currentTaskPhase; this.TxtLogRecorder.WriteLog("当前工位开始加工!"); this.ctlTaskBll.Update(this.currentTask); break; case 2: int uploadStatus = 0; if (this.nodeID == "OPA013") { uploadStatus = UploadDataToMes(1, "Y00100501", this.rfidUID, ref reStr); } else if (this.nodeID == "OPA014") { //LogRecorder.AddDebugLog(nodeName, "烘烤1NG流程开始处理:"); if (BakeNHHandler(this.rfidUID, "OPA016", ref reStr) == false) { LogRecorder.AddDebugLog(nodeName, "烘烤1NG流程处理失败:" + reStr); break; } //LogRecorder.AddDebugLog(nodeName, "烘烤1NG流程开始成功!"); uploadStatus = UploadDataToMes(1, "Y00101001", this.rfidUID, ref reStr); } else if (this.nodeID == "OPA015") { //LogRecorder.AddDebugLog(nodeName, "烘烤2NG流程开始处理:"); if (BakeNHHandler(this.rfidUID, "OPA017", ref reStr) == false) { LogRecorder.AddDebugLog(nodeName, "烘烤2NG流程处理失败:" + reStr); break; } //LogRecorder.AddDebugLog(nodeName, "烘烤2NG流程成功!"); uploadStatus = UploadDataToMes(1, "Y00101301", this.rfidUID, ref reStr); } if (uploadStatus == 0) { //this.logRecorder.AddDebugLog(this.nodeName, "上传MES数据成功:" + reStr); } else if (uploadStatus == 1) { //this.logRecorder.AddDebugLog(this.nodeName, "上传MES数据成功,返回NG:" + reStr); } else if (uploadStatus == 3) //空板放行 { //this.logRecorder.AddDebugLog(this.nodeName, "空板直接放行!" +this.rfidUID); } else { currentTaskDescribe = "上传MES数据失败:" + reStr; Console.WriteLine(this.nodeName + "上传MES数据失败:" + reStr); break; } currentTaskPhase++; this.currentTask.TaskPhase = this.currentTaskPhase; this.ctlTaskBll.Update(this.currentTask); this.TxtLogRecorder.WriteLog(string.Format("上传MES二位码成功:{0}", this.rfidUID)); LogRecorder.AddDebugLog(nodeName, string.Format("上传MES二位码成功:{0}", this.rfidUID)); this.currentTaskDescribe = string.Format("上传MES二维码成功!"); break; case 3: { this.currentTask.TaskPhase = this.currentTaskPhase; this.currentTask.TaskStatus = EnumTaskStatus.已完成.ToString(); this.ctlTaskBll.Update(this.currentTask); db1ValsToSnd[2 + this.channelIndex - 1] = 3; currentTaskDescribe = "流程完成"; this.TxtLogRecorder.WriteLog("工位加工处理完成!"); break; } default: break; } return(true); }