using BPA.Helper; using BPASmartClient.CustomResource.Pages.Model; using BPASmartClient.DosingSystem.ViewModel; using BPASmartClient.Model; using S7.Net.Types; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace BPASmartClient.DosingSystem { /// /// 业务逻辑执行类 /// public class ExcuteControl { private static ExcuteControl Instance; public static ExcuteControl GetInstance => Instance ??= new ExcuteControl(); /// /// 配料完成计数 /// int Comcount = 0; public ExcuteControl() { } /// /// 配料逻辑 /// /// 当前执行的配方 public void BusinessExcute(RecipeModel recipeModel) { ThreadManage.GetInstance.StartLong(new Action(() => { #region 直线双仓型 //拿到当前配方 for (int j = 0; j < GlobalDevice.PlcData.IsAllowIngredients.Length; j++)//遍历允许配料的料桶 { if (GlobalDevice.PlcData.IsAllowIngredients[j]) { int barrelNum = j + 1;//桶号 int stockLoc = GlobalDevice.PlcData.LocationFeedback[j];//允许配料的料仓位置 0~6 双仓情况下返回的位置是否一样,料仓ip设置顺序怎样的 if (stockLoc >= 1 && stockLoc <= Json.Data.BaseParModel.StockCount) { int index = Array.FindIndex(DeviceInquire.GetInstance.devices.ToArray(), p => p.DeviceNum == stockLoc); if (index >= 0) { //查出到配料位置的原料 int result = Array.FindIndex(recipeModel.RawMaterials.ToArray(), p => (p.Loc == barrelNum && p.DeviceIp == DeviceInquire.GetInstance.devices.ElementAt(index).IpAddress));//待定 if (result != -1 && DeviceInquire.GetInstance.GetDevice(recipeModel.RawMaterials[result].DeviceIp).deviceStatus.RunStatus == 1 && RecipeControlViewModel.recipeProcesses.ElementAt(0).RawMaterials[result].Status == Status.等待配料) { var weight = recipeModel.RawMaterials[result].RawMaterialWeight; DeviceInquire.GetInstance.GetDevice(recipeModel.RawMaterials.ElementAt(index).DeviceIp).Start(weight);//所有参数下发并启动配料 MessageNotify.GetInstance.ShowRunLog($"{recipeModel.RawMaterials[result].DeviceIp}:正在配料"); RecipeControlViewModel.recipeProcesses.ElementAt(0).RawMaterials[result].Status = Status.正在配料; } } } else { continue; } } } //配料完成后逻辑 for (int k = 0; k < recipeModel.RawMaterials.Count; k++) { if (DeviceInquire.GetInstance.GetDevice(recipeModel.RawMaterials.ElementAt(k).DeviceIp).deviceStatus.RunStatus == 3 && RecipeControlViewModel.recipeProcesses.ElementAt(0).RawMaterials[k].Status != Status.配料完成)//配料完成 { int DeviceNum = DeviceInquire.GetInstance.GetDevice(recipeModel.RawMaterials.ElementAt(k).DeviceIp).deviceStatus.DeviceNum; Comcount++; DeviceInquire.GetInstance.GetDevice(recipeModel.RawMaterials.ElementAt(k).DeviceIp).StatusReset();//料仓复位 SiemensDevice.GetInstance.MySiemens.Write($"DB4.DBX130.{DeviceNum - 1}", true); Task.Run(() => { int cout = DeviceNum - 1; while (!SiemensDevice.GetInstance.MySiemens.Read($"DB3.DBX148.{cout}").Content) //DB3.DBX148.0-31 148.0-148.5代表6个料仓位置 { SiemensDevice.GetInstance.MySiemens.Write($"DB4.DBX130.{cout}", true); Thread.Sleep(200); } while (SiemensDevice.GetInstance.MySiemens.Read($"DB3.DBX148.{cout}").Content) { SiemensDevice.GetInstance.MySiemens.Write($"DB4.DBX130.{cout}", false); } MessageNotify.GetInstance.ShowRunLog($"{cout}号气缸复位信号写入成功!"); }); RecipeControlViewModel.recipeProcesses.ElementAt(0).RawMaterials[k].Status = Status.配料完成; if (Comcount >= recipeModel.RawMaterials.Count) //配方配料完成 StockStatus.Count >= Recipes.ElementAt(i).RawMaterials.Count && { Comcount = 0; App.Current.Dispatcher.Invoke(new Action(() => { RecipeControlViewModel.recipeProcesses.Clear(); })); MessageNotify.GetInstance.ShowUserLog($"配方:{recipeModel.RecipeName},配料完成"); SiemensDevice.GetInstance.MySiemens.Write("DB4.DBX202.0", true);//配料完成 MessageNotify.GetInstance.ShowRunLog($"配方:{recipeModel.RecipeName},配料完成"); recipeModel.Are.Set();//待定 Thread.Sleep(100); } } } #endregion Thread.Sleep(10); }),"配料业务逻辑"); } } }