From 80ee127af1d4e2bf31ee946ab44a9745d401c47f Mon Sep 17 00:00:00 2001 From: pengliangyang <1406009520@qq.com> Date: Wed, 26 Oct 2022 11:02:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=81=E7=A8=8B=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DosingSystem/Model/StockStatusModel.cs | 23 ++++-- .../ViewModel/RecipeControlViewModel.cs | 78 +++++++------------ 2 files changed, 44 insertions(+), 57 deletions(-) diff --git a/DosingSystem/Model/StockStatusModel.cs b/DosingSystem/Model/StockStatusModel.cs index 072da4e7..16626d7c 100644 --- a/DosingSystem/Model/StockStatusModel.cs +++ b/DosingSystem/Model/StockStatusModel.cs @@ -12,26 +12,27 @@ namespace BPASmartClient.DosingSystem /// /// 料仓物料重量 /// - private double _materialWeight; public double MaterialWeight { get { return _materialWeight; } set { _materialWeight = value; OnPropertyChanged(); } } + private double _materialWeight; /// /// 料仓物料名称 /// - private string _materialName; public string MaterialName { get { return _materialName; } set { _materialName = value; OnPropertyChanged(); } } + private string _materialName; /// /// 是否真在运行 /// - private bool _isRunning; public bool IsRunning { get { return _isRunning; } set { _isRunning = value; OnPropertyChanged(); } } + private bool _isRunning; + /// /// 是否正在下料 /// - private bool _isLayOff; public bool IsLayOff { get { return _isLayOff; } set { _isLayOff = value; OnPropertyChanged(); } } + private bool _isLayOff; /// - /// 打开状态 + /// 是否开盖 /// public bool IsOpen { get { return _mIsOpen; } set { _mIsOpen = value; OnPropertyChanged(); } } private bool _mIsOpen; @@ -39,8 +40,18 @@ namespace BPASmartClient.DosingSystem /// /// 是否故障报警 /// + public bool IsFault { get { return _isFault; } set { _isFault = value; OnPropertyChanged(); } } private bool _isFault; - public bool IsFault { get { return _isFault; } set { _isFault = value; OnPropertyChanged(); } } + /// + /// 下料状态 0:未出料 1:出料指令下发 2:出料完成 + /// + public int IssueStatus { get { return _isIssueStatus; } set { _isIssueStatus = value; OnPropertyChanged(); } } + private int _isIssueStatus; + /// + /// 下料重量 + /// + public double IssueWeight { get { return _IssueWeight; } set { _IssueWeight = value; OnPropertyChanged(); } } + private double _IssueWeight; } } diff --git a/DosingSystem/ViewModel/RecipeControlViewModel.cs b/DosingSystem/ViewModel/RecipeControlViewModel.cs index e20ca786..60787a84 100644 --- a/DosingSystem/ViewModel/RecipeControlViewModel.cs +++ b/DosingSystem/ViewModel/RecipeControlViewModel.cs @@ -20,7 +20,7 @@ namespace BPASmartClient.DosingSystem.ViewModel public class RecipeControlViewModel : NotifyBase { ConcurrentQueue RecipeNames = new ConcurrentQueue(); - + ObservableCollection StockStatus = new ObservableCollection(); public RecipeControlViewModel() { StartCommand = new RelayCommand((o) => @@ -50,8 +50,6 @@ namespace BPASmartClient.DosingSystem.ViewModel var res = Recipes.FirstOrDefault(p => p.RecipeName == deviceName); UserTreeWait.Add(new RecipeModel { RecipeName = deviceName, RawMaterials = res.RawMaterials }); } - - NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"配方下发成功!"); MessageNotify.GetInstance.ShowUserLog($"下发工单 {Guid.NewGuid().ToString()}"); }); @@ -67,6 +65,7 @@ namespace BPASmartClient.DosingSystem.ViewModel { Recipes.ElementAt(index).Are.Reset(); Recipes.ElementAt(index).IsEnable = false; + StockStatus.Clear(); App.Current.Dispatcher.Invoke(new Action(() => { recipeProcesses.Clear(); @@ -180,8 +179,6 @@ namespace BPASmartClient.DosingSystem.ViewModel }), "启动配方下发"); - List RawMaterialNameFinish = new List();//配料完成料仓名称的集合 - bool[] SingleRawMater = new bool[32];//单次配料 ThreadManage.GetInstance().StartLong(new Action(() => { for (int i = 0; i < Recipes.Count; i++) @@ -202,7 +199,6 @@ namespace BPASmartClient.DosingSystem.ViewModel { App.Current.Dispatcher.Invoke(new Action(() => { recipeProcesses.ElementAt(recIndex).RawMaterials.ElementAt(index).RecipeStatus = RunStatus; })); } - //App.Current.Dispatcher.Invoke(new Action(() => { recipeProcesses.ElementAt(index).RecipeStatus = RunStatus; })); for (int j = 0; j < GlobalDevice.PlcData.IsAllowIngredients.Length; j++) { if (GlobalDevice.PlcData.IsAllowIngredients[j]) @@ -213,25 +209,39 @@ namespace BPASmartClient.DosingSystem.ViewModel int loc = Array.FindIndex(Recipes.ElementAt(i).RawMaterials.ToArray(), p => p.RawMaterialName == deviceName); if (cnt > 0 && loc > 0 && deviceName != null && weight > 0) { - if (recipeProcesses.ElementAt(recIndex).RawMaterials.ElementAt(loc).RecipeStatus == 1 && !SingleRawMater[j]) + int St_index = Array.FindIndex(StockStatus.ToArray(), p => p.MaterialName == deviceName); + if (St_index < 0) { - SingleRawMater[j] = true; - DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp).Start(weight); - MessageNotify.GetInstance.ShowRunLog($"味魔方{Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp},开始出料"); + StockStatus.Add(new StockStatusModel() + { + MaterialName = deviceName, + IssueWeight = weight, + IssueStatus = 0, + }); } - if (RTrig.GetInstance("StatusReset").Start(recipeProcesses.ElementAt(recIndex).RawMaterials.ElementAt(loc).RecipeStatus == 3)) + else { - DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp).StatusReset(); - RawMaterialNameFinish.Add(Recipes.ElementAt(i).RawMaterials.ElementAt(loc).RawMaterialName); - SiemensDevice.GetInstance.MySiemens.Write("DB4.DBD130", loc.SetBitValue((byte)loc, true)); - MessageNotify.GetInstance.ShowRunLog($"味魔方{Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp},出料完成,状态复位"); + if (recipeProcesses.ElementAt(recIndex).RawMaterials.ElementAt(loc).RecipeStatus == 1 && StockStatus.ElementAt(St_index).IssueStatus == 0) + { + StockStatus.ElementAt(St_index).IssueStatus = 1; + DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp).Start(weight); + MessageNotify.GetInstance.ShowRunLog($"柔性味魔方{Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp},开始出料"); + } + if (RTrig.GetInstance("StatusReset").Start(recipeProcesses.ElementAt(recIndex).RawMaterials.ElementAt(loc).RecipeStatus == 3) && StockStatus.ElementAt(St_index).IssueStatus == 1) + { + StockStatus.ElementAt(St_index).IssueStatus = 2; + DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp).StatusReset(); + SiemensDevice.GetInstance.MySiemens.Write("DB4.DBD130", 0.SetBitValue((byte)loc, true)); + MessageNotify.GetInstance.ShowRunLog($"柔性味魔方{Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp},出料完成,状态复位"); + } } } } } - if (RawMaterialNameFinish.Count>= Recipes.ElementAt(i).RawMaterials.Count) //配方配料完成 + if (StockStatus.Count >= Recipes.ElementAt(i).RawMaterials.Count) //配方配料完成 { - RawMaterialNameFinish.Clear(); + StockStatus.Clear(); + SiemensDevice.GetInstance.MySiemens.Write("DB4.DBX202.1", true);//配方使用桶数写入 int recipIndex = Array.FindIndex(Recipes.ToArray(), p => p.RecipeName == CurrentRecipeName); App.Current.Dispatcher.Invoke(new Action(() => { recipeProcesses.Clear(); })); Recipes.ElementAt(recipIndex).IsEnable = true; @@ -239,40 +249,6 @@ namespace BPASmartClient.DosingSystem.ViewModel } } } - - //var proc = recipeProcesses.Where(p => p.RecipeStatus == 3).ToList(); - //var proc = recipeProcesses.Where(p => p.RecipeStatus == 3).ToList(); - //if (proc != null && proc.Count > 0 && proc.Count == recipeProcesses.Count) - //{ - // int recipIndex = Array.FindIndex(Recipes.ToArray(), p => p.RecipeName == CurrentRecipeName); - // if (recipIndex >= 0 && recipIndex < Recipes.Count) - // { - // for (int n = 0; n < recipeProcesses.Count; n++) - // { - // DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(recipIndex).RawMaterials.ElementAt(n).DeviceIp).StatusReset();//完成配料的设备运行状态地址写0 - // MessageNotify.GetInstance.ShowRunLog(Recipes.ElementAt(recipIndex).RawMaterials.ElementAt(n).DeviceIp); - // } - // App.Current.Dispatcher.Invoke(new Action(() => { recipeProcesses.Clear(); })); - // Recipes.ElementAt(recipIndex).IsEnable = true; - // Recipes.ElementAt(recipIndex).Are.Set(); - // } - //} - - - - - //Recipes.ElementAt(i).RawMaterials.ElementAt(m).RecipeStatus = RunStatus; - //var res = Recipes.ElementAt(i).RawMaterials.Where(p => p.RecipeStatus == 3).ToList(); - //if (res != null && res.Count == Recipes.ElementAt(i).RawMaterials.Count)//配方所有配料完成下料 - //{ - // for (int r = 0; r < Recipes.ElementAt(i).RawMaterials.Count; r++) - // { - // DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(r).DeviceIp).StatusReset();//完成配料的设备运行状态地址写0 - // App.Current.Dispatcher.Invoke(new Action(() => { recipeProcesses.Clear(); })); - // } - // Recipes.ElementAt(i).IsEnable = true; - // Recipes.ElementAt(i).Are.Set(); - //} } } Thread.Sleep(100);