From b7e7b8618a43c3b5567449412abe93a2562a4ed7 Mon Sep 17 00:00:00 2001 From: pengliangyang <1406009520@qq.com> Date: Fri, 11 Nov 2022 11:15:37 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=89=E9=A6=99=E5=B1=85=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Model/GVL_BigStation.cs | 3 +- .../Model/ProcessControl.cs | 164 +++++++++++-- .../Model/Siemens/DL_Status_DB.cs | 21 +- .../Model/Siemens/SiemensDeviceStatus.cs | 39 ++- .../App.xaml.cs | 2 + .../Model/GVL_SmallStation.cs | 8 +- .../Model/ProcessControl.cs | 222 ++++++++++++++---- .../Model/Siemens/SiemensDeviceStatus.cs | 74 ++++-- .../Model/Siemens/XL_Finish_DB.cs | 6 +- .../Model/Siemens/XL_Start_DB.cs | 4 +- .../Model/Siemens/XL_Status_DB.cs | 2 +- BPASmartClient.S7Net/EntityClassResolution.cs | 2 - BPASmartClient.S7Net/SiemensHelper.cs | 8 + 13 files changed, 442 insertions(+), 113 deletions(-) diff --git a/BPASmartClient.JXJFoodBigStation/Model/GVL_BigStation.cs b/BPASmartClient.JXJFoodBigStation/Model/GVL_BigStation.cs index 902b256c..51deb3bd 100644 --- a/BPASmartClient.JXJFoodBigStation/Model/GVL_BigStation.cs +++ b/BPASmartClient.JXJFoodBigStation/Model/GVL_BigStation.cs @@ -39,7 +39,8 @@ namespace BPASmartClient.JXJFoodBigStation.Model /// 订单请求 /// public static bool Order_Request { get; set; } = false; + public static int SiemensSendRecipeStatus { get; set; } = 0; - public const int StockBinNum = 12; + public const int Max_DosingSotckBinNum = 14; } } diff --git a/BPASmartClient.JXJFoodBigStation/Model/ProcessControl.cs b/BPASmartClient.JXJFoodBigStation/Model/ProcessControl.cs index d312f5e9..b80059a4 100644 --- a/BPASmartClient.JXJFoodBigStation/Model/ProcessControl.cs +++ b/BPASmartClient.JXJFoodBigStation/Model/ProcessControl.cs @@ -49,12 +49,12 @@ namespace BPASmartClient.JXJFoodBigStation.Model ActionManage.GetInstance.Register(new Action((res) => { ObservableCollection RawMaterials = new ObservableCollection(); - if (SiemensDevice.IsConnected ||true) + if (SiemensDevice.IsConnected) { if (res != null && res is DL_Start_DB recipe) { RawMaterials.Clear(); - for (int i = 0; i < 12; i++) + for (int i = 0; i < GVL_BigStation.Max_DosingSotckBinNum; i++) { if (RawMaterialsNamePos.ContainsKey(recipe.Material[i].Material_Name)) { @@ -71,12 +71,15 @@ namespace BPASmartClient.JXJFoodBigStation.Model //报警,配方的原料名称下发和设备不一致 } } - Json.Data.Recipes.Add(new RecipeData() + App.Current.Dispatcher.Invoke(() => { - RecipeName = recipe.RecipeName, - RecipeCode = recipe.RecipeCode, - RawMaterial = RawMaterials, - //TrayCode = recipe.Order_No, + Json.Data.Recipes.Add(new RecipeData() + { + RecipeName = recipe.RecipeName, + RecipeCode = recipe.RecipeCode, + RawMaterial = RawMaterials, + TrayCode = recipe.Job_No, + }); }); } } @@ -86,7 +89,7 @@ namespace BPASmartClient.JXJFoodBigStation.Model try { //HKDevice.HK_PLC_S7.Connect(S7.Net.CpuType.S71500, HK_PLC_IP); - //SiemensDevice.Siemens_PLC_S7.Connect(S7.Net.CpuType.S71500, Siemens_PLC_IP); + SiemensDevice.Siemens_PLC_S7.Connect(S7.Net.CpuType.S71500, Siemens_PLC_IP); if (HKDevice.IsConnected) { HKDevice.Init(); @@ -132,25 +135,134 @@ namespace BPASmartClient.JXJFoodBigStation.Model { foreach (var data in Recipes) { - if (RecipeQueue1.Count == 0 && !RecipeQueue2.Contains(data.RecipeCode) && !RecipeQueue3.Contains(data.RecipeCode) && !RecipeQueue4.Contains(data.RecipeCode)) + if (RecipeQueue1.Count == 0 && !RecipeQueue2.Contains(data.RecipeCode) && !RecipeQueue3.Contains(data.RecipeCode) && !RecipeQueue4.Contains(data.RecipeCode)) { if (!(RecipeQueue1.Contains(data.RecipeCode))) - RecipeQueue1.Enqueue(data.RecipeCode); + { + if (SiemensDevice.DL_Status is DL_Status_DB status) + { + if (GVL_BigStation.SiemensSendRecipeStatus == 3) + { + GVL_BigStation.SiemensSendRecipeStatus = 4; + SiemensDevice.Siemens_PLC_S7.WriteString(2331, data.RecipeCode, 10); + SiemensDevice.Siemens_PLC_S7.Write("DB2331.DBX28.0", true); + } + if (GVL_BigStation.SiemensSendRecipeStatus == 4) + { + if (SiemensDevice.DL_Status.Dosing_Start_ACK) + { + GVL_BigStation.SiemensSendRecipeStatus = 5; + SiemensDevice.Siemens_PLC_S7.WriteString(2331, "", 10); + SiemensDevice.Siemens_PLC_S7.Write("DB2331.DBX28.0", false); + } + } + if (GVL_BigStation.SiemensSendRecipeStatus == 5) + { + if (SiemensDevice.DL_Status.Dosing_Start_ACK == false) + { + GVL_BigStation.SiemensSendRecipeStatus = 6; + RecipeQueue1.Enqueue(data.RecipeCode); + } + } + } + + } } - else if (RecipeQueue2.Count == 0 && !RecipeQueue1.Contains(data.RecipeCode) && !RecipeQueue3.Contains(data.RecipeCode) && !RecipeQueue4.Contains(data.RecipeCode)) + else if (RecipeQueue2.Count == 0 && !RecipeQueue1.Contains(data.RecipeCode) && !RecipeQueue3.Contains(data.RecipeCode) && !RecipeQueue4.Contains(data.RecipeCode)) { if (!(RecipeQueue2.Contains(data.RecipeCode))) - RecipeQueue2.Enqueue(data.RecipeCode); + { + if (SiemensDevice.DL_Status is DL_Status_DB status) + { + if (GVL_BigStation.SiemensSendRecipeStatus == 3) + { + GVL_BigStation.SiemensSendRecipeStatus = 4; + SiemensDevice.Siemens_PLC_S7.WriteString(2331, data.RecipeCode, 10); + SiemensDevice.Siemens_PLC_S7.Write("DB2331.DBX28.0", true); + } + if (GVL_BigStation.SiemensSendRecipeStatus == 4) + { + if (SiemensDevice.DL_Status.Dosing_Start_ACK) + { + GVL_BigStation.SiemensSendRecipeStatus = 5; + SiemensDevice.Siemens_PLC_S7.WriteString(2331, "", 10); + SiemensDevice.Siemens_PLC_S7.Write("DB3231.DBX28.0", false); + } + } + if (GVL_BigStation.SiemensSendRecipeStatus == 5) + { + if (SiemensDevice.DL_Status.Dosing_Start_ACK == false) + { + GVL_BigStation.SiemensSendRecipeStatus = 6; + RecipeQueue2.Enqueue(data.RecipeCode); + } + } + } + } } else if (RecipeQueue3.Count == 0 && !RecipeQueue1.Contains(data.RecipeCode) && !RecipeQueue2.Contains(data.RecipeCode) && !RecipeQueue4.Contains(data.RecipeCode)) { - if (!(RecipeQueue3.Contains(data.RecipeCode))) - RecipeQueue3.Enqueue(data.RecipeCode); + if (!(RecipeQueue3.Contains(data.RecipeCode))) + { + if (SiemensDevice.DL_Status is DL_Status_DB status) + { + if (GVL_BigStation.SiemensSendRecipeStatus == 3) + { + GVL_BigStation.SiemensSendRecipeStatus = 4; + SiemensDevice.Siemens_PLC_S7.WriteString(2331, data.RecipeCode, 10); + SiemensDevice.Siemens_PLC_S7.Write("DB2331.DBX28.0", true); + } + if (GVL_BigStation.SiemensSendRecipeStatus == 4) + { + if (SiemensDevice.DL_Status.Dosing_Start_ACK) + { + GVL_BigStation.SiemensSendRecipeStatus = 5; + SiemensDevice.Siemens_PLC_S7.WriteString(2331, "", 10); + SiemensDevice.Siemens_PLC_S7.Write("DB3231.DBX28.0", false); + } + } + if (GVL_BigStation.SiemensSendRecipeStatus == 5) + { + if (SiemensDevice.DL_Status.Dosing_Start_ACK == false) + { + GVL_BigStation.SiemensSendRecipeStatus = 6; + RecipeQueue3.Enqueue(data.RecipeCode); + } + } + } + } } else if (RecipeQueue4.Count == 0 && !RecipeQueue1.Contains(data.RecipeCode) && !RecipeQueue2.Contains(data.RecipeCode) && !RecipeQueue3.Contains(data.RecipeCode)) { - if (!(RecipeQueue4.Contains(data.RecipeCode))) - RecipeQueue4.Enqueue(data.RecipeCode); + if (!(RecipeQueue4.Contains(data.RecipeCode))) + { + if (SiemensDevice.DL_Status is DL_Status_DB status) + { + if (GVL_BigStation.SiemensSendRecipeStatus == 3) + { + GVL_BigStation.SiemensSendRecipeStatus = 4; + SiemensDevice.Siemens_PLC_S7.WriteString(2331, data.RecipeCode, 10); + SiemensDevice.Siemens_PLC_S7.Write("DB2331.DBX28.0", true); + } + if (GVL_BigStation.SiemensSendRecipeStatus == 4) + { + if (SiemensDevice.DL_Status.Dosing_Start_ACK) + { + GVL_BigStation.SiemensSendRecipeStatus = 5; + SiemensDevice.Siemens_PLC_S7.WriteString(2331, "", 10); + SiemensDevice.Siemens_PLC_S7.Write("DB3231.DBX28.0", false); + } + } + if (GVL_BigStation.SiemensSendRecipeStatus == 5) + { + if (SiemensDevice.DL_Status.Dosing_Start_ACK == false) + { + GVL_BigStation.SiemensSendRecipeStatus = 6; + RecipeQueue4.Enqueue(data.RecipeCode); + } + } + } + } } } } @@ -266,6 +378,8 @@ namespace BPASmartClient.JXJFoodBigStation.Model } if (SiemensDevice.IsConnected) { + FinishData.Ask_For_Finish = true; + GVL_BigStation.SiemensSendRecipeStatus = 7; SiemensDevice.Siemens_PLC_S7.WriteClass(FinishData, 2361); } RecipeQueue1.TryDequeue(out code); @@ -705,6 +819,22 @@ namespace BPASmartClient.JXJFoodBigStation.Model RawMaterialsNamePos.Clear(); if (!HKDevice.IsConnected) { + RawMaterialsNamePos.Add("A10", 1); + RawMaterialsNamePos.Add("A20", 2); + RawMaterialsNamePos.Add("A30", 3); + RawMaterialsNamePos.Add("A40", 4); + RawMaterialsNamePos.Add("A50", 5); + RawMaterialsNamePos.Add("A60", 6); + RawMaterialsNamePos.Add("A70", 7); + RawMaterialsNamePos.Add("A80", 8); + RawMaterialsNamePos.Add("A90", 9); + RawMaterialsNamePos.Add("A100", 10); + RawMaterialsNamePos.Add("A110", 11); + RawMaterialsNamePos.Add("A120", 12); + RawMaterialsNamePos.Add("A130", 13); + RawMaterialsNamePos.Add("A140", 14); + } +/* HKDevice.StockBinName.RawMaterialName1 = "1"; HKDevice.StockBinName.RawMaterialName2 = "2"; HKDevice.StockBinName.RawMaterialName3 = "3"; @@ -775,7 +905,7 @@ namespace BPASmartClient.JXJFoodBigStation.Model if (!RawMaterialsNamePos.ContainsKey(HKDevice.StockBinName.RawMaterialName14)) { RawMaterialsNamePos.Add(HKDevice.StockBinName.RawMaterialName14, 14); - } + }*/ } } } diff --git a/BPASmartClient.JXJFoodBigStation/Model/Siemens/DL_Status_DB.cs b/BPASmartClient.JXJFoodBigStation/Model/Siemens/DL_Status_DB.cs index 56c74a2f..90077656 100644 --- a/BPASmartClient.JXJFoodBigStation/Model/Siemens/DL_Status_DB.cs +++ b/BPASmartClient.JXJFoodBigStation/Model/Siemens/DL_Status_DB.cs @@ -7,12 +7,12 @@ using System.Threading.Tasks; namespace BPASmartClient.JXJFoodBigStation.Model.Siemens { - internal class DL_Status_DB + public class DL_Status_DB { /// - /// 配料开始 + /// 配料开始确认 /// - public bool Dosing_Start { get; set; } + public bool Dosing_Start_ACK { get; set; } /// /// 配料开始确认 /// @@ -29,18 +29,21 @@ namespace BPASmartClient.JXJFoodBigStation.Model.Siemens /// 生产工单 /// public string RecipeCode { get; set; } - public bool Dosing_Cancel4 { get; set; } + /// + /// 配料开始 + /// + public bool Dosing_Start { get; set; } - public bool Dosing_Cancel5 { get; set; } + public bool Allow_Agv_Put { get; set; } - public bool Dosing_Cancel6 { get; set; } + public bool Allow_Agv_Get { get; set; } - public bool Dosing_Cancel7 { get; set; } + public bool Allow_Agv_Get_Empty { get; set; } - public short Dosing_Cancel8 { get; set; } + public short Pallet_Position_Occ { get; set; } public short Dosing_Cancel9 { get; set; } - public short[] Standby2 { get; set; } = new short[4]; + public short[] Standby2 { get; set; } = new short[3]; } } diff --git a/BPASmartClient.JXJFoodBigStation/Model/Siemens/SiemensDeviceStatus.cs b/BPASmartClient.JXJFoodBigStation/Model/Siemens/SiemensDeviceStatus.cs index d02a7bab..4631b4dd 100644 --- a/BPASmartClient.JXJFoodBigStation/Model/Siemens/SiemensDeviceStatus.cs +++ b/BPASmartClient.JXJFoodBigStation/Model/Siemens/SiemensDeviceStatus.cs @@ -15,6 +15,7 @@ namespace BPASmartClient.JXJFoodBigStation.Model.Siemens public SiemensHelper Siemens_PLC_S7 = new SiemensHelper(); public bool IsConnected => Siemens_PLC_S7.IsConnected; + public DL_Status_DB DL_Status = new DL_Status_DB(); bool a = false; public void Init() { @@ -34,7 +35,7 @@ namespace BPASmartClient.JXJFoodBigStation.Model.Siemens start.RecipeCode = "1201"; start.Order_Request_Ack = true; - for (int i = 0; i < GVL_BigStation.StockBinNum ; i++) + for (int i = 0; i < GVL_BigStation.Max_DosingSotckBinNum ; i++) { start.Material[i] = new UDT(); start.Material[i].Material_Name = "" + (i +1); @@ -42,25 +43,43 @@ namespace BPASmartClient.JXJFoodBigStation.Model.Siemens start.Material[i].Material_BarrelNum = (short)(i + 1); } } - if (RTrig.GetInstance("Order_Request").Start(GVL_BigStation.Order_Request)) + if (RTrig.GetInstance("Order_Request").Start(GVL_BigStation.Order_Request) && GVL_BigStation.SiemensSendRecipeStatus == 0) { - start.Order_Request = true; - Siemens_PLC_S7.WriteClass(start, 2301); + GVL_BigStation.SiemensSendRecipeStatus = 1; + this.Siemens_PLC_S7.Write("DB2301.DBX330.0", true); } - if (RTrig.GetInstance("Order_Request_Ack").Start(start.Order_Request_Ack)) + if (RTrig.GetInstance("Order_Request_Ack").Start(start.Order_Request_Ack) && GVL_BigStation.SiemensSendRecipeStatus == 1) { + GVL_BigStation.SiemensSendRecipeStatus = 2; ActionManage.GetInstance.Send("SiemensSendRecipe", start); + this.Siemens_PLC_S7.Write("DB2301.DBX330.0", false); + } + if (TTrig.GetInstance("Order_Request_Ack").Start(start.Order_Request_Ack) && GVL_BigStation.SiemensSendRecipeStatus == 2) + { + GVL_BigStation.SiemensSendRecipeStatus = 3; + GVL_BigStation.Order_Request = false; } } if (res1 != null && res1 is DL_Status_DB status) { - + DL_Status = status; } - if (res2 != null && res2.Ask_For_Finish_PLC) + if (res2 != null && res2 is DL_Finish_DB finish) { - ActionManage.GetInstance.Send("配料完成信号确认完成"); - res2.Ask_For_Finish_PLC = false; - this.Siemens_PLC_S7.WriteClass(res2, 3); + if (RTrig.GetInstance("Ask_For_Finish_PLC").Start(finish.Ask_For_Finish_PLC) && GVL_BigStation.SiemensSendRecipeStatus == 7) + { + finish.Order_No = ""; + finish.Product_Code = ""; + finish.job_No = 0; + for (int i = 0; i < 20; i++) + { + finish.Material[i] = new UDT1(); + } + GVL_BigStation.SiemensSendRecipeStatus = 0; + finish.Ask_For_Finish = false; + finish.ProcessTime = 0; + this.Siemens_PLC_S7.WriteClass(finish, 2261); + } } Thread.Sleep(10); }), "监听服务数据"); diff --git a/BPASmartClient.JXJFoodSmallStation/App.xaml.cs b/BPASmartClient.JXJFoodSmallStation/App.xaml.cs index d118ec64..e5787289 100644 --- a/BPASmartClient.JXJFoodSmallStation/App.xaml.cs +++ b/BPASmartClient.JXJFoodSmallStation/App.xaml.cs @@ -48,6 +48,7 @@ namespace BPASmartClient.JXJFoodSmallStation base.OnExit(e); Json.Save(); Json.Save(); + Json.Save(); MessageNotify.GetInstance.LogSave(); ThreadManage.GetInstance().Dispose(); } @@ -268,6 +269,7 @@ namespace BPASmartClient.JXJFoodSmallStation Json.Read(); Json.Read(); Json.Read(); + Json.Read(); } } diff --git a/BPASmartClient.JXJFoodSmallStation/Model/GVL_SmallStation.cs b/BPASmartClient.JXJFoodSmallStation/Model/GVL_SmallStation.cs index 5f6cf940..4bfa8690 100644 --- a/BPASmartClient.JXJFoodSmallStation/Model/GVL_SmallStation.cs +++ b/BPASmartClient.JXJFoodSmallStation/Model/GVL_SmallStation.cs @@ -23,14 +23,17 @@ namespace BPASmartClient.JXJFoodSmallStation.Model /// /// 风送料仓数目 /// - public const int Max_PowderSotckBinNum = 15; + public const int Max_PowderSotckBinNum = 5; public bool HeartBeatToPlc { get; set; } = false; public bool HeartBeatFromPlc { get; set; } = false; /// /// 是否允许西门子下发配方 /// public static bool IsAllowSiemensSendRecipe { get; set; } = false; - + /// + /// 西门子下发配方状态 0:等待下发配方 1:请求下发配方 2:上位机接收配方 3:配方接收完成 4:请求配料 5:西门子开始配料确认 6:配方配料完成 7:配料完成确认 + /// + public static int SiemensSendRecipeStatus { get; set; } = 0; /// /// 往输送带下发配方完成 /// @@ -114,6 +117,7 @@ namespace BPASmartClient.JXJFoodSmallStation.Model /// 是否使用本地模拟订单+风送配方 /// public bool IsUseWindSendDosing { get; set; } + public static int test1 = 1; #endregion } } diff --git a/BPASmartClient.JXJFoodSmallStation/Model/ProcessControl.cs b/BPASmartClient.JXJFoodSmallStation/Model/ProcessControl.cs index 26e477ec..25aee4c5 100644 --- a/BPASmartClient.JXJFoodSmallStation/Model/ProcessControl.cs +++ b/BPASmartClient.JXJFoodSmallStation/Model/ProcessControl.cs @@ -50,6 +50,7 @@ namespace BPASmartClient.JXJFoodSmallStation.Model public RecipeRawMaterial RawMaterial; public void Init() { + testData(); for (int i = 0; i < 16; i++) { if (DeviceInquire.GetInstance.GetDevice(i).DeviceName != null) @@ -69,57 +70,91 @@ namespace BPASmartClient.JXJFoodSmallStation.Model { if (res != null && res is XL_Start_DB recipe) { - RawMaterials.Clear(); - for (int i = 0; i < GVL_SmallStation.Max_DosingSotckBinNum; i++) - { - if (!string.IsNullOrEmpty(recipe.Material[i].Material_Name)) + if (!string.IsNullOrEmpty(recipe.RecipeCode)) { + RawMaterials.Clear(); + for (int i = 0; i < GVL_SmallStation.Max_DosingSotckBinNum; i++) { - if (RawMaterialsNamePos.ContainsKey(recipe.Material[i].Material_Name)) + if (!string.IsNullOrEmpty(recipe.Material[i].Material_Name)) { - RawMaterials.Add(new RemoteRecipeRawMaterial() + if (RawMaterialsNamePos.ContainsKey(recipe.Material[i].Material_Name)) { - RawMaterialName = recipe.Material[i].Material_Name, - RawMaterialBarrelNum = recipe.Material[i].Material_BarrelNum, - RawMaterialWeight = recipe.Material[i].Material_Weight, - RawMaterialLocation = (int)RawMaterialsNamePos[recipe.Material[i].Material_Name] - }); + RawMaterials.Add(new RemoteRecipeRawMaterial() + { + RawMaterialName = recipe.Material[i].Material_Name, + RawMaterialBarrelNum = recipe.Material[i].Material_BarrelNum, + RawMaterialWeight = recipe.Material[i].Material_Weight, + RawMaterialLocation = (int)RawMaterialsNamePos[recipe.Material[i].Material_Name] + }); + } + else + { + //MessageNotify.GetInstance.AlarmLog("配方名称与本地不符合"); + } } else { - //MessageNotify.GetInstance.AlarmLog("配方名称与本地不符合"); + break; } } - else + for (int i = 0; i < GVL_SmallStation.Max_PowderSotckBinNum; i++) { - break; + if (!string.IsNullOrEmpty(recipe.Powder[i].Powder_Name)) + { + WindSendData.Add(new WindSendRawMaterial() + { + RawMaterialName = recipe.Powder[i].Powder_Name, + RawMaterialWeight = recipe.Powder[i].Powder_Weight + }); + } + else + { + break; + } } - } - for (int i = 0; i < GVL_SmallStation.Max_PowderSotckBinNum; i++) - { - if (!string.IsNullOrEmpty(recipe.Powder[i].Powder_Name)) - { - WindSendData.Add(new WindSendRawMaterial() + App.Current.Dispatcher.Invoke(() => { + Json.Data.Recipes.Add(new RemoteRecipeData() { - RawMaterialName = recipe.Powder[i].Powder_Name, - RawMaterialWeight = recipe.Powder[i].Powder_Weight + RecipeName = recipe.RecipeName, + RecipeCode = recipe.RecipeCode, + RawMaterial = RawMaterials, + TrayCode = recipe.StockCode, + WindSend = WindSendData }); - } - else - { - break; - } + }); } - Json.Data.Recipes.Add(new RemoteRecipeData() - { - RecipeName = recipe.RecipeName, - RecipeCode = recipe.RecipeCode, - RawMaterial = RawMaterials, - TrayCode = recipe.TrayCode, - WindSend = WindSendData - }); } } }), "SiemensRecipeRecive", true); + ActionManage.GetInstance.CancelRegister("SiemensRecipeFinish"); + ActionManage.GetInstance.Register(new Action((res) => + { + if (SiemensDevice.IsConnected) + { + if (res != null && res is RemoteRecipeData recipe) + { + RecipeFinishInfo.Order_No = recipe.RecipeCode; + RecipeFinishInfo.Product_Code = recipe.RecipeName; + RecipeFinishInfo.Job_No = (short)recipe.TrayCode; + for (int i = 0; i < recipe.RawMaterial.Count; i++) + { + RecipeFinishInfo.Material[i] = new UDT1(); + RecipeFinishInfo.Material[i].Material_Name = recipe.RawMaterial.ElementAt(i).RawMaterialName; + RecipeFinishInfo.Material[i].Material_BarrelNum = recipe.RawMaterial.ElementAt(i).RawMaterialBarrelNum; + RecipeFinishInfo.Material[i].Material_Laying_Off_Weight = recipe.RawMaterial.ElementAt(i).Laying_Off_Weight; + } + for (int i = 0; i < recipe.WindSend.Count; i++) + { + RecipeFinishInfo.Powder[i] = new UDT2(); + } + if (GVL_SmallStation.SiemensSendRecipeStatus == 6) + { + GVL_SmallStation.SiemensSendRecipeStatus = 7; + RecipeFinishInfo.Ask_For_Finish = true; + SiemensDevice.Siemens_PLC_S7.WriteClass(RecipeFinishInfo, 2261); + } + } + } + }), "SiemensRecipeFinish", true); ActionManage.GetInstance.CancelRegister("WindSendDosingFinish"); ActionManage.GetInstance.Register(new Action(() => { @@ -644,7 +679,6 @@ namespace BPASmartClient.JXJFoodSmallStation.Model GVL_SmallStation.GetInstance.HeartBeatToPlc = !GVL_SmallStation.GetInstance.HeartBeatToPlc; HKDevice.HK_PLC_S7.Write("DB4.DBX0.0", GVL_SmallStation.GetInstance.HeartBeatToPlc); GVL_SmallStation.GetInstance.HeartBeatFromPlc = HKDevice.HK_PLC_S7.Read("DB3.DBX0.0"); - } } /// @@ -661,14 +695,66 @@ namespace BPASmartClient.JXJFoodSmallStation.Model { if (!(RecipeQueue.Contains(data.RecipeCode))) { - RecipeQueue.Enqueue(data.RecipeCode); + if (SiemensDevice.XL_Status is XL_Status_DB status) + { + if (GVL_SmallStation.SiemensSendRecipeStatus == 3) + { + GVL_SmallStation.SiemensSendRecipeStatus = 4; + SiemensDevice.Siemens_PLC_S7.WriteString(2231, data.RecipeCode,10); + SiemensDevice.Siemens_PLC_S7.Write("DB2231.DBX28.0",true); + } + if (GVL_SmallStation.SiemensSendRecipeStatus == 4) + { + if (SiemensDevice.XL_Status.Dosing_Confirm) + { + GVL_SmallStation.SiemensSendRecipeStatus = 5; + SiemensDevice.Siemens_PLC_S7.WriteString(2231, "", 10); + SiemensDevice.Siemens_PLC_S7.Write("DB2231.DBX28.0", false); + } + } + if (GVL_SmallStation.SiemensSendRecipeStatus == 5) + { + if (SiemensDevice.XL_Status.Dosing_Confirm == false) + { + GVL_SmallStation.SiemensSendRecipeStatus = 6; + RecipeQueue.Enqueue(data.RecipeCode); + } + + } + + } } } - else if(data.TrayCode == 2) + else if (data.TrayCode == 2) { if (!(RecipeQueueTray2.Contains(data.RecipeCode))) { - RecipeQueueTray2.Enqueue(data.RecipeCode); + if (SiemensDevice.XL_Status is XL_Status_DB status) + { + if (GVL_SmallStation.SiemensSendRecipeStatus == 3) + { + GVL_SmallStation.SiemensSendRecipeStatus = 4; + SiemensDevice.Siemens_PLC_S7.WriteString(2231, data.RecipeCode, 10); + SiemensDevice.Siemens_PLC_S7.Write("DB2231.DBX28.0", true); + } + if (GVL_SmallStation.SiemensSendRecipeStatus == 4) + { + if (SiemensDevice.XL_Status.Dosing_Confirm) + { + GVL_SmallStation.SiemensSendRecipeStatus = 5; + SiemensDevice.Siemens_PLC_S7.WriteString(2231, "", 10); + SiemensDevice.Siemens_PLC_S7.Write("DB2231.DBX28.0", false); + } + } + if (GVL_SmallStation.SiemensSendRecipeStatus == 5) + { + if (SiemensDevice.XL_Status.Dosing_Confirm == false) + { + GVL_SmallStation.SiemensSendRecipeStatus = 0; + RecipeQueueTray2.Enqueue(data.RecipeCode); + } + } + } } } } @@ -851,23 +937,39 @@ namespace BPASmartClient.JXJFoodSmallStation.Model } } - if (RTrig.GetInstance("配方配料完成").Start(HKDevice.HK_PLC_S7.Read("DB3.DBX1.1")) && (GVL_SmallStation.GetInstance.WindSendDosingFinish || !GVL_SmallStation.GetInstance.IsUseWindSend)) + if ((RTrig.GetInstance("配方配料完成").Start(HKDevice.HK_PLC_S7.Read("DB3.DBX1.1")) && (GVL_SmallStation.GetInstance.WindSendDosingFinish || !GVL_SmallStation.GetInstance.IsUseWindSend)) || GVL_SmallStation.GetInstance.RecipeStatusID == 5) { var res = Json.Data.Recipes.FirstOrDefault(p => p.RecipeCode == code); MessageNotify.GetInstance.ShowRunLog($"托盘1,配方{res.RecipeName},配料完成"); - RecipeFinishInfo.Order_No = RemoteRecipes.ElementAt(index).RecipeCode; - RecipeFinishInfo.Product_Code = RemoteRecipes.ElementAt(index).RecipeName; - for (int i = 0; i < RemoteRecipes.ElementAt(index).RawMaterial.Count; i++) - { - RecipeFinishInfo.Material[i] = new UDT1(); - 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; - } if (SiemensDevice.IsConnected) { - RecipeFinishInfo.Ask_For_Finish = true; - SiemensDevice.Siemens_PLC_S7.WriteClass(RecipeFinishInfo, 2261); + 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++) + { + RecipeFinishInfo.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; + } + for (int i = 0; i < RemoteRecipes.ElementAt(index).WindSend.Count; i++) + { + + } + if (GVL_SmallStation.SiemensSendRecipeStatus == 6) + { + GVL_SmallStation.SiemensSendRecipeStatus = 7; + RecipeFinishInfo.Ask_For_Finish = true; + SiemensDevice.Siemens_PLC_S7.WriteClass(RecipeFinishInfo, 2261); + } } App.Current.Dispatcher.Invoke(() => { @@ -1079,5 +1181,23 @@ namespace BPASmartClient.JXJFoodSmallStation.Model } } } + private void testData() + { + RawMaterialsNamePos.Add("A10", 1); + RawMaterialsNamePos.Add("A20", 2); + RawMaterialsNamePos.Add("A30", 3); + RawMaterialsNamePos.Add("A40", 4); + RawMaterialsNamePos.Add("A50", 5); + RawMaterialsNamePos.Add("A60", 6); + RawMaterialsNamePos.Add("A70", 7); + RawMaterialsNamePos.Add("A80", 8); + RawMaterialsNamePos.Add("A90", 9); + RawMaterialsNamePos.Add("A100", 10); + RawMaterialsNamePos.Add("A110", 11); + RawMaterialsNamePos.Add("A120", 12); + RawMaterialsNamePos.Add("A130", 13); + RawMaterialsNamePos.Add("A140", 14); + RawMaterialsNamePos.Add("A150", 15); + } } } diff --git a/BPASmartClient.JXJFoodSmallStation/Model/Siemens/SiemensDeviceStatus.cs b/BPASmartClient.JXJFoodSmallStation/Model/Siemens/SiemensDeviceStatus.cs index e17aeaaf..b62daf28 100644 --- a/BPASmartClient.JXJFoodSmallStation/Model/Siemens/SiemensDeviceStatus.cs +++ b/BPASmartClient.JXJFoodSmallStation/Model/Siemens/SiemensDeviceStatus.cs @@ -14,34 +14,79 @@ namespace BPASmartClient.JXJFoodSmallStation.Model.Siemens { public SiemensHelper Siemens_PLC_S7 = new SiemensHelper(); public bool IsConnected => Siemens_PLC_S7.IsConnected; - + public XL_Status_DB XL_Status = new XL_Status_DB(); + bool test; public void Init() { if (IsConnected) { - ThreadManage.GetInstance().StartLong(new Action(() => + ThreadManage.GetInstance().StartLong(new Action(() => { var Start = this.Siemens_PLC_S7.ReadClass(2201); var Status = this.Siemens_PLC_S7.ReadClass(2231); var Finish = this.Siemens_PLC_S7.ReadClass(2261); var DataColl = this.Siemens_PLC_S7.ReadClass(2291); - if (Start != null && Start.Order_Request == false && GVL_SmallStation.IsAllowSiemensSendRecipe) + if (test) { - Start.Order_Request = true; - this.Siemens_PLC_S7.WriteClass(Start, 1); + for (int i = 0; i < XL_Status.Powder.Length; i++) { + + XL_Status.Powder.ElementAt(i).Powder_Name = ""+i; + } + Siemens_PLC_S7.WriteClass(XL_Status, 2231); } - if (Start != null && RTrig.GetInstance("RecipeTrig").Start(Start.Order_Request_ACK)) + if (Start != null && Start is XL_Start_DB st) { - ActionManage.GetInstance.Send("SiemensRecipeRecive", Start); - Start.Order_Request_ACK = false; - this.Siemens_PLC_S7.WriteClass(Start, 1); + if (RTrig.GetInstance("DB2201.DBX450.0").Start(GVL_SmallStation.IsAllowSiemensSendRecipe) && GVL_SmallStation.SiemensSendRecipeStatus == 0) + { + GVL_SmallStation.SiemensSendRecipeStatus = 1; + this.Siemens_PLC_S7.Write("DB2201.DBX450.0", true); + } + if (RTrig.GetInstance("Order_Request_ACK").Start(Start.Order_Request_ACK) && GVL_SmallStation.SiemensSendRecipeStatus == 1) + { + if (!string.IsNullOrEmpty(st.RecipeCode)) + { + GVL_SmallStation.SiemensSendRecipeStatus = 2; + ActionManage.GetInstance.Send("SiemensRecipeRecive", st); + this.Siemens_PLC_S7.Write("DB2201.DBX450.0", false); + } + } + if (TTrig.GetInstance("Order_Request_ACK_").Start(Start.Order_Request_ACK) && GVL_SmallStation.SiemensSendRecipeStatus == 2) + { + GVL_SmallStation.IsAllowSiemensSendRecipe = false; + GVL_SmallStation.SiemensSendRecipeStatus = 3; + //需要等待请求信号复位才能认为接收配方完成 + } } - - if (Status != null && RTrig.GetInstance("Allow_AGV_Put[0]").Start(Status.AgvRequestPut)) + if (Finish != null && Finish is XL_Finish_DB FinishData) { - ActionManage.GetInstance.Send("AGV放货架到位",Status); - Status.AgvRequestPut = false; - this.Siemens_PLC_S7.WriteClass(Status, 2); + if (RTrig.GetInstance("Ask_For_Finish_PLC").Start(FinishData.Ask_For_Finish_PLC) && GVL_SmallStation.SiemensSendRecipeStatus == 7) + { + FinishData.Order_No = ""; + FinishData.Product_Code = ""; + FinishData.Job_No = 0; + for (int i = 0; i < 20; i++) + { + FinishData.Material[i] = new UDT1(); + } + for (int i = 0; i < 10; i++) + { + FinishData.Powder[i] = new UDT2(); + } + GVL_SmallStation.SiemensSendRecipeStatus = 0; + FinishData.Ask_For_Finish = false; + FinishData.DosingTime = 0; + this.Siemens_PLC_S7.WriteClass(FinishData, 2261); + } + } + if (Status != null && Status is XL_Status_DB state) + { + XL_Status = state; + if (RTrig.GetInstance("Allow_AGV_Put[0]").Start(Status.AgvRequestPut)) + { + ActionManage.GetInstance.Send("AGV放货架到位", Status); + Status.AgvRequestPut = false; + this.Siemens_PLC_S7.WriteClass(Status, 2); + } } if (Status != null && RTrig.GetInstance("Allow_AGV_Put[1]").Start(Status.AgvRequestGet)) { @@ -49,7 +94,6 @@ namespace BPASmartClient.JXJFoodSmallStation.Model.Siemens Status.AgvRequestGet = false; this.Siemens_PLC_S7.WriteClass(Status, 2); } - Thread.Sleep(10); }),"监听服务数据"); } diff --git a/BPASmartClient.JXJFoodSmallStation/Model/Siemens/XL_Finish_DB.cs b/BPASmartClient.JXJFoodSmallStation/Model/Siemens/XL_Finish_DB.cs index c7ee07a7..66972b25 100644 --- a/BPASmartClient.JXJFoodSmallStation/Model/Siemens/XL_Finish_DB.cs +++ b/BPASmartClient.JXJFoodSmallStation/Model/Siemens/XL_Finish_DB.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace BPASmartClient.JXJFoodSmallStation.Model.Siemens { - internal class XL_Finish_DB + public class XL_Finish_DB { /// /// 配料完成信号确认 @@ -52,7 +52,7 @@ namespace BPASmartClient.JXJFoodSmallStation.Model.Siemens /// 原料名称 /// [Siemens(6)] - public string Material_Name { get; set; } + public string Material_Name { get; set; } = ""; /// /// 原料下料重量 /// @@ -68,7 +68,7 @@ namespace BPASmartClient.JXJFoodSmallStation.Model.Siemens /// 粉料仓名称 /// [Siemens(6)] - public string Powder_Name { get; set; } + public string Powder_Name { get; set; } = ""; /// /// 粉料仓重量 /// diff --git a/BPASmartClient.JXJFoodSmallStation/Model/Siemens/XL_Start_DB.cs b/BPASmartClient.JXJFoodSmallStation/Model/Siemens/XL_Start_DB.cs index db6be882..3746f978 100644 --- a/BPASmartClient.JXJFoodSmallStation/Model/Siemens/XL_Start_DB.cs +++ b/BPASmartClient.JXJFoodSmallStation/Model/Siemens/XL_Start_DB.cs @@ -51,7 +51,7 @@ namespace BPASmartClient.JXJFoodSmallStation.Model.Siemens /// /// 原料名称 /// - public string Material_Name { get; set; } + public string Material_Name { get; set; } = ""; /// /// 原料重量 /// @@ -69,7 +69,7 @@ namespace BPASmartClient.JXJFoodSmallStation.Model.Siemens /// 粉料仓名称 /// [Siemens(6)] - public string Powder_Name { get; set; } + public string Powder_Name { get; set; } = ""; /// /// 粉料仓重量 /// diff --git a/BPASmartClient.JXJFoodSmallStation/Model/Siemens/XL_Status_DB.cs b/BPASmartClient.JXJFoodSmallStation/Model/Siemens/XL_Status_DB.cs index 722a5774..97339485 100644 --- a/BPASmartClient.JXJFoodSmallStation/Model/Siemens/XL_Status_DB.cs +++ b/BPASmartClient.JXJFoodSmallStation/Model/Siemens/XL_Status_DB.cs @@ -78,7 +78,7 @@ namespace BPASmartClient.JXJFoodSmallStation.Model.Siemens /// 粉料名称 /// [Siemens(6)] - public string Powder_Name { get; set; } + public string Powder_Name { get; set; } = ""; /// /// 粉料仓剩余重量 /// diff --git a/BPASmartClient.S7Net/EntityClassResolution.cs b/BPASmartClient.S7Net/EntityClassResolution.cs index 01b52922..14f4e622 100644 --- a/BPASmartClient.S7Net/EntityClassResolution.cs +++ b/BPASmartClient.S7Net/EntityClassResolution.cs @@ -379,7 +379,6 @@ namespace BPASmartClient.S7Net { break; } - numBytes = SetBytesFromProperty(array.GetValue(i), bytes, numBytes, accessableProperty); } } @@ -388,7 +387,6 @@ namespace BPASmartClient.S7Net numBytes = SetBytesFromProperty(accessableProperty.GetValue(sourceClass, null), bytes, numBytes, accessableProperty); } } - return numBytes; } diff --git a/BPASmartClient.S7Net/SiemensHelper.cs b/BPASmartClient.S7Net/SiemensHelper.cs index 141fbb5c..2a428caa 100644 --- a/BPASmartClient.S7Net/SiemensHelper.cs +++ b/BPASmartClient.S7Net/SiemensHelper.cs @@ -1,4 +1,5 @@ using S7.Net; +using System.Text; namespace BPASmartClient.S7Net { @@ -89,6 +90,13 @@ namespace BPASmartClient.S7Net } } + public void WriteString(int db,string txt, int startAddress = 0) + { + var temp = Encoding.ASCII.GetBytes(txt); + var bytes = S7.Net.Types.S7String.ToByteArray(txt, temp.Length); + myPlc.WriteBytes(DataType.DataBlock,db, startAddress, bytes); + + } public TResult ReadClass(int db, int startByteAdr = 0) where TResult : class, new() { TResult sourceClass = new TResult();