From 5a9f7a35ee0f58b9776d2da587f9d4a39dd5a2b4 Mon Sep 17 00:00:00 2001 From: pengliangyang <1406009520@qq.com> Date: Wed, 19 Oct 2022 17:35:28 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=A7=E6=96=99=E7=AB=99=E7=A8=8B=E5=BA=8F?= =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BPASmartClient.JXJFoodBigStation/App.xaml.cs | 3 +- .../BPASmartClient.JXJFoodBigStation.csproj | 4 + .../Model/HK_PLC/DB_Read.cs | 12 ++ .../Model/HK_PLC/DB_Write.cs | 146 ++++++++++++++++++ .../Model/HK_PLC/HKDeviceStatus.cs | 56 ++++--- .../Model/HK_PLC/Test1.cs | 30 ++++ .../Model/ProcessControl.cs | 50 +++--- .../ViewModel/RecipeInfosViewModel.cs | 2 +- 8 files changed, 250 insertions(+), 53 deletions(-) create mode 100644 BPASmartClient.JXJFoodBigStation/Model/HK_PLC/DB_Read.cs create mode 100644 BPASmartClient.JXJFoodBigStation/Model/HK_PLC/DB_Write.cs create mode 100644 BPASmartClient.JXJFoodBigStation/Model/HK_PLC/Test1.cs diff --git a/BPASmartClient.JXJFoodBigStation/App.xaml.cs b/BPASmartClient.JXJFoodBigStation/App.xaml.cs index 600674cb..7d285245 100644 --- a/BPASmartClient.JXJFoodBigStation/App.xaml.cs +++ b/BPASmartClient.JXJFoodBigStation/App.xaml.cs @@ -46,7 +46,6 @@ namespace BPASmartClient.JXJFoodBigStation { base.OnExit(e); MessageLog.GetInstance.LogSave(); - Json.Save(); ThreadManage.GetInstance().Dispose(); } @@ -170,7 +169,7 @@ namespace BPASmartClient.JXJFoodBigStation { //Config.GetInstance.Init(); //Json.Read(); - Json.Read(); + Json.Read(); } } diff --git a/BPASmartClient.JXJFoodBigStation/BPASmartClient.JXJFoodBigStation.csproj b/BPASmartClient.JXJFoodBigStation/BPASmartClient.JXJFoodBigStation.csproj index 965d4327..0c148a2a 100644 --- a/BPASmartClient.JXJFoodBigStation/BPASmartClient.JXJFoodBigStation.csproj +++ b/BPASmartClient.JXJFoodBigStation/BPASmartClient.JXJFoodBigStation.csproj @@ -7,6 +7,10 @@ true + + + + diff --git a/BPASmartClient.JXJFoodBigStation/Model/HK_PLC/DB_Read.cs b/BPASmartClient.JXJFoodBigStation/Model/HK_PLC/DB_Read.cs new file mode 100644 index 00000000..d4294cdf --- /dev/null +++ b/BPASmartClient.JXJFoodBigStation/Model/HK_PLC/DB_Read.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmartClient.JXJFoodBigStation.Model.HK_PLC +{ + internal class DB_Read + { + } +} diff --git a/BPASmartClient.JXJFoodBigStation/Model/HK_PLC/DB_Write.cs b/BPASmartClient.JXJFoodBigStation/Model/HK_PLC/DB_Write.cs new file mode 100644 index 00000000..dca2d6f3 --- /dev/null +++ b/BPASmartClient.JXJFoodBigStation/Model/HK_PLC/DB_Write.cs @@ -0,0 +1,146 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmartClient.JXJFoodBigStation.Model.HK_PLC +{ + public class DB_Write + { + /// + /// 上位机 到 PLC的心跳 + /// + public bool HeartBeat { get; set; } + /// + /// 配方锁定(暂时不使用) + /// + public bool RecipeLock { get; set; } + /// + /// 配方清零 + /// + public bool RecipeReset { get; set; } + /// + /// 配方1下发完成 + /// + public bool Recipe1IssuedFinish { get; set; } + /// + /// 配方2下发完成 + /// + public bool Recipe2IssuedFinish { get; set; } + /// + /// 配方3下发完成 + /// + public bool Recipe3IssuedFinish { get; set; } + /// + /// 配方4下发完成 + /// + public bool Recipe4IssuedFinish { get; set; } + /// + /// AGV在托盘1到位 + /// + public bool Tray1InPlace { get; set; } + /// + /// AGV在托盘2到位 + /// + public bool Tray2InPlace { get; set; } + /// + /// AGV在托盘3到位 + /// + public bool Tray3InPlace { get; set; } + /// + /// AGV在托盘4到位 + /// + public bool Tray4InPlace { get; set; } + /// + /// AGV在托盘5到位 + /// + public bool Tray5InPlace { get; set; } + /// + /// 配方编码 + /// + public bool RecipeCode { get; set; } + /// + /// 托盘编码 + /// + public bool TrayCode { get; set; } + public bool Bareel1Bin1SetWeight { get; set; } + public bool Bareel1Bin2SetWeight { get; set; } + public bool Bareel1Bin3SetWeight { get; set; } + public bool Bareel1Bin4SetWeight { get; set; } + public bool Bareel1Bin5SetWeight { get; set; } + public bool Bareel1Bin6SetWeight { get; set; } + public bool Bareel1Bin7SetWeight { get; set; } + public bool Bareel1Bin8SetWeight { get; set; } + public bool Bareel1Bin9SetWeight { get; set; } + public bool Bareel1Bin10SetWeight { get; set; } + public bool Bareel1Bin11SetWeight { get; set; } + public bool Bareel1Bin12SetWeight { get; set; } + public bool Bareel1Bin13SetWeight { get; set; } + public bool Bareel1Bin14SetWeight { get; set; } + + + public bool Bareel2Bin1SetWeight { get; set; } + public bool Bareel2Bin2SetWeight { get; set; } + public bool Bareel2Bin3SetWeight { get; set; } + public bool Bareel2Bin4SetWeight { get; set; } + public bool Bareel2Bin5SetWeight { get; set; } + public bool Bareel2Bin6SetWeight { get; set; } + public bool Bareel2Bin7SetWeight { get; set; } + public bool Bareel2Bin8SetWeight { get; set; } + public bool Bareel2Bin9SetWeight { get; set; } + public bool Bareel2Bin10SetWeight { get; set; } + public bool Bareel2Bin11SetWeight { get; set; } + public bool Bareel2Bin12SetWeight { get; set; } + public bool Bareel2Bin13SetWeight { get; set; } + public bool Bareel2Bin14SetWeight { get; set; } + + + + public bool Bareel3Bin1SetWeight { get; set; } + public bool Bareel3Bin2SetWeight { get; set; } + public bool Bareel3Bin3SetWeight { get; set; } + public bool Bareel3Bin4SetWeight { get; set; } + public bool Bareel3Bin5SetWeight { get; set; } + public bool Bareel3Bin6SetWeight { get; set; } + public bool Bareel3Bin7SetWeight { get; set; } + public bool Bareel3Bin8SetWeight { get; set; } + public bool Bareel3Bin9SetWeight { get; set; } + public bool Bareel3Bin10SetWeight { get; set; } + public bool Bareel3Bin11SetWeight { get; set; } + public bool Bareel3Bin12SetWeight { get; set; } + public bool Bareel3Bin13SetWeight { get; set; } + public bool Bareel3Bin14SetWeight { get; set; } + + + public bool Bareel4Bin1SetWeight { get; set; } + public bool Bareel4Bin2SetWeight { get; set; } + public bool Bareel4Bin3SetWeight { get; set; } + public bool Bareel4Bin4SetWeight { get; set; } + public bool Bareel4Bin5SetWeight { get; set; } + public bool Bareel4Bin6SetWeight { get; set; } + public bool Bareel4Bin7SetWeight { get; set; } + public bool Bareel4Bin8SetWeight { get; set; } + public bool Bareel4Bin9SetWeight { get; set; } + public bool Bareel4Bin10SetWeight { get; set; } + public bool Bareel4Bin11SetWeight { get; set; } + public bool Bareel4Bin12SetWeight { get; set; } + public bool Bareel4Bin13SetWeight { get; set; } + public bool Bareel4Bin14SetWeight { get; set; } + + public bool Bareel5Bin1SetWeight { get; set; } + public bool Bareel5Bin2SetWeight { get; set; } + public bool Bareel5Bin3SetWeight { get; set; } + public bool Bareel5Bin4SetWeight { get; set; } + public bool Bareel5Bin5SetWeight { get; set; } + public bool Bareel5Bin6SetWeight { get; set; } + public bool Bareel5Bin7SetWeight { get; set; } + public bool Bareel5Bin8SetWeight { get; set; } + public bool Bareel5Bin9SetWeight { get; set; } + public bool Bareel5Bin10SetWeight { get; set; } + public bool Bareel5Bin11SetWeight { get; set; } + public bool Bareel5Bin12SetWeight { get; set; } + public bool Bareel5Bin13SetWeight { get; set; } + public bool Bareel5Bin14SetWeight { get; set; } + } +} diff --git a/BPASmartClient.JXJFoodBigStation/Model/HK_PLC/HKDeviceStatus.cs b/BPASmartClient.JXJFoodBigStation/Model/HK_PLC/HKDeviceStatus.cs index 35c7e144..2181fb20 100644 --- a/BPASmartClient.JXJFoodBigStation/Model/HK_PLC/HKDeviceStatus.cs +++ b/BPASmartClient.JXJFoodBigStation/Model/HK_PLC/HKDeviceStatus.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Text; +using BPASmartClient.CustomResource.Pages.Model; using System.Threading.Tasks; using BPASmartClient.S7Net; @@ -19,7 +20,10 @@ namespace BPASmartClient.JXJFoodBigStation.Model.HK_PLC { ThreadManage.GetInstance().StartLong(new Action(() => { - + //var res1 = HK_PLC_S7.ReadClass(99); + //var res1 = HK_PLC_S7.Read("DB46.DBX10.0"); + var res = HK_PLC_S7.ReadClass(46); + int a = 1; }),"信号收发处理"); } } @@ -32,31 +36,45 @@ namespace BPASmartClient.JXJFoodBigStation.Model.HK_PLC { if (recipe != null) { + string recipecode = "MW4040"; + string recipeTrayCode = "MW4042"; + short recipecode1 = Convert.ToInt16(recipe.RecipeCode); + HK_PLC_S7.Write(recipecode, recipecode1); + HK_PLC_S7.Write(recipeTrayCode, (short)recipe.TrayCode); for (int barrel = 1; barrel < 6; barrel++) { - for (int loc = 1; loc < 13; loc++) + if (barrel != 3) { - int index = Array.FindIndex(recipe.RawMaterial.ToArray(), p => p.RawMaterialBarrelNum == barrel && p.RawMaterialLocation == loc); - if (barrel >= 3)//PLC没有3号桶的重量位置,故4,5号桶地址向前偏移48个位置 + for (int loc = 1; loc < 13; loc++) { - if (index != -1) + int index = Array.FindIndex(recipe.RawMaterial.ToArray(), p => p.RawMaterialBarrelNum == barrel && p.RawMaterialLocation == loc); + if (barrel >= 3)//PLC没有3号桶的重量位置,故4,5号桶地址向前偏移48个位置 { - HK_PLC_S7.Write("MD" + 4120 + (loc - 1) * 4 + (barrel - 1 - 1) * 48, recipe.RawMaterial.ElementAt(index).RawMaterialWeight); + if (index != -1) + { + string address = "MD" + (4120 + (loc - 1) * 4 + (barrel - 1 - 1) * 48); + HK_PLC_S7.Write(address, recipe.RawMaterial.ElementAt(index).RawMaterialWeight); + MessageLog.GetInstance.ShowRunLog($"配方数据下发完成,地址:{address},重量:{recipe.RawMaterial.ElementAt(index).RawMaterialWeight}"); + } + else//不存在的原料信息,重量写0 + { + string address = "MD" + (4120 + (loc - 1) * 4 + (barrel - 1 - 1) * 48); + HK_PLC_S7.Write(address, 0); + } } - else//不存在的原料信息,重量写0 + else { - HK_PLC_S7.Write("MD" + 4120 + (loc - 1) * 4 + (barrel - 1 - 1) * 48, 0); - } - } - else - { - if (index != -1) - { - HK_PLC_S7.Write("MD" + 4120 + (loc - 1) * 4 + (barrel - 1) * 48, recipe.RawMaterial.ElementAt(index).RawMaterialWeight); - } - else//不存在的原料信息,重量写0 - { - HK_PLC_S7.Write("MD" + 4120 + (loc - 1) * 4 + (barrel - 1) * 48, 0); + if (index != -1) + { + string address = "MD" + (4120 + (loc - 1) * 4 + (barrel - 1) * 48); + HK_PLC_S7.Write(address, recipe.RawMaterial.ElementAt(index).RawMaterialWeight); + MessageLog.GetInstance.ShowRunLog($"配方数据下发完成,地址:{address},重量:{recipe.RawMaterial.ElementAt(index).RawMaterialWeight}"); + } + else//不存在的原料信息,重量写0 + { + string address = "MD" + (4120 + (loc - 1) * 4 + (barrel - 1) * 48); + HK_PLC_S7.Write(address, 0); + } } } } diff --git a/BPASmartClient.JXJFoodBigStation/Model/HK_PLC/Test1.cs b/BPASmartClient.JXJFoodBigStation/Model/HK_PLC/Test1.cs new file mode 100644 index 00000000..d4caa9bd --- /dev/null +++ b/BPASmartClient.JXJFoodBigStation/Model/HK_PLC/Test1.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmartClient.JXJFoodBigStation.Model.HK_PLC +{ + internal class Test1 + { + public string[] name1 { get; set; } = new string[8]; + public string[] name2 { get; set; }=new string[8]; + /*public string name3 { get; set; } + public string name4 { get; set; } + public string name5 { get; set; } + public string name6 { get; set; } + public string name7 { get; set; } + public string name8 { get; set; } + public string name9 { get; set; } + public string name10 { get; set; } + public string name11 { get; set; } + public string name12 { get; set; } + public string name13 { get; set; } + public string name14 { get; set; } + public string name15 { get; set; } + public string name16 { get; set; } + public string name17 { get; set; } + public string name18 { get; set; }*/ + } +} diff --git a/BPASmartClient.JXJFoodBigStation/Model/ProcessControl.cs b/BPASmartClient.JXJFoodBigStation/Model/ProcessControl.cs index 5c66ea6c..3b19daa8 100644 --- a/BPASmartClient.JXJFoodBigStation/Model/ProcessControl.cs +++ b/BPASmartClient.JXJFoodBigStation/Model/ProcessControl.cs @@ -52,6 +52,18 @@ namespace BPASmartClient.JXJFoodBigStation.Model public RecipeRawMaterial RawMaterial; public void Init() { + RawMaterialsNamePos.Add("1", 1); + RawMaterialsNamePos.Add("2", 2); + RawMaterialsNamePos.Add("3", 3); + RawMaterialsNamePos.Add("4", 4); + RawMaterialsNamePos.Add("5", 5); + RawMaterialsNamePos.Add("6", 6); + RawMaterialsNamePos.Add("7", 7); + RawMaterialsNamePos.Add("8", 8); + RawMaterialsNamePos.Add("9", 9); + RawMaterialsNamePos.Add("10", 10); + RawMaterialsNamePos.Add("11", 11); + RawMaterialsNamePos.Add("12", 12); ActionManage.GetInstance.Register(new Action((res) => { ObservableCollection RawMaterials = new ObservableCollection(); @@ -114,6 +126,10 @@ namespace BPASmartClient.JXJFoodBigStation.Model if (o !=null && o is RecipeData a) { Json.Data.Recipes.Add(a); + foreach (var item in Json.Data.Recipes.ElementAt(0).RawMaterial) + { + item.RawMaterialLocation = Convert.ToInt32(item.RawMaterialName); + } } }), "ManualSendRecipe", true); RecipeQueue.Clear(); @@ -293,35 +309,6 @@ namespace BPASmartClient.JXJFoodBigStation.Model } if (BigStation.RecipeDosingStatus == 2) { - for (int i = 0; i < 12; i++) - { - if (i >= 0 && i < 8) - { - if (HKDevice.HK_PLC_S7.Read("M5008." + (i)))//根据配料完成信号, - { - int a = Array.FindIndex(RemoteRecipes.ElementAt(index).RawMaterial.ToArray(), p => p.RawMaterialLocation == (i+1)); - if (a >= 0) - { - int barrelNum = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(a).RawMaterialBarrelNum; - string address = "MD" + 5060 + i * 4 + (barrelNum - 1) * 48; - RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(a).Laying_Off_Weight = HKDevice.HK_PLC_S7.Read(address);//料仓配料完成后的出料重量 - } - } - } - else - { - if (HKDevice.HK_PLC_S7.Read("M5009." + (i - 8))) - { - int a = Array.FindIndex(RemoteRecipes.ElementAt(index).RawMaterial.ToArray(), p => p.RawMaterialLocation == i); - if (a >= 0) - { - int barrelNum = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(a).RawMaterialBarrelNum; - string address = "MD" + 5060 + i * 4 + (barrelNum - 1) * 48; - RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(a).Laying_Off_Weight = HKDevice.HK_PLC_S7.Read(address); - } - } - } - } if (RTrig.GetInstance("StockState").Start(HKDevice.HK_PLC_S7.Read("M5007.0"))) { BigStation.RecipeDosingStatus = 3; @@ -454,13 +441,14 @@ namespace BPASmartClient.JXJFoodBigStation.Model /// private void ReadPLCDeviceInfo() { - for (int i = 0; i < 12; i++) + /*for (int i = 0; i < 12; i++) { string RawMaterialName = HKDevice.HK_PLC_S7.Read(""); short RawMaterialLocation = HKDevice.HK_PLC_S7.Read(""); if (RawMaterialsNamePos.ContainsKey(RawMaterialName)) RawMaterialsNamePos.Add(RawMaterialName, RawMaterialLocation); - } + }*/ + } } } diff --git a/BPASmartClient.JXJFoodBigStation/ViewModel/RecipeInfosViewModel.cs b/BPASmartClient.JXJFoodBigStation/ViewModel/RecipeInfosViewModel.cs index e2bfe01d..e78c6407 100644 --- a/BPASmartClient.JXJFoodBigStation/ViewModel/RecipeInfosViewModel.cs +++ b/BPASmartClient.JXJFoodBigStation/ViewModel/RecipeInfosViewModel.cs @@ -47,7 +47,7 @@ namespace BPASmartClient.JXJFoodBigStation.ViewModel if (name == null) { go: - string recipeCode = new Random().Next(10000, 99999).ToString(); + string recipeCode = new Random().Next(10000, 32767).ToString(); var res = Json.Data.Recipes.FirstOrDefault(p => p.RecipeCode == recipeCode); if (res == null) {