From c1a95d08c841a7986ddb9da76ab34fd6069b5387 Mon Sep 17 00:00:00 2001 From: ZhaoGang <15196688790@163.com> Date: Tue, 22 Aug 2023 15:12:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E6=95=B0=E6=8D=AE=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E6=B2=A1=E6=94=B6=E5=88=B0=E5=B0=B1=E4=B8=80?= =?UTF-8?q?=E7=9B=B4=E7=BB=99=E8=A5=BF=E9=97=A8=E5=AD=90=E5=8F=91=E9=80=81?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Model/ProcessControl.cs | 254 ++++++++++++----- .../Model/GVL_SmallStation.cs | 4 +- .../Model/ProcessControl.cs | 265 ++++++++++++------ 3 files changed, 370 insertions(+), 153 deletions(-) diff --git a/BPASmartClient.JXJFoodBigStation/Model/ProcessControl.cs b/BPASmartClient.JXJFoodBigStation/Model/ProcessControl.cs index daa8422f..47442575 100644 --- a/BPASmartClient.JXJFoodBigStation/Model/ProcessControl.cs +++ b/BPASmartClient.JXJFoodBigStation/Model/ProcessControl.cs @@ -864,7 +864,7 @@ namespace BPASmartClient.JXJFoodBigStation.Model case 3: SiemensDevice.Siemens_PLC_S7.WriteString(2331, data.RecipeCode, 10); SiemensDevice.Siemens_PLC_S7.Write("DB2331.DBX28.0", true); - MessageNotify.GetInstance.ShowRunLog($"配方1,发送配方编号和请求配料标志给西门子"); + MessageNotify.GetInstance.ShowRunLog($"配方队列【1】,配方:【{data.RecipeCode}】发送配方编号和请求配料标志给西门子"); GVL_BigStation.SiemensSendRecipeStatus = 4; break; case 4: @@ -872,7 +872,7 @@ namespace BPASmartClient.JXJFoodBigStation.Model { SiemensDevice.Siemens_PLC_S7.WriteString(2331, "", 10); SiemensDevice.Siemens_PLC_S7.Write("DB2331.DBX28.0", false); - MessageNotify.GetInstance.ShowRunLog($"配方1,西门子确认开始配料"); + MessageNotify.GetInstance.ShowRunLog($"配方队列【1】,配方:【{data.RecipeCode}】西门子确认开始配料"); GVL_BigStation.SiemensSendRecipeStatus = 5; } break; @@ -880,7 +880,7 @@ namespace BPASmartClient.JXJFoodBigStation.Model if (SiemensDevice.DL_Status.Dosing_Start_ACK == false) { SiemensRecipeQueue1.Enqueue(data.RecipeCode); - MessageNotify.GetInstance.ShowRunLog($"配方1,配方:【{data.RecipeCode}】,加入队列"); + MessageNotify.GetInstance.ShowRunLog($"配方队列【1】,配方:【{data.RecipeCode}】,加入队列"); GVL_BigStation.SiemensSendRecipeStatus = 0; } break; @@ -900,7 +900,7 @@ namespace BPASmartClient.JXJFoodBigStation.Model { SiemensDevice.Siemens_PLC_S7.WriteString(2331, data.RecipeCode, 10); SiemensDevice.Siemens_PLC_S7.Write("DB2331.DBX28.0", true); - MessageNotify.GetInstance.ShowRunLog($"配方2,发送配方编号和请求配料标志给西门子"); + MessageNotify.GetInstance.ShowRunLog($"配方队列【2】,配方:【{data.RecipeCode}】发送配方编号和请求配料标志给西门子"); GVL_BigStation.SiemensSendRecipeStatus = 4; } if (GVL_BigStation.SiemensSendRecipeStatus == 4) @@ -909,7 +909,7 @@ namespace BPASmartClient.JXJFoodBigStation.Model { SiemensDevice.Siemens_PLC_S7.WriteString(2331, "", 10); SiemensDevice.Siemens_PLC_S7.Write("DB2331.DBX28.0", false); - MessageNotify.GetInstance.ShowRunLog($"配方2,西门子确认开始配料"); + MessageNotify.GetInstance.ShowRunLog($"配方队列【2】,配方:【{data.RecipeCode}】西门子确认开始配料"); GVL_BigStation.SiemensSendRecipeStatus = 5; } } @@ -918,7 +918,7 @@ namespace BPASmartClient.JXJFoodBigStation.Model if (SiemensDevice.DL_Status.Dosing_Start_ACK == false) { SiemensRecipeQueue2.Enqueue(data.RecipeCode); - MessageNotify.GetInstance.ShowRunLog($"配方2,配方:【{data.RecipeCode}】,加入队列"); + MessageNotify.GetInstance.ShowRunLog($"配方队列【2】,配方:【{data.RecipeCode}】,加入队列"); GVL_BigStation.SiemensSendRecipeStatus = 0; } } @@ -935,7 +935,7 @@ namespace BPASmartClient.JXJFoodBigStation.Model { SiemensDevice.Siemens_PLC_S7.WriteString(2331, data.RecipeCode, 10); SiemensDevice.Siemens_PLC_S7.Write("DB2331.DBX28.0", true); - MessageNotify.GetInstance.ShowRunLog($"配方3,发送配方编号和请求配料标志给西门子"); + MessageNotify.GetInstance.ShowRunLog($"配方队列【3】,配方:【{data.RecipeCode}】发送配方编号和请求配料标志给西门子"); GVL_BigStation.SiemensSendRecipeStatus = 4; } if (GVL_BigStation.SiemensSendRecipeStatus == 4) @@ -944,7 +944,7 @@ namespace BPASmartClient.JXJFoodBigStation.Model { SiemensDevice.Siemens_PLC_S7.WriteString(2331, "", 10); SiemensDevice.Siemens_PLC_S7.Write("DB2331.DBX28.0", false); - MessageNotify.GetInstance.ShowRunLog($"配方3,西门子确认开始配料"); + MessageNotify.GetInstance.ShowRunLog($"配方队列【3】,配方:【{data.RecipeCode}】西门子确认开始配料"); GVL_BigStation.SiemensSendRecipeStatus = 5; } } @@ -953,7 +953,7 @@ namespace BPASmartClient.JXJFoodBigStation.Model if (SiemensDevice.DL_Status.Dosing_Start_ACK == false) { SiemensRecipeQueue3.Enqueue(data.RecipeCode); - MessageNotify.GetInstance.ShowRunLog($"配方3,配方:【{data.RecipeCode}】,加入队列"); + MessageNotify.GetInstance.ShowRunLog($"配方队列【3】,配方:【{data.RecipeCode}】,加入队列"); GVL_BigStation.SiemensSendRecipeStatus = 0; } } @@ -970,7 +970,7 @@ namespace BPASmartClient.JXJFoodBigStation.Model { SiemensDevice.Siemens_PLC_S7.WriteString(2331, data.RecipeCode, 10); SiemensDevice.Siemens_PLC_S7.Write("DB2331.DBX28.0", true); - MessageNotify.GetInstance.ShowRunLog($"配方4,发送配方编号和请求配料标志给西门子"); + MessageNotify.GetInstance.ShowRunLog($"配方4,配方:【{data.RecipeCode}】发送配方编号和请求配料标志给西门子"); GVL_BigStation.SiemensSendRecipeStatus = 4; } if (GVL_BigStation.SiemensSendRecipeStatus == 4) @@ -979,7 +979,7 @@ namespace BPASmartClient.JXJFoodBigStation.Model { SiemensDevice.Siemens_PLC_S7.WriteString(2331, "", 10); SiemensDevice.Siemens_PLC_S7.Write("DB2331.DBX28.0", false); - MessageNotify.GetInstance.ShowRunLog($"配方4,西门子确认开始配料"); + MessageNotify.GetInstance.ShowRunLog($"配方队列【4】,配方:【{data.RecipeCode}】西门子确认开始配料"); GVL_BigStation.SiemensSendRecipeStatus = 5; } } @@ -988,7 +988,7 @@ namespace BPASmartClient.JXJFoodBigStation.Model if (SiemensDevice.DL_Status.Dosing_Start_ACK == false) { SiemensRecipeQueue4.Enqueue(data.RecipeCode); - MessageNotify.GetInstance.ShowRunLog($"配方4,配方:【{data.RecipeCode}】,加入队列"); + MessageNotify.GetInstance.ShowRunLog($"配方队列【4】,配方:【{data.RecipeCode}】,加入队列"); GVL_BigStation.SiemensSendRecipeStatus = 0; } } @@ -1001,22 +1001,22 @@ namespace BPASmartClient.JXJFoodBigStation.Model if (SiemensRecipeQueue1.Count == 0 && !SiemensRecipeQueue2.Contains(data.RecipeCode) && !SiemensRecipeQueue3.Contains(data.RecipeCode) && !SiemensRecipeQueue4.Contains(data.RecipeCode) && HKDevice.PlcRead.IsAllowIssueRecipe1 && data.TrayCode == 1) { SiemensRecipeQueue1.Enqueue(data.RecipeCode); - MessageNotify.GetInstance.ShowRunLog($"本地配方,配方:【{data.RecipeCode}】,加入队列1"); + MessageNotify.GetInstance.ShowRunLog($"本地配方,配方:【{data.RecipeCode}】,加入队列【1】"); } else if (SiemensRecipeQueue2.Count == 0 && !SiemensRecipeQueue1.Contains(data.RecipeCode) && !SiemensRecipeQueue3.Contains(data.RecipeCode) && !SiemensRecipeQueue4.Contains(data.RecipeCode) && HKDevice.PlcRead.IsAllowIssueRecipe2 && data.TrayCode == 2) { SiemensRecipeQueue2.Enqueue(data.RecipeCode); - MessageNotify.GetInstance.ShowRunLog($"本地配方,配方:【{data.RecipeCode}】,加入队列2"); + MessageNotify.GetInstance.ShowRunLog($"本地配方,配方:【{data.RecipeCode}】,加入队列【2】"); } else if (SiemensRecipeQueue3.Count == 0 && !SiemensRecipeQueue1.Contains(data.RecipeCode) && !SiemensRecipeQueue2.Contains(data.RecipeCode) && !SiemensRecipeQueue4.Contains(data.RecipeCode) && HKDevice.PlcRead.IsAllowIssueRecipe3 && data.TrayCode == 3) { SiemensRecipeQueue3.Enqueue(data.RecipeCode); - MessageNotify.GetInstance.ShowRunLog($"本地配方,配方:【{data.RecipeCode}】,加入队列3"); + MessageNotify.GetInstance.ShowRunLog($"本地配方,配方:【{data.RecipeCode}】,加入队列【3】"); } else if (SiemensRecipeQueue4.Count == 0 && !SiemensRecipeQueue1.Contains(data.RecipeCode) && !SiemensRecipeQueue2.Contains(data.RecipeCode) && !SiemensRecipeQueue3.Contains(data.RecipeCode) && HKDevice.PlcRead.IsAllowIssueRecipe4 && data.TrayCode == 4) { SiemensRecipeQueue4.Enqueue(data.RecipeCode); - MessageNotify.GetInstance.ShowRunLog($"本地配方,配方:【{data.RecipeCode}】,加入队列4"); + MessageNotify.GetInstance.ShowRunLog($"本地配方,配方:【{data.RecipeCode}】,加入队列【4】"); } } } @@ -1307,7 +1307,7 @@ namespace BPASmartClient.JXJFoodBigStation.Model default: break; } - if (HKDevice.PlcRead.IsAllowIssueRecipe1 && GVL_BigStation.Recipe1DosingStatus == 0 && Inplace)//配方1是否允许下发配发 + if (HKDevice.PlcRead.IsAllowIssueRecipe1 && GVL_BigStation.Recipe1DosingStatus == 0 && Inplace)//配方队列【1】是否允许下发配发 { if (SiemensRecipes.ElementAt(index).IsWashingBarrel) { @@ -1315,13 +1315,13 @@ namespace BPASmartClient.JXJFoodBigStation.Model { GVL_BigStation.BarrelWasherSign = true; HKDevice.HK_PLC_S7.Write("DB99.DBX0.1", true);//洗桶 - MessageNotify.GetInstance.ShowRunLog($"配方1,配方编号:{code},托盘编号:{trayCode},订单类型为洗桶"); + MessageNotify.GetInstance.ShowRunLog($"配方队列【1】,配方编号:{code},托盘编号:{trayCode},订单类型为洗桶"); GVL_BigStation.DosingRecipe1Time = DateTime.Now; HKDevice.WritePlcRecipeData(SiemensRecipes.ElementAt(index)); HKDevice.HK_PLC_S7.Write("DB99.DBX0.3", true); GVL_BigStation.Recipe1DosingStatus = 1; - MessageNotify.GetInstance.ShowRunLog($"配方1,配方编号:{code},托盘编号:{trayCode},下发完成"); + MessageNotify.GetInstance.ShowRunLog($"配方队列【1】,配方编号:{code},托盘编号:{trayCode},下发完成"); } } else @@ -1330,7 +1330,7 @@ namespace BPASmartClient.JXJFoodBigStation.Model HKDevice.WritePlcRecipeData(SiemensRecipes.ElementAt(index)); HKDevice.HK_PLC_S7.Write("DB99.DBX0.3", true); GVL_BigStation.Recipe1DosingStatus = 1; - MessageNotify.GetInstance.ShowRunLog($"配方1,配方编号:{code},托盘编号:{trayCode},下发完成"); + MessageNotify.GetInstance.ShowRunLog($"配方队列【1】,配方编号:{code},托盘编号:{trayCode},下发完成"); } } if (HKDevice.PlcRead.ReceiveFinishRecipe1 && GVL_BigStation.Recipe1DosingStatus == 1) @@ -1338,11 +1338,11 @@ namespace BPASmartClient.JXJFoodBigStation.Model if (SiemensRecipes.ElementAt(index).IsWashingBarrel) { HKDevice.HK_PLC_S7.Write("DB99.DBX0.1", false);//洗桶 - MessageNotify.GetInstance.ShowRunLog($"配方1,配方编号:{code},托盘编号:{trayCode},洗桶复位"); + MessageNotify.GetInstance.ShowRunLog($"配方队列【1】,配方编号:{code},托盘编号:{trayCode},洗桶复位"); } HKDevice.HK_PLC_S7.Write("DB99.DBX0.3", false); StockBinParReset(); - MessageNotify.GetInstance.ShowRunLog($"配方1,配方编号:{code},托盘编号:{trayCode},PLC接收配方完成"); + MessageNotify.GetInstance.ShowRunLog($"配方队列【1】,配方编号:{code},托盘编号:{trayCode},PLC接收配方完成"); GVL_BigStation.Recipe1DosingStatus = 2; } if (GVL_BigStation.Recipe1DosingStatus == 2 && HKDevice.PlcRead.Recipe1DosingFinish) @@ -1352,11 +1352,11 @@ namespace BPASmartClient.JXJFoodBigStation.Model GVL_BigStation.BarrelWasherSign = false; } GVL_BigStation.Recipe1DosingFinish = true; - GVL_BigStation.Recipe1DosingStatus = 3; - MessageNotify.GetInstance.ShowRunLog($"配方1,配方编号:{code},托盘编号:{trayCode},配料完成"); + //GVL_BigStation.Recipe1DosingStatus = 3; + MessageNotify.GetInstance.ShowRunLog($"配方队列【1】,配方编号:{code},托盘编号:{trayCode},配料完成"); ReadStockBinDosingWeight(SiemensRecipes.ElementAt(index)); //2023-8-21:如果不是MES系统下发的配方,不要返回结束数据。 - if (SiemensDevice.IsConnected && SiemensRecipes.ElementAt(index).RecipesSource==RecipeSource.远程 /*!GVL_BigStation.IsUseLocalRecipe*/) + if (SiemensRecipes.ElementAt(index).RecipesSource==RecipeSource.远程 /*!GVL_BigStation.IsUseLocalRecipe*/) { FinishData.Order_No = SiemensRecipes.ElementAt(index).RecipeCode; FinishData.Product_Code = SiemensRecipes.ElementAt(index).RecipeName; @@ -1370,18 +1370,37 @@ namespace BPASmartClient.JXJFoodBigStation.Model FinishData.Material[i].Material_Name = SiemensRecipes.ElementAt(index).RawMaterial.ElementAt(i).RawMaterialName; FinishData.Material[i].Material_BarrelNum = (short)SiemensRecipes.ElementAt(index).RawMaterial.ElementAt(i).RawMaterialBarrelNum; FinishData.Material[i].Material_Laying_Off_Weight = Math.Abs(SiemensRecipes.ElementAt(index).RawMaterial.ElementAt(i).Laying_Off_Weight); - MessageNotify.GetInstance.ShowRunLog($"配方1,配方编号:{code},托盘编号:{trayCode},原料名称:{FinishData.Material[i].Material_Name},原料桶号:{FinishData.Material[i].Material_BarrelNum},配料重量:{FinishData.Material[i].Material_Laying_Off_Weight}kg"); + MessageNotify.GetInstance.ShowRunLog($"配方队列【1】,配方编号:{code},托盘编号:{trayCode},原料名称:{FinishData.Material[i].Material_Name},原料桶号:{FinishData.Material[i].Material_BarrelNum},配料重量:{FinishData.Material[i].Material_Laying_Off_Weight}kg"); } FinishData.Ask_For_Finish = true; double a = DateTime.Now.Subtract(GVL_BigStation.DosingRecipe1Time).TotalSeconds; FinishData.ProcessTime = Convert.ToInt16(a); - SiemensDevice.Siemens_PLC_S7.WriteClass(FinishData, 2361); - MessageNotify.GetInstance.ShowRunLog($"配方1,配方编号:{code},托盘编号:{trayCode},配料完成,将信号反馈给西门子。"); + //SiemensDevice.Siemens_PLC_S7.WriteClass(FinishData, 2361); + MessageNotify.GetInstance.ShowRunLog($"配方队列【1】,配方编号:{code},托盘编号:{trayCode},配料完成,将信号反馈给西门子。"); + + SendDataOperation(() => + { + SiemensDevice.Siemens_PLC_S7.WriteClass(FinishData, 2361); + }, () => + { + return SiemensDevice.Siemens_PLC_S7.Read("DB2361.DBX0.0"); + }); + + var result = SiemensDevice.Siemens_PLC_S7.Write("DB2361.DBX330.0", false, 5); + if (!string.IsNullOrEmpty(result) && result.Contains("成功")) + { + MessageNotify.GetInstance.ShowRunLog($"配方队列【1】,托盘编号:【{trayCode}】,配方编号:【{code}】,配料完成信号写入复位。"); + } + else + { + MessageNotify.GetInstance.ShowRunLog($"配方队列【1】,托盘编号:【{trayCode}】,配方编号:【{code}】,配料完成,已发送数据,但复位请求完成信号失败。"); + } } else { - MessageNotify.GetInstance.ShowRunLog($"配方1,配方编号:【{code}】,托盘编号:【{trayCode}】,配料完成,西门子未连接或配方为本地下发未将完成数据反馈至MES系统。"); + MessageNotify.GetInstance.ShowRunLog($"配方队列【1】,配方编号:【{code}】,托盘编号:【{trayCode}】,配料完成,配方为本地下发未将完成数据反馈至MES系统。"); } + HKDevice.HK_PLC_S7.Write("DB99.DBX1.4", true); GVL_BigStation.Recipe1DosingStatus = 3; } @@ -1394,7 +1413,7 @@ namespace BPASmartClient.JXJFoodBigStation.Model Json.Data.Recipes.RemoveAt(index);//制作完成,移除当前配方 }); GVL_BigStation.Recipe1DosingStatus = 0; - MessageNotify.GetInstance.ShowRunLog($"配方1,配方编号:{code},托盘编号:{trayCode},复位plc配料完成信号"); + MessageNotify.GetInstance.ShowRunLog($"配方队列【1】,配方编号:{code},托盘编号:{trayCode},复位plc配料完成信号"); } } } @@ -1426,7 +1445,7 @@ namespace BPASmartClient.JXJFoodBigStation.Model default: break; } - if (HKDevice.PlcRead.IsAllowIssueRecipe2 && GVL_BigStation.Recipe2DosingStatus == 0 && Inplace)//配方2是否允许下发配发 + if (HKDevice.PlcRead.IsAllowIssueRecipe2 && GVL_BigStation.Recipe2DosingStatus == 0 && Inplace)//配方队列【2】是否允许下发配发 { if (SiemensRecipes.ElementAt(index).IsWashingBarrel) { @@ -1434,13 +1453,13 @@ namespace BPASmartClient.JXJFoodBigStation.Model { GVL_BigStation.BarrelWasherSign = true; HKDevice.HK_PLC_S7.Write("DB99.DBX0.1", true);//洗桶 - MessageNotify.GetInstance.ShowRunLog($"配方2,配方编号:{code},托盘编号:{trayCode},订单类型为洗桶"); + MessageNotify.GetInstance.ShowRunLog($"配方队列【2】,配方编号:{code},托盘编号:{trayCode},订单类型为洗桶"); GVL_BigStation.DosingRecipe2Time = DateTime.Now; HKDevice.WritePlcRecipeData(SiemensRecipes.ElementAt(index)); HKDevice.HK_PLC_S7.Write("DB99.DBX0.4", true); GVL_BigStation.Recipe2DosingStatus = 1; - MessageNotify.GetInstance.ShowRunLog($"配方2,配方编号:{code},托盘编号:{trayCode},下发完成"); + MessageNotify.GetInstance.ShowRunLog($"配方队列【2】,配方编号:{code},托盘编号:{trayCode},下发完成"); } } else @@ -1449,7 +1468,7 @@ namespace BPASmartClient.JXJFoodBigStation.Model HKDevice.WritePlcRecipeData(SiemensRecipes.ElementAt(index)); HKDevice.HK_PLC_S7.Write("DB99.DBX0.4", true); GVL_BigStation.Recipe2DosingStatus = 1; - MessageNotify.GetInstance.ShowRunLog($"配方2,配方编号:{code},托盘编号:{trayCode},下发完成"); + MessageNotify.GetInstance.ShowRunLog($"配方队列【2】,配方编号:{code},托盘编号:{trayCode},下发完成"); } } if (HKDevice.PlcRead.ReceiveFinishRecipe2 && GVL_BigStation.Recipe2DosingStatus == 1) @@ -1457,12 +1476,12 @@ namespace BPASmartClient.JXJFoodBigStation.Model if (SiemensRecipes.ElementAt(index).IsWashingBarrel) { HKDevice.HK_PLC_S7.Write("DB99.DBX0.1", false);//洗桶 - MessageNotify.GetInstance.ShowRunLog($"配方2,配方编号:{code},托盘编号:{trayCode},洗桶复位"); + MessageNotify.GetInstance.ShowRunLog($"配方队列【2】,配方编号:{code},托盘编号:{trayCode},洗桶复位"); } HKDevice.HK_PLC_S7.Write("DB99.DBX0.4", false); StockBinParReset(); GVL_BigStation.Recipe2DosingStatus = 2; - MessageNotify.GetInstance.ShowRunLog($"配方2,配方编号:{code},托盘编号:{trayCode},PLC接收配方完成"); + MessageNotify.GetInstance.ShowRunLog($"配方队列【2】,配方编号:{code},托盘编号:{trayCode},PLC接收配方完成"); } if (GVL_BigStation.Recipe2DosingStatus == 2 && HKDevice.PlcRead.Recipe2DosingFinish) { @@ -1471,10 +1490,10 @@ namespace BPASmartClient.JXJFoodBigStation.Model GVL_BigStation.BarrelWasherSign = false; } GVL_BigStation.Recipe2DosingFinish = true; - MessageNotify.GetInstance.ShowRunLog($"配方2,配方编号:{code},托盘编号:{trayCode},配料完成"); + MessageNotify.GetInstance.ShowRunLog($"配方队列【2】,配方编号:{code},托盘编号:{trayCode},配料完成"); ReadStockBinDosingWeight(SiemensRecipes.ElementAt(index)); - if (SiemensDevice.IsConnected && SiemensRecipes.ElementAt(index).RecipesSource == RecipeSource.远程 /*!GVL_BigStation.IsUseLocalRecipe*/) + if (SiemensRecipes.ElementAt(index).RecipesSource == RecipeSource.远程 /*!GVL_BigStation.IsUseLocalRecipe*/) { FinishData.Order_No = SiemensRecipes.ElementAt(index).RecipeCode; FinishData.Product_Code = SiemensRecipes.ElementAt(index).RecipeName; @@ -1488,17 +1507,36 @@ namespace BPASmartClient.JXJFoodBigStation.Model FinishData.Material[i].Material_Name = SiemensRecipes.ElementAt(index).RawMaterial.ElementAt(i).RawMaterialName; FinishData.Material[i].Material_BarrelNum = (short)SiemensRecipes.ElementAt(index).RawMaterial.ElementAt(i).RawMaterialBarrelNum; FinishData.Material[i].Material_Laying_Off_Weight = Math.Abs(SiemensRecipes.ElementAt(index).RawMaterial.ElementAt(i).Laying_Off_Weight); - MessageNotify.GetInstance.ShowRunLog($"配方2,配方编号:{code},托盘编号:{trayCode},原料名称:{FinishData.Material[i].Material_Name},原料桶号:{FinishData.Material[i].Material_BarrelNum},配料重量:{FinishData.Material[i].Material_Laying_Off_Weight}kg"); + MessageNotify.GetInstance.ShowRunLog($"配方队列【2】,配方编号:{code},托盘编号:{trayCode},原料名称:{FinishData.Material[i].Material_Name},原料桶号:{FinishData.Material[i].Material_BarrelNum},配料重量:{FinishData.Material[i].Material_Laying_Off_Weight}kg"); } FinishData.Ask_For_Finish = true; double a = DateTime.Now.Subtract(GVL_BigStation.DosingRecipe2Time).TotalSeconds; FinishData.ProcessTime = Convert.ToInt16(a); - SiemensDevice.Siemens_PLC_S7.WriteClass(FinishData, 2361); - MessageNotify.GetInstance.ShowRunLog($"配方2,配方编号:{code},托盘编号:{trayCode},配料完成,将信号反馈给西门子"); + //SiemensDevice.Siemens_PLC_S7.WriteClass(FinishData, 2361); + MessageNotify.GetInstance.ShowRunLog($"配方队列【2】,配方编号:{code},托盘编号:{trayCode},配料完成,将信号反馈给西门子"); + + SendDataOperation(() => + { + SiemensDevice.Siemens_PLC_S7.WriteClass(FinishData, 2361); + }, () => + { + return SiemensDevice.Siemens_PLC_S7.Read("DB2361.DBX0.0"); + }); + + var result = SiemensDevice.Siemens_PLC_S7.Write("DB2361.DBX330.0", false, 5); + if (!string.IsNullOrEmpty(result) && result.Contains("成功")) + { + MessageNotify.GetInstance.ShowRunLog($"配方队列【2】,托盘编号:【{trayCode}】,配方编号:【{code}】,配料完成信号写入复位。"); + } + else + { + MessageNotify.GetInstance.ShowRunLog($"配方队列【2】,托盘编号:【{trayCode}】,配方编号:【{code}】,配料完成,已发送数据,但复位请求完成信号失败。"); + } + } else { - MessageNotify.GetInstance.ShowRunLog($"配方2,配方编号:【{code}】,托盘编号:【{trayCode}】,配料完成,西门子未连接或配方为本地下发未将完成数据反馈至MES系统。"); + MessageNotify.GetInstance.ShowRunLog($"配方队列【2】,配方编号:【{code}】,托盘编号:【{trayCode}】,配料完成,西门子未连接或配方为本地下发未将完成数据反馈至MES系统。"); } HKDevice.HK_PLC_S7.Write("DB99.DBX1.5", true); @@ -1515,7 +1553,7 @@ namespace BPASmartClient.JXJFoodBigStation.Model Json.Data.Recipes.RemoveAt(index);//制作完成,移除当前配方 }); GVL_BigStation.Recipe2DosingStatus = 0; - MessageNotify.GetInstance.ShowRunLog($"配方2,配方编号:{code},托盘编号:{trayCode},,复位plc配料完成信号"); + MessageNotify.GetInstance.ShowRunLog($"配方队列【2】,配方编号:{code},托盘编号:{trayCode},,复位plc配料完成信号"); } } } @@ -1547,7 +1585,7 @@ namespace BPASmartClient.JXJFoodBigStation.Model default: break; } - if (HKDevice.PlcRead.IsAllowIssueRecipe3 && GVL_BigStation.Recipe3DosingStatus == 0 && Inplace)//配方3是否允许下发配发 + if (HKDevice.PlcRead.IsAllowIssueRecipe3 && GVL_BigStation.Recipe3DosingStatus == 0 && Inplace)//配方队列【3】是否允许下发配发 { if (SiemensRecipes.ElementAt(index).IsWashingBarrel) { @@ -1555,12 +1593,12 @@ namespace BPASmartClient.JXJFoodBigStation.Model { GVL_BigStation.BarrelWasherSign = true; HKDevice.HK_PLC_S7.Write("DB99.DBX0.1", true);//洗桶 - MessageNotify.GetInstance.ShowRunLog($"配方3,配方编号:{code},托盘编号:{trayCode},订单类型为洗桶"); + MessageNotify.GetInstance.ShowRunLog($"配方队列【3】,配方编号:{code},托盘编号:{trayCode},订单类型为洗桶"); GVL_BigStation.DosingRecipe3Time = DateTime.Now; HKDevice.WritePlcRecipeData(SiemensRecipes.ElementAt(index)); HKDevice.HK_PLC_S7.Write("DB99.DBX0.5", true); GVL_BigStation.Recipe3DosingStatus = 1; - MessageNotify.GetInstance.ShowRunLog($"配方3,配方编号:{code},托盘编号:{trayCode},下发完成"); + MessageNotify.GetInstance.ShowRunLog($"配方队列【3】,配方编号:{code},托盘编号:{trayCode},下发完成"); } } else @@ -1569,7 +1607,7 @@ namespace BPASmartClient.JXJFoodBigStation.Model HKDevice.WritePlcRecipeData(SiemensRecipes.ElementAt(index)); HKDevice.HK_PLC_S7.Write("DB99.DBX0.5", true); GVL_BigStation.Recipe3DosingStatus = 1; - MessageNotify.GetInstance.ShowRunLog($"配方3,配方编号:{code},托盘编号:{trayCode},下发完成"); + MessageNotify.GetInstance.ShowRunLog($"配方队列【3】,配方编号:{code},托盘编号:{trayCode},下发完成"); } } if (HKDevice.PlcRead.ReceiveFinishRecipe3 && GVL_BigStation.Recipe3DosingStatus == 1) @@ -1577,12 +1615,12 @@ namespace BPASmartClient.JXJFoodBigStation.Model if (SiemensRecipes.ElementAt(index).IsWashingBarrel) { HKDevice.HK_PLC_S7.Write("DB99.DBX0.1", false);//洗桶 - MessageNotify.GetInstance.ShowRunLog($"配方3,配方编号:{code},托盘编号:{trayCode},洗桶复位"); + MessageNotify.GetInstance.ShowRunLog($"配方队列【3】,配方编号:{code},托盘编号:{trayCode},洗桶复位"); } HKDevice.HK_PLC_S7.Write("DB99.DBX0.5", false); StockBinParReset(); GVL_BigStation.Recipe3DosingStatus = 2; - MessageNotify.GetInstance.ShowRunLog($"配方3,配方编号:{code},托盘编号:{trayCode},PLC接收配方完成"); + MessageNotify.GetInstance.ShowRunLog($"配方队列【3】,配方编号:{code},托盘编号:{trayCode},PLC接收配方完成"); } if (HKDevice.PlcRead.Recipe3DosingFinish && GVL_BigStation.Recipe3DosingStatus == 2) { @@ -1591,8 +1629,8 @@ namespace BPASmartClient.JXJFoodBigStation.Model GVL_BigStation.BarrelWasherSign = false; } GVL_BigStation.Recipe3DosingFinish = true; - GVL_BigStation.Recipe3DosingStatus = 3; - MessageNotify.GetInstance.ShowRunLog($"配方3,配方编号:{code},托盘编号:{trayCode},配料完成"); + //GVL_BigStation.Recipe3DosingStatus = 3; + MessageNotify.GetInstance.ShowRunLog($"配方队列【3】,配方编号:{code},托盘编号:{trayCode},配料完成"); ReadStockBinDosingWeight(SiemensRecipes.ElementAt(index)); if (SiemensDevice.IsConnected && SiemensRecipes.ElementAt(index).RecipesSource == RecipeSource.远程 /*!GVL_BigStation.IsUseLocalRecipe*/) { @@ -1608,17 +1646,36 @@ namespace BPASmartClient.JXJFoodBigStation.Model FinishData.Material[i].Material_Name = SiemensRecipes.ElementAt(index).RawMaterial.ElementAt(i).RawMaterialName; FinishData.Material[i].Material_BarrelNum = (short)SiemensRecipes.ElementAt(index).RawMaterial.ElementAt(i).RawMaterialBarrelNum; FinishData.Material[i].Material_Laying_Off_Weight = Math.Abs(SiemensRecipes.ElementAt(index).RawMaterial.ElementAt(i).Laying_Off_Weight); - MessageNotify.GetInstance.ShowRunLog($"配方3,配方编号:{code},托盘编号:{trayCode},原料名称:{FinishData.Material[i].Material_Name},原料桶号:{FinishData.Material[i].Material_BarrelNum},配料重量:{FinishData.Material[i].Material_Laying_Off_Weight}kg"); + MessageNotify.GetInstance.ShowRunLog($"配方队列【3】,配方编号:{code},托盘编号:{trayCode},原料名称:{FinishData.Material[i].Material_Name},原料桶号:{FinishData.Material[i].Material_BarrelNum},配料重量:{FinishData.Material[i].Material_Laying_Off_Weight}kg"); } FinishData.Ask_For_Finish = true; double a = DateTime.Now.Subtract(GVL_BigStation.DosingRecipe3Time).TotalSeconds; FinishData.ProcessTime = Convert.ToInt16(a); - SiemensDevice.Siemens_PLC_S7.WriteClass(FinishData, 2361); - MessageNotify.GetInstance.ShowRunLog($"配方3,配方编号:{code},托盘编号:{trayCode},配料完成,将信号反馈给西门子"); + //SiemensDevice.Siemens_PLC_S7.WriteClass(FinishData, 2361); + MessageNotify.GetInstance.ShowRunLog($"配方队列【3】,配方编号:{code},托盘编号:{trayCode},配料完成,将信号反馈给西门子"); + + SendDataOperation(() => + { + SiemensDevice.Siemens_PLC_S7.WriteClass(FinishData, 2361); + }, () => + { + return SiemensDevice.Siemens_PLC_S7.Read("DB2361.DBX0.0"); + }); + + var result = SiemensDevice.Siemens_PLC_S7.Write("DB2361.DBX330.0", false, 5); + if (!string.IsNullOrEmpty(result) && result.Contains("成功")) + { + MessageNotify.GetInstance.ShowRunLog($"配方队列【3】,托盘编号:【{trayCode}】,配方编号:【{code}】,配料完成信号写入复位。"); + } + else + { + MessageNotify.GetInstance.ShowRunLog($"配方队列【3】,托盘编号:【{trayCode}】,配方编号:【{code}】,配料完成,已发送数据,但复位请求完成信号失败。"); + } + } else { - MessageNotify.GetInstance.ShowRunLog($"配方3,配方编号:【{code}】,托盘编号:【{trayCode}】,配料完成,西门子未连接或配方为本地下发未将完成数据反馈至MES系统。"); + MessageNotify.GetInstance.ShowRunLog($"配方队列【3】,配方编号:【{code}】,托盘编号:【{trayCode}】,配料完成,西门子未连接或配方为本地下发未将完成数据反馈至MES系统。"); } HKDevice.HK_PLC_S7.Write("DB99.DBX1.6", true); GVL_BigStation.Recipe3DosingStatus = 3; @@ -1632,7 +1689,7 @@ namespace BPASmartClient.JXJFoodBigStation.Model Json.Data.Recipes.RemoveAt(index);//制作完成,移除当前配方 }); GVL_BigStation.Recipe3DosingStatus = 0; - MessageNotify.GetInstance.ShowRunLog($"配方3,配方编号:{code},托盘编号:{trayCode},复位plc配料完成信号"); + MessageNotify.GetInstance.ShowRunLog($"配方队列【3】,配方编号:{code},托盘编号:{trayCode},复位plc配料完成信号"); } } } @@ -1664,7 +1721,7 @@ namespace BPASmartClient.JXJFoodBigStation.Model default: break; } - if (HKDevice.PlcRead.IsAllowIssueRecipe4 && GVL_BigStation.Recipe4DosingStatus == 0 && Inplace)//配方4是否允许下发配发 + if (HKDevice.PlcRead.IsAllowIssueRecipe4 && GVL_BigStation.Recipe4DosingStatus == 0 && Inplace)//配方队列【4】是否允许下发配发 { if (SiemensRecipes.ElementAt(index).IsWashingBarrel) { @@ -1672,12 +1729,12 @@ namespace BPASmartClient.JXJFoodBigStation.Model { GVL_BigStation.BarrelWasherSign = true; HKDevice.HK_PLC_S7.Write("DB99.DBX0.1", true);//洗桶 - MessageNotify.GetInstance.ShowRunLog($"配方4,配方编号:{code},托盘编号:{trayCode},订单类型为洗桶"); + MessageNotify.GetInstance.ShowRunLog($"配方队列【4】,配方编号:{code},托盘编号:{trayCode},订单类型为洗桶"); GVL_BigStation.DosingRecipe4Time = DateTime.Now; HKDevice.WritePlcRecipeData(SiemensRecipes.ElementAt(index)); HKDevice.HK_PLC_S7.Write("DB99.DBX0.6", true); GVL_BigStation.Recipe4DosingStatus = 1; - MessageNotify.GetInstance.ShowRunLog($"配方4,配方编号:{code},托盘编号:{trayCode},下发完成"); + MessageNotify.GetInstance.ShowRunLog($"配方队列【4】,配方编号:{code},托盘编号:{trayCode},下发完成"); } } else @@ -1686,7 +1743,7 @@ namespace BPASmartClient.JXJFoodBigStation.Model HKDevice.WritePlcRecipeData(SiemensRecipes.ElementAt(index)); HKDevice.HK_PLC_S7.Write("DB99.DBX0.6", true); GVL_BigStation.Recipe4DosingStatus = 1; - MessageNotify.GetInstance.ShowRunLog($"配方4,配方编号:{code},托盘编号:{trayCode},下发完成"); + MessageNotify.GetInstance.ShowRunLog($"配方队列【4】,配方编号:{code},托盘编号:{trayCode},下发完成"); } } if (HKDevice.PlcRead.ReceiveFinishRecipe4 && GVL_BigStation.Recipe4DosingStatus == 1) @@ -1694,12 +1751,12 @@ namespace BPASmartClient.JXJFoodBigStation.Model if (SiemensRecipes.ElementAt(index).IsWashingBarrel) { HKDevice.HK_PLC_S7.Write("DB99.DBX0.1", false);//洗桶 - MessageNotify.GetInstance.ShowRunLog($"配方4,配方编号:{code},托盘编号:{trayCode},洗桶复位"); + MessageNotify.GetInstance.ShowRunLog($"配方队列【4】,配方编号:{code},托盘编号:{trayCode},洗桶复位"); } GVL_BigStation.Recipe4DosingStatus = 2; HKDevice.HK_PLC_S7.Write("DB99.DBX0.6", false); StockBinParReset(); - MessageNotify.GetInstance.ShowRunLog($"配方4,配方编号:{code},托盘编号:{trayCode},PLC接收配方完成"); + MessageNotify.GetInstance.ShowRunLog($"配方队列【4】,配方编号:{code},托盘编号:{trayCode},PLC接收配方完成"); } if (GVL_BigStation.Recipe4DosingStatus == 2 && HKDevice.PlcRead.Recipe4DosingFinish) { @@ -1708,8 +1765,8 @@ namespace BPASmartClient.JXJFoodBigStation.Model GVL_BigStation.BarrelWasherSign = false; } GVL_BigStation.Recipe4DosingFinish = true; - GVL_BigStation.Recipe4DosingStatus = 3; - MessageNotify.GetInstance.ShowRunLog($"配方4,配方编号:{code},托盘编号:{trayCode},配料完成"); + //GVL_BigStation.Recipe4DosingStatus = 3; + MessageNotify.GetInstance.ShowRunLog($"配方队列【4】,配方编号:{code},托盘编号:{trayCode},配料完成"); ReadStockBinDosingWeight(SiemensRecipes.ElementAt(index)); if (SiemensDevice.IsConnected && SiemensRecipes.ElementAt(index).RecipesSource == RecipeSource.远程 /*!GVL_BigStation.IsUseLocalRecipe*/) { @@ -1725,17 +1782,35 @@ namespace BPASmartClient.JXJFoodBigStation.Model FinishData.Material[i].Material_Name = SiemensRecipes.ElementAt(index).RawMaterial.ElementAt(i).RawMaterialName; FinishData.Material[i].Material_BarrelNum = (short)SiemensRecipes.ElementAt(index).RawMaterial.ElementAt(i).RawMaterialBarrelNum; FinishData.Material[i].Material_Laying_Off_Weight = Math.Abs(SiemensRecipes.ElementAt(index).RawMaterial.ElementAt(i).Laying_Off_Weight); - MessageNotify.GetInstance.ShowRunLog($"配方4,配方编号:{code},托盘编号:{trayCode},原料名称:{FinishData.Material[i].Material_Name},原料桶号:{FinishData.Material[i].Material_BarrelNum},配料重量:{FinishData.Material[i].Material_Laying_Off_Weight}kg"); + MessageNotify.GetInstance.ShowRunLog($"配方队列【4】,配方编号:{code},托盘编号:{trayCode},原料名称:{FinishData.Material[i].Material_Name},原料桶号:{FinishData.Material[i].Material_BarrelNum},配料重量:{FinishData.Material[i].Material_Laying_Off_Weight}kg"); } FinishData.Ask_For_Finish = true; double a = DateTime.Now.Subtract(GVL_BigStation.DosingRecipe4Time).TotalSeconds; FinishData.ProcessTime = Convert.ToInt16(a); - SiemensDevice.Siemens_PLC_S7.WriteClass(FinishData, 2361); - MessageNotify.GetInstance.ShowRunLog($"配方4,配方编号:{code},托盘编号:{trayCode},配料完成,将信号反馈给西门子"); + //SiemensDevice.Siemens_PLC_S7.WriteClass(FinishData, 2361); + MessageNotify.GetInstance.ShowRunLog($"配方队列【4】,配方编号:{code},托盘编号:{trayCode},配料完成,将信号反馈给西门子"); + + SendDataOperation(() => + { + SiemensDevice.Siemens_PLC_S7.WriteClass(FinishData, 2361); + }, () => + { + return SiemensDevice.Siemens_PLC_S7.Read("DB2361.DBX0.0"); + }); + + var result = SiemensDevice.Siemens_PLC_S7.Write("DB2361.DBX330.0", false, 5); + if (!string.IsNullOrEmpty(result) && result.Contains("成功")) + { + MessageNotify.GetInstance.ShowRunLog($"配方队列【4】,托盘编号:【{trayCode}】,配方编号:【{code}】,配料完成信号写入复位。"); + } + else + { + MessageNotify.GetInstance.ShowRunLog($"配方队列【4】,托盘编号:【{trayCode}】,配方编号:【{code}】,配料完成,已发送数据,但复位请求完成信号失败。"); + } } else { - MessageNotify.GetInstance.ShowRunLog($"配方4,配方编号:【{code}】,托盘编号:【{trayCode}】,配料完成,西门子未连接或配方为本地下发未将完成数据反馈至MES系统。"); + MessageNotify.GetInstance.ShowRunLog($"配方队列【4】,配方编号:【{code}】,托盘编号:【{trayCode}】,配料完成,西门子未连接或配方为本地下发未将完成数据反馈至MES系统。"); } HKDevice.HK_PLC_S7.Write("DB99.DBX1.7", true); GVL_BigStation.Recipe4DosingStatus = 3; @@ -1749,7 +1824,7 @@ namespace BPASmartClient.JXJFoodBigStation.Model Json.Data.Recipes.RemoveAt(index);//制作完成,移除当前配方 }); GVL_BigStation.Recipe4DosingStatus = 0; - MessageNotify.GetInstance.ShowRunLog($"配方4,配方编号:{code},托盘编号:{trayCode},复位plc配料完成信号"); + MessageNotify.GetInstance.ShowRunLog($"配方队列【4】,配方编号:{code},托盘编号:{trayCode},复位plc配料完成信号"); } } } @@ -2434,5 +2509,46 @@ namespace BPASmartClient.JXJFoodBigStation.Model } } } + + + /// + /// 发送操作,直到收到确认信号 + /// + /// + /// + /// + /// + /// + private bool SendDataOperation(Action operate, Func ack, int retrySecond = 3) + { + if (operate is null) + { + throw new ArgumentNullException("operate", "需要执行的操作不可为Null。"); + } + + if (ack is null) + { + throw new ArgumentNullException("ack", "验证确认的委托不可为Null。"); + } + + var isSuccess = false; + var isConnected = SiemensDevice.IsConnected; + var retryDelay = TimeSpan.FromSeconds(retrySecond); + + operate?.Invoke(); + + isSuccess = ack.Invoke(); + while (!isSuccess) + { + if (isConnected) + { + Thread.Sleep(retryDelay); + operate?.Invoke(); + isSuccess = isSuccess && ack.Invoke(); + } + } + + return isSuccess; + } } } diff --git a/BPASmartClient.JXJFoodSmallStation/Model/GVL_SmallStation.cs b/BPASmartClient.JXJFoodSmallStation/Model/GVL_SmallStation.cs index 33c7ee88..d2fcd7f2 100644 --- a/BPASmartClient.JXJFoodSmallStation/Model/GVL_SmallStation.cs +++ b/BPASmartClient.JXJFoodSmallStation/Model/GVL_SmallStation.cs @@ -204,9 +204,9 @@ namespace BPASmartClient.JXJFoodSmallStation.Model /// public int RecipeStatusIDTray1 { get; set; } = 0; - [VarComm("Global", "配方1下发状态 =0:配方未下发 ,1:配方下发给plc ,2:plc成功接收配方,正在配料,3:PLC配料完成,返回完成数据。")] + [VarComm("Global", "配方1下发状态 =0:配方未下发 ,1:配方下发给plc ,2:plc成功接收配方,正在配料,30:PLC配料完成,返回完成数据。")] /// - /// 配方下发状态 =0:配方未下发 ,1:配方下发给plc ,2:plc成功接收配方,正在配料,3:PLC配料完成,返回完成数据。 + /// 配方下发状态 =0:配方未下发 ,1:配方下发给plc ,2:plc成功接收配方,正在配料,30:PLC配料完成,返回完成数据。 /// public int[] RecipeProcessStatus { get; set; } = new int[5] { 0, 0, 0, 0, 0 }; diff --git a/BPASmartClient.JXJFoodSmallStation/Model/ProcessControl.cs b/BPASmartClient.JXJFoodSmallStation/Model/ProcessControl.cs index a3e055d8..e8e02a43 100644 --- a/BPASmartClient.JXJFoodSmallStation/Model/ProcessControl.cs +++ b/BPASmartClient.JXJFoodSmallStation/Model/ProcessControl.cs @@ -57,7 +57,10 @@ namespace BPASmartClient.JXJFoodSmallStation.Model public ObservableCollection CommData { get; set; } = new ObservableCollection(); public ObservableCollection ProcessVar { get; set; } = new ObservableCollection(); - XL_Finish_DB RecipeFinishInfo = new XL_Finish_DB(); + /// + /// 配方完成信息。 + /// + XL_Finish_DB[] RecipeFinishInfo = new XL_Finish_DB[5]; /// /// 风送PLC的DB块 /// @@ -661,6 +664,7 @@ namespace BPASmartClient.JXJFoodSmallStation.Model /// private void RecipeInfoToHKPLC() { + #region AGV信号交互 if (!GVL_SmallStation.GetInstance.NotUseSmallStation) { //2023-8-18:i<5--> i<1 。只有一个工位,只发一个工位的信号即可。 @@ -710,7 +714,8 @@ namespace BPASmartClient.JXJFoodSmallStation.Model break; } } - } + } + #endregion foreach (var recipe in RecipeQueueTray) { int recipeNum = recipe.Key; @@ -725,45 +730,70 @@ namespace BPASmartClient.JXJFoodSmallStation.Model string windSend = RemoteRecipes.ElementAt(index).ToString(); if (trayCode == 1) { + #region 未使用小料站的情况下配料 if (GVL_SmallStation.GetInstance.NotUseSmallStation) { if (GVL_SmallStation.GetInstance.AGV_PutTray1Finish) { Thread.Sleep(5000); var res = Json.Data.Recipes.FirstOrDefault(p => p.RecipeCode == code); - if (SiemensDevice.IsConnected && RemoteRecipes.ElementAt(index).RecipesSource==RecipeSource.远程 /*!GVL_SmallStation.GetInstance.IsUseLocalRecipe*/) + + if (RemoteRecipes.ElementAt(index).RecipesSource == RecipeSource.远程 /*!GVL_SmallStation.GetInstance.IsUseLocalRecipe*/) { - RecipeFinishInfo.Order_No = RemoteRecipes.ElementAt(index).RecipeCode; - RecipeFinishInfo.Product_Code = RemoteRecipes.ElementAt(index).RecipeName; - RecipeFinishInfo.Job_No = (short)trayCode; + RecipeFinishInfo[recipeNum].Order_No = RemoteRecipes.ElementAt(index).RecipeCode; + RecipeFinishInfo[recipeNum].Product_Code = RemoteRecipes.ElementAt(index).RecipeName; + RecipeFinishInfo[recipeNum].Job_No = (short)trayCode; for (int i = 0; i < 20; i++) { - RecipeFinishInfo.Material[i] = new UDT1(); + RecipeFinishInfo[recipeNum].Material[i] = new UDT1(); } for (int i = 0; i < 10; i++) { - RecipeFinishInfo.Powder[i] = new UDT2(); + RecipeFinishInfo[recipeNum].Powder[i] = new UDT2(); } for (int i = 0; i < RemoteRecipes.ElementAt(index).RawMaterial.Count; i++) { - RecipeFinishInfo.Material[i].Material_Name = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(i).RawMaterialName; - RecipeFinishInfo.Material[i].Material_BarrelNum = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(i).RawMaterialBarrelNum; - RecipeFinishInfo.Material[i].Material_Laying_Off_Weight = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(i).Laying_Off_Weight * (float)0.001; + RecipeFinishInfo[recipeNum].Material[i].Material_Name = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(i).RawMaterialName; + RecipeFinishInfo[recipeNum].Material[i].Material_BarrelNum = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(i).RawMaterialBarrelNum; + RecipeFinishInfo[recipeNum].Material[i].Material_Laying_Off_Weight = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(i).Laying_Off_Weight * (float)0.001; } for (int i = 0; i < RemoteRecipes.ElementAt(index).WindSend.Count; i++) { - RecipeFinishInfo.Powder[i].Powder_Weight = RemoteRecipes.ElementAt(index).WindSend.ElementAt(i).DosingCompleWeight; + RecipeFinishInfo[recipeNum].Powder[i].Powder_Weight = RemoteRecipes.ElementAt(index).WindSend.ElementAt(i).DosingCompleWeight; + } + RecipeFinishInfo[recipeNum].Ask_For_Finish = true; + RecipeFinishInfo[recipeNum].DosingTime = Convert.ToInt16(0); + + MessageNotify.GetInstance.ShowRunLog($"托盘【{trayCode}】,配方【{res.RecipeCode}】,配料完成,开始写入反馈数据。"); + SendDataOperation(() => + { + SiemensDevice.Siemens_PLC_S7.WriteClass(RecipeFinishInfo[recipeNum], 2261); + }, () => + { + return SiemensDevice.Siemens_PLC_S7.Read("DB2261.DBX0.0"); + }); + MessageNotify.GetInstance.ShowRunLog($"托盘【{trayCode}】,配方【{res.RecipeCode}】,配料完成反馈数据写入成功,西门子已确认。"); + + + var result= SiemensDevice.Siemens_PLC_S7.Write("DB2261.DBX450.0", false,5); + + if (!string.IsNullOrEmpty(result) && result.Contains("成功")) + { + MessageNotify.GetInstance.ShowRunLog($"托盘【{trayCode}】,配方【{res.RecipeCode}】,配料完成信号写入复位。"); + } + else + { + MessageNotify.GetInstance.ShowRunLog($"托盘【{trayCode}】,配方【{res.RecipeCode}】,配料完成,已发送数据,但复位请求完成信号失败。"); } - RecipeFinishInfo.Ask_For_Finish = true; - RecipeFinishInfo.DosingTime = Convert.ToInt16(0); - SiemensDevice.Siemens_PLC_S7.WriteClass(RecipeFinishInfo, 2261); + //SiemensDevice.Siemens_PLC_S7.WriteClass(RecipeFinishInfo[recipeNum], 2261); - MessageNotify.GetInstance.ShowRunLog($"托盘【{trayCode}】,配方【{res.RecipeCode}】,配料完成,数据反馈给西门子"); + } else { - MessageNotify.GetInstance.ShowRunLog($"托盘【{trayCode}】,配方【{res.RecipeCode}】,配料完成,数据无法反馈给西门子,西门子设备未连接或处于本地配方"); + MessageNotify.GetInstance.ShowRunLog($"托盘【{trayCode}】,配方【{res.RecipeCode}】,本地配方配料完成,不反馈完成数据至西门子。"); } + GVL_SmallStation.GetInstance.WindSendDosing = false; App.Current.Dispatcher.Invoke(() => { @@ -773,7 +803,9 @@ namespace BPASmartClient.JXJFoodSmallStation.Model GVL_SmallStation.GetInstance.RecipeStockBinDosing[recipeNum] = 0; GVL_SmallStation.GetInstance.RecipeProcessStatus[recipeNum] = 0; } - } + } + #endregion + else { //粉料仓下发配方 @@ -874,6 +906,11 @@ namespace BPASmartClient.JXJFoodSmallStation.Model GVL_SmallStation.GetInstance.StockBinDosingIssue[recipeNum] = 0; MessageNotify.GetInstance.ShowRunLog($"托盘1,配方编号【{code}】,配方号【{recipeNum + 1}】,配方接收完成"); } + //如果没检测到,配方接收完成信号,是否应该返回第0步 下发。 + else + { + + } if (GVL_SmallStation.GetInstance.RecipeProcessStatus[recipeNum] == 2) { @@ -977,7 +1014,7 @@ namespace BPASmartClient.JXJFoodSmallStation.Model MessageNotify.GetInstance.ShowRunLog(commInfo1); } GVL_SmallStation.GetInstance.RecipeStockBinDosing[recipeNum] = GVL_SmallStation.GetInstance.RecipeStockBinDosing[recipeNum].SetBitValue((byte)i, false);//配料完成设备写成false - MessageNotify.GetInstance.ShowRunLog($"配方队列:【{recipeNum+1}】,配方ID:【{code}】,{GVL_SmallStation.GetInstance.RecipeStockBinDosing[recipeNum].ToBinString()}"); + MessageNotify.GetInstance.ShowRunLog($"配方队列:【{recipeNum + 1}】,配方ID:【{code}】,{GVL_SmallStation.GetInstance.RecipeStockBinDosing[recipeNum].ToBinString()}"); } } } @@ -989,7 +1026,7 @@ namespace BPASmartClient.JXJFoodSmallStation.Model var completedSingleAddr = "DB3.DBX6." + recipeNum; bool DosingComple = HKDevice.HK_PLC_S7.Read(completedSingleAddr); var dosingCompleTrig = RTrig.GetInstance("配方配料完成").Start(DosingComple); - //2023-8-18:删除通过小料仓下发情况和配料完成信号判断配料完成。只通过配料完成上升沿作为判断配料结束信号。 + //2023-8-18:删除通过小料仓下发情况和配料完成信号判断配料完成。只通过配料完成上升沿且配料下发有仓完成过作为判断配料结束信号。 if (GVL_SmallStation.GetInstance.StockBinDosingIssue[recipeNum] > 0 && dosingCompleTrig /*&& DosingComple)*/) { MessageNotify.GetInstance.ShowRunLog($"接收到配料PLC配料完成信号【{completedSingleAddr}】上升沿,配方ID:【{code}】,配方队列【{recipeNum + 1}】。"); @@ -1001,70 +1038,113 @@ namespace BPASmartClient.JXJFoodSmallStation.Model { if (GVL_SmallStation.GetInstance.RecipeStockBinDosing[recipeNum].Get16bitValue((byte)i)) { - MessageNotify.GetInstance.ShowRunLog($"配方ID:【{code}】,配方队列【{recipeNum+1}】,料仓配料完成,但存在料仓未配料:{i}号仓"); + MessageNotify.GetInstance.ShowRunLog($"配方ID:【{code}】,配方队列【{recipeNum + 1}】,料仓配料完成,但存在料仓未配料:{i}号仓"); } } } - var res = Json.Data.Recipes.FirstOrDefault(p => p.RecipeCode == code); - double a = DateTime.Now.Subtract(GVL_SmallStation.GetInstance.DosingTime[recipeNum]).TotalSeconds; + + foreach (var item in RemoteRecipes.ElementAt(index).RawMaterial) { MessageNotify.GetInstance.ShowRunLog($"配方ID:【{code}】:【{item.RawMaterialName}】,下料重量:【{item.Laying_Off_Weight}】g"); } - GVL_SmallStation.GetInstance.RecipeProcessStatus[recipeNum] = 3; + } + } + + #region 生成配方完成数据。 + if (RemoteRecipes.ElementAt(index).RecipesSource == RecipeSource.远程 /*!GVL_SmallStation.GetInstance.IsUseLocalRecipe*/) + { + double totalMakeTime = DateTime.Now.Subtract(GVL_SmallStation.GetInstance.DosingTime[recipeNum]).TotalSeconds; - #region 给主控PLC发送配料完成数据信号。 - if (SiemensDevice.IsConnected && RemoteRecipes.ElementAt(index).RecipesSource==RecipeSource.远程 /*!GVL_SmallStation.GetInstance.IsUseLocalRecipe*/) + RecipeFinishInfo[recipeNum].Order_No = RemoteRecipes.ElementAt(index).RecipeCode; + RecipeFinishInfo[recipeNum].Product_Code = RemoteRecipes.ElementAt(index).RecipeName; + RecipeFinishInfo[recipeNum].Job_No = (short)trayCode; + for (int i = 0; i < 20; i++) + { + RecipeFinishInfo[recipeNum].Material[i] = new UDT1(); + } + for (int i = 0; i < 10; i++) + { + RecipeFinishInfo[recipeNum].Powder[i] = new UDT2(); + } + for (int i = 0; i < RemoteRecipes.ElementAt(index).RawMaterial.Count; i++) + { + RecipeFinishInfo[recipeNum].Material[i].Material_Name = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(i).RawMaterialName; + RecipeFinishInfo[recipeNum].Material[i].Material_BarrelNum = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(i).RawMaterialBarrelNum; + RecipeFinishInfo[recipeNum].Material[i].Material_Laying_Off_Weight = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(i).Laying_Off_Weight * (float)0.001; + } + for (int i = 0; i < RemoteRecipes.ElementAt(index).WindSend.Count; i++) + { + RecipeFinishInfo[recipeNum].Powder[i].Powder_Weight = RemoteRecipes.ElementAt(index).WindSend.ElementAt(i).DosingCompleWeight; + } + RecipeFinishInfo[recipeNum].Ask_For_Finish = true; + RecipeFinishInfo[recipeNum].DosingTime = Convert.ToInt16(totalMakeTime); + //SiemensDevice.Siemens_PLC_S7.WriteClass(RecipeFinishInfo[recipeNum], 2261); + + //MessageNotify.GetInstance.ShowRunLog($"托盘1,配方【{res.RecipeCode}】,配料完成,数据反馈给西门子"); + //MessageNotify.GetInstance.ShowRecipeLog($"配方名称:【{res.RecipeName}】\t 配方号:【{res.RecipeCode}】"); + } + //else + //{ + // MessageNotify.GetInstance.ShowRunLog($"托盘1,配方【{res.RecipeCode}】,配料完成,数据无法反馈给西门子,西门子设备未连接或处于本地配方"); + // MessageNotify.GetInstance.ShowRecipeLog($"配方名称:【{res.RecipeName}】\t 配方号:【{res.RecipeCode}】"); + //} + + GVL_SmallStation.GetInstance.RecipeProcessStatus[recipeNum] = 30; + + #endregion + + #region 发送完成数据 + if (GVL_SmallStation.GetInstance.RecipeProcessStatus[recipeNum] == 30) + { + //如果不是远程配方,不需要发送,直接进入下一步。 + if (RemoteRecipes.ElementAt(index).RecipesSource == RecipeSource.远程) + { + //如果MES没连接,直接不发送 等待连接上。 + if (SiemensDevice.IsConnected) { - RecipeFinishInfo.Order_No = RemoteRecipes.ElementAt(index).RecipeCode; - RecipeFinishInfo.Product_Code = RemoteRecipes.ElementAt(index).RecipeName; - RecipeFinishInfo.Job_No = (short)trayCode; - for (int i = 0; i < 20; i++) - { - RecipeFinishInfo.Material[i] = new UDT1(); - } - for (int i = 0; i < 10; i++) + //发送完成 确认MES已经收到了。 + //TODO:多配方队列单反馈变量,不知道到时候会不会有数据抢占的现象。 + if (SiemensDevice.Siemens_PLC_S7.Read("DB2261.DBX0.0")) { - RecipeFinishInfo.Powder[i] = new UDT2(); + GVL_SmallStation.GetInstance.RecipeProcessStatus[recipeNum] = 40; + SiemensDevice.Siemens_PLC_S7.Write("DB2261.DBX450.0", false); + MessageNotify.GetInstance.ShowRunLog($"托盘1,配方【{code}】,MES系统确认收到完成数据。"); } - for (int i = 0; i < RemoteRecipes.ElementAt(index).RawMaterial.Count; i++) - { - RecipeFinishInfo.Material[i].Material_Name = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(i).RawMaterialName; - RecipeFinishInfo.Material[i].Material_BarrelNum = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(i).RawMaterialBarrelNum; - RecipeFinishInfo.Material[i].Material_Laying_Off_Weight = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(i).Laying_Off_Weight * (float)0.001; - } - for (int i = 0; i < RemoteRecipes.ElementAt(index).WindSend.Count; i++) + else { - RecipeFinishInfo.Powder[i].Powder_Weight = RemoteRecipes.ElementAt(index).WindSend.ElementAt(i).DosingCompleWeight; + SiemensDevice.Siemens_PLC_S7.WriteClass(RecipeFinishInfo[recipeNum], 2261); + Thread.Sleep(3000); } - RecipeFinishInfo.Ask_For_Finish = true; - RecipeFinishInfo.DosingTime = Convert.ToInt16(a); - SiemensDevice.Siemens_PLC_S7.WriteClass(RecipeFinishInfo, 2261); - - MessageNotify.GetInstance.ShowRunLog($"托盘1,配方【{res.RecipeCode}】,配料完成,数据反馈给西门子"); - MessageNotify.GetInstance.ShowRecipeLog($"配方名称:【{res.RecipeName}】\t 配方号:【{res.RecipeCode}】"); - } - else - { - MessageNotify.GetInstance.ShowRunLog($"托盘1,配方【{res.RecipeCode}】,配料完成,数据无法反馈给西门子,西门子设备未连接或处于本地配方"); - MessageNotify.GetInstance.ShowRecipeLog($"配方名称:【{res.RecipeName}】\t 配方号:【{res.RecipeCode}】"); } - #endregion - - - - GVL_SmallStation.GetInstance.WindSendDosing = false; - App.Current.Dispatcher.Invoke(() => - { - Json.Data.Recipes.Remove(res); - }); - RecipeQueueTray[recipeNum].TryDequeue(out code); - GVL_SmallStation.GetInstance.RecipeStockBinDosing[recipeNum] = 0; - GVL_SmallStation.GetInstance.RecipeProcessStatus[recipeNum] = 0; - MessageNotify.GetInstance.ShowRunLog($"配方【{res.RecipeCode}】,配料流程完成。"); } + else + { + MessageNotify.GetInstance.ShowRunLog($"托盘1,配方【{code}】,配料完成,为本地配方,不发送完成数据。"); + GVL_SmallStation.GetInstance.RecipeProcessStatus[recipeNum] = 40; + } + } + #endregion + + #region 发送完成数据完成,清理本地流程数据。 + if (GVL_SmallStation.GetInstance.RecipeProcessStatus[recipeNum] == 40) + { + var res = Json.Data.Recipes.FirstOrDefault(p => p.RecipeCode == code); + GVL_SmallStation.GetInstance.WindSendDosing = false; + App.Current.Dispatcher.Invoke(() => + { + Json.Data.Recipes.Remove(res); + }); + RecipeQueueTray[recipeNum].TryDequeue(out code); + GVL_SmallStation.GetInstance.RecipeStockBinDosing[recipeNum] = 0; + GVL_SmallStation.GetInstance.RecipeProcessStatus[recipeNum] = 0; + MessageNotify.GetInstance.ShowRunLog($"配方【{code}】,配料流程完成。"); + } + #endregion + + } } } @@ -1480,7 +1560,9 @@ namespace BPASmartClient.JXJFoodSmallStation.Model ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write("DB44.DBX0.4", true);}), "CLearRecipeInfo", true); ActionManage.GetInstance.Register(new Action(() => { + MessageNotify.GetInstance.ShowRunLog("系统流程开始复位。"); Json.Data.Recipes.Clear(); + MessageNotify.GetInstance.ShowRunLog("远程配方数据已清空。"); GVL_SmallStation.GetInstance.SiemensSendRecipeStatus = 0; GVL_SmallStation.GetInstance.WindSendDosingStatus = 0; @@ -1489,20 +1571,23 @@ namespace BPASmartClient.JXJFoodSmallStation.Model GVL_SmallStation.GetInstance.Order_Cancel = false; GVL_SmallStation.GetInstance.Order_CancelRecipeCode = ""; GVL_SmallStation.GetInstance.OrderCancelStep = 0; - + MessageNotify.GetInstance.ShowRunLog("系统流程变量已复位。"); for (int i = 0; i < 5; i++) { RecipeQueueTray[i].Clear(); GVL_SmallStation.GetInstance.RecipeProcessStatus[i] = 0; GVL_SmallStation.GetInstance.Tray_AGVLogic[i] = 0; } + MessageNotify.GetInstance.ShowRunLog("配方队列已清空。"); StockBinInit(); + MessageNotify.GetInstance.ShowRunLog("料仓初始化完成。"); WindSendReset(); + MessageNotify.GetInstance.ShowRunLog("风送系统复位完成。"); //for (int i = 0; i < GVL_SmallStation.GetInstance.StockInDosingComple.Length; i++) //{ // GVL_SmallStation.GetInstance.StockInDosingComple[i] = false; //} - MessageNotify.GetInstance.ShowRunLog("系统流程复位,等待西门子重新下发订单"); + MessageNotify.GetInstance.ShowRunLog("系统流程复位结束,等待西门子重新下发订单"); }), "BPASystemReset", true); //往海科PLC写值 @@ -1802,28 +1887,44 @@ namespace BPASmartClient.JXJFoodSmallStation.Model } return result; } - private void SendFinishData(XL_Finish_DB finishData) + /// + /// 发送操作,直到收到确认信号 + /// + /// + /// + /// + /// + /// + private bool SendDataOperation(Action operate,Func ack,int retrySecond=3) { - var isConnected = SiemensDevice.IsConnected; - - if (isConnected) + if (operate is null) { - SiemensDevice.Siemens_PLC_S7.WriteClass(finishData, 2261); + throw new ArgumentNullException("operate", "需要执行的操作不可为Null。"); } - - - //读取mes是否收到完成数据。 - if (SiemensDevice.Siemens_PLC_S7.Read("DB2261.DBX0.0")==true) + if (ack is null) { - MessageNotify.GetInstance.ShowRunLog("发送了完成数据"); + throw new ArgumentNullException("ack", "验证确认的委托不可为Null。"); } - else - { - } + var isSuccess = false; + var isConnected = SiemensDevice.IsConnected; + var retryDelay = TimeSpan.FromSeconds(retrySecond); + operate?.Invoke(); + + isSuccess = ack.Invoke(); + while (!isSuccess) + { + if (isConnected) + { + Thread.Sleep(retryDelay); + operate?.Invoke(); + isSuccess = isSuccess && ack.Invoke(); + } + } + return isSuccess; } } }