终端一体化运控平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

116 lines
6.0 KiB

  1. using BPA.Helper;
  2. using BPASmartClient.CustomResource.Pages.Model;
  3. using BPASmartClient.DosingSystem.ViewModel;
  4. using BPASmartClient.Model;
  5. using S7.Net.Types;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Collections.ObjectModel;
  9. using System.Diagnostics;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading;
  13. using System.Threading.Tasks;
  14. namespace BPASmartClient.DosingSystem
  15. {
  16. /// <summary>
  17. /// 业务逻辑执行类
  18. /// </summary>
  19. public class ExcuteControl
  20. {
  21. private static ExcuteControl Instance;
  22. public static ExcuteControl GetInstance => Instance ??= new ExcuteControl();
  23. /// <summary>
  24. /// 配料完成计数
  25. /// </summary>
  26. int Comcount = 0;
  27. public ExcuteControl() { }
  28. /// <summary>
  29. /// 配料逻辑
  30. /// </summary>
  31. /// <param name="recipeModel">当前执行的配方</param>
  32. public void BusinessExcute(RecipeModel recipeModel)
  33. {
  34. ThreadManage.GetInstance.StartLong(new Action(() => {
  35. #region 直线双仓型
  36. //拿到当前配方
  37. for (int j = 0; j < GlobalDevice.PlcData.IsAllowIngredients.Length; j++)//遍历允许配料的料桶
  38. {
  39. if (GlobalDevice.PlcData.IsAllowIngredients[j])
  40. {
  41. int barrelNum = j + 1;//桶号
  42. int stockLoc = GlobalDevice.PlcData.LocationFeedback[j];//允许配料的料仓位置 0~6 双仓情况下返回的位置是否一样,料仓ip设置顺序怎样的
  43. if (stockLoc >= 1 && stockLoc <= Json<DevicePar>.Data.BaseParModel.StockCount)
  44. {
  45. int index = Array.FindIndex(DeviceInquire.GetInstance.devices.ToArray(), p => p.DeviceNum == stockLoc);
  46. if (index >= 0)
  47. {
  48. //查出到配料位置的原料
  49. int result = Array.FindIndex(recipeModel.RawMaterials.ToArray(), p => (p.Loc == barrelNum && p.DeviceIp == DeviceInquire.GetInstance.devices.ElementAt(index).IpAddress));//待定
  50. if (result != -1 && DeviceInquire.GetInstance.GetDevice(recipeModel.RawMaterials[result].DeviceIp).deviceStatus.RunStatus == 1 && RecipeControlViewModel.recipeProcesses.ElementAt(0).RawMaterials[result].Status == Status.等待配料)
  51. {
  52. var weight = recipeModel.RawMaterials[result].RawMaterialWeight;
  53. DeviceInquire.GetInstance.GetDevice(recipeModel.RawMaterials.ElementAt(index).DeviceIp).Start(weight);//所有参数下发并启动配料
  54. MessageNotify.GetInstance.ShowRunLog($"{recipeModel.RawMaterials[result].DeviceIp}:正在配料");
  55. RecipeControlViewModel.recipeProcesses.ElementAt(0).RawMaterials[result].Status = Status.正在配料;
  56. }
  57. }
  58. }
  59. else
  60. {
  61. continue;
  62. }
  63. }
  64. }
  65. //配料完成后逻辑
  66. for (int k = 0; k < recipeModel.RawMaterials.Count; k++)
  67. {
  68. if (DeviceInquire.GetInstance.GetDevice(recipeModel.RawMaterials.ElementAt(k).DeviceIp).deviceStatus.RunStatus == 3 && RecipeControlViewModel.recipeProcesses.ElementAt(0).RawMaterials[k].Status != Status.配料完成)//配料完成
  69. {
  70. int DeviceNum = DeviceInquire.GetInstance.GetDevice(recipeModel.RawMaterials.ElementAt(k).DeviceIp).deviceStatus.DeviceNum;
  71. Comcount++;
  72. DeviceInquire.GetInstance.GetDevice(recipeModel.RawMaterials.ElementAt(k).DeviceIp).StatusReset();//料仓复位
  73. SiemensDevice.GetInstance.MySiemens.Write($"DB4.DBX130.{DeviceNum - 1}", true);
  74. Task.Run(() =>
  75. {
  76. int cout = DeviceNum - 1;
  77. while (!SiemensDevice.GetInstance.MySiemens.Read<bool>($"DB3.DBX148.{cout}").Content) //DB3.DBX148.0-31 148.0-148.5代表6个料仓位置
  78. {
  79. SiemensDevice.GetInstance.MySiemens.Write($"DB4.DBX130.{cout}", true);
  80. Thread.Sleep(200);
  81. }
  82. while (SiemensDevice.GetInstance.MySiemens.Read<bool>($"DB3.DBX148.{cout}").Content)
  83. {
  84. SiemensDevice.GetInstance.MySiemens.Write($"DB4.DBX130.{cout}", false);
  85. }
  86. MessageNotify.GetInstance.ShowRunLog($"{cout}号气缸复位信号写入成功!");
  87. });
  88. RecipeControlViewModel.recipeProcesses.ElementAt(0).RawMaterials[k].Status = Status.配料完成;
  89. if (Comcount >= recipeModel.RawMaterials.Count) //配方配料完成 StockStatus.Count >= Recipes.ElementAt(i).RawMaterials.Count &&
  90. {
  91. Comcount = 0;
  92. App.Current.Dispatcher.Invoke(new Action(() => { RecipeControlViewModel.recipeProcesses.Clear(); }));
  93. MessageNotify.GetInstance.ShowUserLog($"配方:{recipeModel.RecipeName},配料完成");
  94. SiemensDevice.GetInstance.MySiemens.Write("DB4.DBX202.0", true);//配料完成
  95. MessageNotify.GetInstance.ShowRunLog($"配方:{recipeModel.RecipeName},配料完成");
  96. recipeModel.Are.Set();//待定
  97. Thread.Sleep(100);
  98. }
  99. }
  100. }
  101. #endregion
  102. Thread.Sleep(10);
  103. }),"配料业务逻辑");
  104. }
  105. }
  106. }