From 31ba7533802694c6d12af484e4e4f6d5f6515025 Mon Sep 17 00:00:00 2001 From: lyw <刘耀文@DESKTOP-E1TI268> Date: Tue, 27 Feb 2024 13:57:26 +0800 Subject: [PATCH] hhh --- DosingSystem/ExcuteControl .cs | 121 +++++++++++++----- DosingSystem/Model/RecipeSeeModel.cs | 12 ++ .../ViewModel/MaterialDosageViewModel.cs | 16 +-- 3 files changed, 102 insertions(+), 47 deletions(-) create mode 100644 DosingSystem/Model/RecipeSeeModel.cs diff --git a/DosingSystem/ExcuteControl .cs b/DosingSystem/ExcuteControl .cs index d8068da1..46441b14 100644 --- a/DosingSystem/ExcuteControl .cs +++ b/DosingSystem/ExcuteControl .cs @@ -409,7 +409,6 @@ namespace BPASmartClient.DosingSystem }); } - App.Current.Dispatcher.Invoke(() => { NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"配方下发成功!"); }); } @@ -584,7 +583,9 @@ namespace BPASmartClient.DosingSystem } bool allowStart=false; - public ConcurrentDictionary finish_weight = new ConcurrentDictionary(); + public ConcurrentDictionary start_Stop = new ConcurrentDictionary(); + + private void MatchRun() { @@ -620,6 +621,7 @@ namespace BPASmartClient.DosingSystem List device_Loc = new List();//下发桶号 int recipeNameNum = doDeviceCount[DeviceInquire.GetInstance.devices[i].IpAddress]; var dnum = DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.DeviceNum; + int passPail = DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PassPail; if (recipeNameNum == 0) { index = Array.FindIndex(Recipes.ToArray(), p => p.RecipeName == RecipeNames.ElementAt(recipeNameNum)); @@ -636,7 +638,7 @@ namespace BPASmartClient.DosingSystem device_Loc.Add(rawMaterial.Loc); } } - if (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PassPail == 0) + if (passPail == 0) { doDeviceCount.TryUpdate(DeviceInquire.GetInstance.devices[i].IpAddress, recipeNameNum + 1, doDeviceCount[DeviceInquire.GetInstance.devices[i].IpAddress]); foreach (var down_Loc in device_Loc) @@ -676,6 +678,7 @@ namespace BPASmartClient.DosingSystem } } } + if (recipeNameNum > 0 && recipeNameNum <= RecipeNames.Count) { index = Array.FindIndex(Recipes.ToArray(), p => p.RecipeName == RecipeNames.ElementAt(recipeNameNum - 1)); @@ -689,14 +692,14 @@ namespace BPASmartClient.DosingSystem } } - if (dnum == 18 && maxPail <= DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PassPail) + if (dnum == 18 && maxPail <= passPail) { App.Current.Dispatcher.Invoke(() => { RecipeModel recipe = recipeProcesses?.ToList().Find(a => a.RecipeName == RecipeNames.ElementAt(recipeNameNum - 1)); - if (recipe != null && recipe.RecipStatus != "制作完成") + if (recipe != null) { int res = recipe.RawMaterials.ToList().FindIndex(a => a.RecipeStatus !=3); if (res < 0 ) @@ -711,26 +714,27 @@ namespace BPASmartClient.DosingSystem ActionManage.GetInstance.Send("配料完成", UserTreeCompelete); ActionManage.GetInstance.Send("历史记录", Json.Data.Recipes); } - /*Json.Data.Recipes.RemoveAt(recipeProcesses.ToList().FindIndex(a => a.RecipeName == RecipeNames.ElementAt(recipeNameNum))); - Json.Save();*/ } }); } - + int recipecount = recipeProcesses.Count - (recipeNameNum - UserTreeCompelete.Count); int re = -1; if (recipecount < recipeProcesses.Count && recipecount >= 0) { re = recipeProcesses.ElementAt(recipecount).RawMaterials.ToList().FindIndex(a => a.RawMaterialName == DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].DeviceName && a.Loc == DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PassPail && a.RecipeStatus != 3); - + } - - if (maxPail <= DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PassPail && recipeNameNum < RecipeNames.Count && !DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PailArrive&& re<0) + + if (maxPail <= passPail && recipeNameNum < RecipeNames.Count && !DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PailArrive&&re<0) { - - SimensSend.GetInstance.SendSimens.Write($"DB1.DBW{810 + 2 * (dnum - 1)}", 0); - MessageNotify.GetInstance.ShowRunLog($"设备{dnum}下发配方{RecipeNames.ElementAt(recipeNameNum - 1)},桶数已清零"); + + while (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PassPail!=0) + { + SimensSend.GetInstance.SendSimens.Write($"DB1.DBW{810 + 2 * (dnum - 1)}", 0); + } + MessageNotify.GetInstance.ShowRunLog($"设备{dnum}桶数已清零"); doDeviceCount.TryUpdate(DeviceInquire.GetInstance.devices[i].IpAddress, recipeNameNum + 1, doDeviceCount[DeviceInquire.GetInstance.devices[i].IpAddress]); recipeNameNum = doDeviceCount[DeviceInquire.GetInstance.devices[i].IpAddress]; index = Array.FindIndex(Recipes.ToArray(), p => p.RecipeName == RecipeNames.ElementAt(recipeNameNum - 1)); @@ -738,10 +742,6 @@ namespace BPASmartClient.DosingSystem { foreach (var rawMaterial in Recipes.ElementAt(index).RawMaterials) { - if (rawMaterial.Loc > maxPail) - { - maxPail = rawMaterial.Loc; - } if (rawMaterial.DeviceIp == DeviceInquire.GetInstance.devices[i].IpAddress) { device_Loc.Add(rawMaterial.Loc); @@ -815,10 +815,9 @@ namespace BPASmartClient.DosingSystem while (!DeviceInquire.GetInstance.DeviceLists[s].modbusTcp.Write(DeviceAddress.Start.ToAdd(), 1).IsSuccess) { MessageNotify.GetInstance.ShowRunLog($"设备{s}下发开始信号失败"); - stop = false; + start_Stop.TryUpdate(s,false,true); } - stop = true; - MessageNotify.GetInstance.ShowRunLog($"允许下发复位信号"); + start_Stop.TryUpdate(s, true, false); } }); @@ -829,16 +828,66 @@ namespace BPASmartClient.DosingSystem { for (int i = 0; i < DeviceInquire.GetInstance.devices.Count; i++) { + + string ip = DeviceInquire.GetInstance.devices[i].IpAddress; + if (!start_Stop.ContainsKey(ip)) + { + start_Stop.TryAdd(ip,false); + } + int dnum = DeviceInquire.GetInstance.DeviceLists[ip].deviceStatus.DeviceNum; + int passPail = -1; + string nextIp = ""; + if (dnum < 18) + { + nextIp = $"192.168.2.{(dnum + 1) * 10}"; + if (DeviceInquire.GetInstance.DeviceLists.ContainsKey(nextIp)) + { + passPail = DeviceInquire.GetInstance.DeviceLists[nextIp].deviceStatus.PassPail; + } + } + else + { + passPail = 0; + } if (DeviceInquire.GetInstance.DeviceLists.ContainsKey(ip) &&doDeviceCount.ContainsKey(ip)) { - int dnum = DeviceInquire.GetInstance.DeviceLists[ip].deviceStatus.DeviceNum; - int count = doDeviceCount[ip]; + int recipeNameNum = doDeviceCount[ip]; + if (DeviceInquire.GetInstance.DeviceLists[ip].deviceStatus.PailArrive) + { + + if (recipeNameNum >= 0) + { + int doCount = Array.FindIndex(Recipes.ToArray(), p => p.RecipeName == RecipeNames.ElementAt(recipeNameNum - 1)); + if (doCount >= 0) + { + int finish = UserTreeCompelete.Count; + int re = 0; + int recipecount = recipeProcesses.Count - (recipeNameNum - finish); + if (recipecount < recipeProcesses.Count && recipecount >= 0) + { + re = recipeProcesses.ElementAt(recipecount).RawMaterials.ToList().FindIndex(a => a.RawMaterialName == DeviceInquire.GetInstance.DeviceLists[ip].DeviceName && a.Loc == DeviceInquire.GetInstance.DeviceLists[ip].deviceStatus.PassPail && a.RecipeStatus == 1); + if (re >= 0) + { + MessageNotify.GetInstance.ShowRunLog($"当前设备{dnum}执行位配方数{doCount},开始下{recipeProcesses.ElementAt(recipecount).RawMaterials.ElementAt(re).RawMaterialWeight}g料"); + Raction?.Invoke(ip, recipeProcesses.ElementAt(recipecount).RawMaterials.ElementAt(re).RawMaterialWeight); + recipeProcesses.ElementAt(recipecount).RawMaterials.ElementAt(re).RecipeStatus = 2; + recipeProcesses.ElementAt(recipecount).RawMaterials.ElementAt(re).Status = (Status)1; + } + } + + } + } + } + if (DeviceInquire.GetInstance.DeviceLists[ip].deviceStatus.PassPail != 0&& DeviceInquire.GetInstance.DeviceLists[ip].deviceStatus.Finish_mt&&!DeviceInquire.GetInstance.DeviceLists[ip].deviceStatus.PailArrive) + { + + } - if (DeviceInquire.GetInstance.DeviceLists[ip].deviceStatus.Finish_mt) + if (DeviceInquire.GetInstance.DeviceLists[ip].deviceStatus.Finish_mt&& passPail==0) { - int recipecount = recipeProcesses.Count - (count - UserTreeCompelete.Count); + int recipecount = recipeProcesses.Count - (recipeNameNum - UserTreeCompelete.Count); if (recipecount < recipeProcesses.Count && recipecount >= 0) { int re_1 = recipeProcesses.ElementAt(recipecount).RawMaterials.ToList().FindIndex(a => a.RawMaterialName == DeviceInquire.GetInstance.DeviceLists[ip].DeviceName && a.Loc == DeviceInquire.GetInstance.DeviceLists[ip].deviceStatus.PassPail && a.RecipeStatus == 2); @@ -859,39 +908,41 @@ namespace BPASmartClient.DosingSystem } recipeProcesses.ElementAt(recipecount).RawMaterials.ElementAt(re_1).RecipeStatus = 3; recipeProcesses.ElementAt(recipecount).RawMaterials.ElementAt(re_1).Status = (Status)2; - while (DeviceInquire.GetInstance.DeviceLists[ip].deviceStatus.Finish_mt) + Json.Data.Recipes = recipeProcesses; + Json.Save(); + while(DeviceInquire.GetInstance.DeviceLists[ip].deviceStatus.Finish_mt) { DeviceInquire.GetInstance.DeviceLists[ip].modbusTcp.Write(DeviceAddress.WorkModel.ToAdd(), 0); - Thread.Sleep(10); } while (!DeviceInquire.GetInstance.DeviceLists[ip].deviceStatus.RecipeFinish) { SimensSend.GetInstance.SendSimens.Write($"DB1.DBX70{(int)((dnum - 1) / 8)}.{(dnum - 1) % 8}", true); - Thread.Sleep(10); } - Json.Data.Recipes = recipeProcesses; - Json.Save(); + ActionManage.GetInstance.Send("正在配料", recipeProcesses); MessageNotify.GetInstance.ShowRunLog($"设备{ip}已下料{recipeProcesses.ElementAt(recipecount).RawMaterials.ElementAt(re_1).TotalWeight}g"); MessageNotify.GetInstance.ShowRunLog($"设备{dnum}下发完成信号"); while (DeviceInquire.GetInstance.DeviceLists[ip].deviceStatus.RecipeFinish) { SimensSend.GetInstance.SendSimens.Write($"DB1.DBX70{(int)((dnum - 1) / 8)}.{(dnum - 1) % 8}", false); - Thread.Sleep(10); } + + /*finish_weight.TryUpdate(ip, true, false);*/ } } } - if (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.RunStatus == 2 && DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.RunStatus == 3) + if (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.RunStatus != 1 && start_Stop[ip]) { - if (stop) + while (!DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write(DeviceAddress.Start.ToAdd(), 0).IsSuccess) { - MessageNotify.GetInstance.ShowRunLog($"设备{dnum}下发开始配料复位信号"); - DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write(DeviceAddress.Start.ToAdd(), 0); + MessageNotify.GetInstance.ShowRunLog($"设备{dnum}下发开始配料复位信号失败"); } + start_Stop.TryUpdate(ip, false, true); + MessageNotify.GetInstance.ShowRunLog($"设备{dnum}下发开始配料复位信号"); + } } } diff --git a/DosingSystem/Model/RecipeSeeModel.cs b/DosingSystem/Model/RecipeSeeModel.cs new file mode 100644 index 00000000..d8ce9d16 --- /dev/null +++ b/DosingSystem/Model/RecipeSeeModel.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmartClient.DosingSystem.Model +{ + internal class RecipeSeeModel + { + } +} diff --git a/DosingSystem/ViewModel/MaterialDosageViewModel.cs b/DosingSystem/ViewModel/MaterialDosageViewModel.cs index 26440f1b..8ab36c2b 100644 --- a/DosingSystem/ViewModel/MaterialDosageViewModel.cs +++ b/DosingSystem/ViewModel/MaterialDosageViewModel.cs @@ -19,14 +19,6 @@ namespace BPASmartClient.DosingSystem.ViewModel public MaterialDosageViewModel() { - TaskManage.GetInstance.StartLong(() => - { - InRecipe = SimensSend.GetInstance.SendSimens.Read($"DB1.DBW1000").Content.ToString(); - OutRecipe = SimensSend.GetInstance.SendSimens.Read($"DB1.DBW1002").Content.ToString(); - - Thread.Sleep(1000); - - }, "进出桶计数"); App.Current.Dispatcher.Invoke(() => { @@ -322,11 +314,11 @@ namespace BPASmartClient.DosingSystem.ViewModel public static ObservableCollection OldRecipeAllweight { get; set; } = new ObservableCollection(); - public string inRecipe; - public string InRecipe { get { return inRecipe; } set { inRecipe = value; OnPropertyChanged(); } } + public int inRecipe =SimensSend.GetInstance.SendSimens.Read($"DB1.DBW1000").Content; + public int InRecipe { get { return inRecipe; } set { inRecipe = value; OnPropertyChanged(); } } - public string outRecipe; - public string OutRecipe { get { return outRecipe; } set { outRecipe = value; OnPropertyChanged(); } } + public int outRecipe = SimensSend.GetInstance.SendSimens.Read($"DB1.DBW1002").Content; + public int OutRecipe { get { return outRecipe; } set { outRecipe = value; OnPropertyChanged(); } } } public class Allweight : NotifyBase