diff --git a/DosingSystem/ViewModel/RecipeControlViewModel.cs b/DosingSystem/ViewModel/RecipeControlViewModel.cs index 05ea2efb..e20ca786 100644 --- a/DosingSystem/ViewModel/RecipeControlViewModel.cs +++ b/DosingSystem/ViewModel/RecipeControlViewModel.cs @@ -180,6 +180,8 @@ 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++) @@ -187,7 +189,6 @@ namespace BPASmartClient.DosingSystem.ViewModel for (int m = 0; m < Recipes.ElementAt(i).RawMaterials.Count; m++) { var RunStatus = DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(m).DeviceIp).deviceStatus.RunStatus; - //设备状态显示 if (Recipes.ElementAt(i).RecipeName == CurrentRecipeName) { @@ -202,25 +203,40 @@ 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; })); - - - var proc = recipeProcesses.ElementAt(recIndex).RawMaterials.Where(p => p.RecipeStatus == 3).ToList(); - if (proc != null && proc.Count > 0 && proc.Count == recipeProcesses.Count) + for (int j = 0; j < GlobalDevice.PlcData.IsAllowIngredients.Length; j++) { - int recipIndex = Array.FindIndex(Recipes.ToArray(), p => p.RecipeName == CurrentRecipeName); - if (recipIndex >= 0 && recipIndex < Recipes.Count) + if (GlobalDevice.PlcData.IsAllowIngredients[j]) { - for (int n = 0; n < recipeProcesses.Count; n++) + int cnt = j + 1;//获取允许配料信号桶号的料仓位置 + float weight = Recipes.ElementAt(i).RawMaterials.ElementAt(Array.FindIndex(Recipes.ElementAt(i).RawMaterials.ToArray(), p => p.Loc == j)).RawMaterialWeight; + string deviceName = DeviceInquire.GetInstance.devices.ElementAt(Array.FindIndex(DeviceInquire.GetInstance.devices.ToArray(), p => p.DeviceNum == cnt)).DeviceName; + int loc = Array.FindIndex(Recipes.ElementAt(i).RawMaterials.ToArray(), p => p.RawMaterialName == deviceName); + if (cnt > 0 && loc > 0 && deviceName != null && weight > 0) { - DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(recipIndex).RawMaterials.ElementAt(n).DeviceIp).StatusReset();//完成配料的设备运行状态地址写0 - MessageNotify.GetInstance.ShowRunLog(Recipes.ElementAt(recipIndex).RawMaterials.ElementAt(n).DeviceIp); + if (recipeProcesses.ElementAt(recIndex).RawMaterials.ElementAt(loc).RecipeStatus == 1 && !SingleRawMater[j]) + { + 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},开始出料"); + } + if (RTrig.GetInstance("StatusReset").Start(recipeProcesses.ElementAt(recIndex).RawMaterials.ElementAt(loc).RecipeStatus == 3)) + { + 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},出料完成,状态复位"); + } } - App.Current.Dispatcher.Invoke(new Action(() => { recipeProcesses.Clear(); })); - Recipes.ElementAt(recipIndex).IsEnable = true; - Recipes.ElementAt(recipIndex).Are.Set(); } } - + if (RawMaterialNameFinish.Count>= Recipes.ElementAt(i).RawMaterials.Count) //配方配料完成 + { + RawMaterialNameFinish.Clear(); + int recipIndex = Array.FindIndex(Recipes.ToArray(), p => p.RecipeName == CurrentRecipeName); + App.Current.Dispatcher.Invoke(new Action(() => { recipeProcesses.Clear(); })); + Recipes.ElementAt(recipIndex).IsEnable = true; + Recipes.ElementAt(recipIndex).Are.Set(); + } } }