终端一体化运控平台
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.
 
 
 

137 lines
3.8 KiB

  1. using BPA.Message.Enum;
  2. using BPASmartClient.Device;
  3. using BPASmartClient.EventBus;
  4. using BPASmartClient.Helper;
  5. using BPASmartClient.Model;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading;
  11. using System.Threading.Tasks;
  12. using static BPASmartClient.EventBus.EventBus;
  13. namespace BPASmartClient.MorkBF
  14. {
  15. public class Control_MorkBF : BaseDevice
  16. {
  17. GVL_MorkBF morkBF = new GVL_MorkBF();
  18. public override DeviceClientType DeviceType => DeviceClientType.MORKCS;
  19. public override void DoMain()
  20. {
  21. CommandRegist();//调试
  22. ServerInit();
  23. DataParse();//数据解析
  24. DeviceProcessLogShow("MORKF 设备初始化完成");
  25. }
  26. private void DataParse()
  27. {
  28. EventBus.EventBus.GetInstance().Subscribe<DoOrderEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBackHandle)
  29. {
  30. if (@event == null) return;
  31. if (@event is DoOrderEvent order)
  32. {
  33. if (order.MorkOrder.GoodBatchings == null) return;
  34. OrderCount++;
  35. DeviceProcessLogShow($"接收到{OrderCount}次订单");
  36. }
  37. });
  38. }
  39. private void ServerInit()
  40. {
  41. //物料信息
  42. EventBus.EventBus.GetInstance().Subscribe<MaterialDeliveryEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  43. {
  44. if (@event == null) return;
  45. if (@event is MaterialDeliveryEvent material)
  46. {
  47. orderMaterialDelivery = material.orderMaterialDelivery;
  48. }
  49. });
  50. //配方数据信息
  51. EventBus.EventBus.GetInstance().Subscribe<RecipeBomEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  52. {
  53. if (@event == null) return;
  54. if (@event is RecipeBomEvent recipe)
  55. {
  56. recipeBoms = recipe.recipeBoms;
  57. }
  58. });
  59. }
  60. /// <summary>
  61. /// 调试
  62. /// </summary>
  63. /// <exception cref="NotImplementedException"></exception>
  64. private void CommandRegist()
  65. {
  66. }
  67. public override void MainTask()
  68. {
  69. if(morkBF.FirePan1_Order.Count == 0&&!morkBF.FirePan1_Busy)
  70. {
  71. ThreadManage.GetInstance().Start(FirePot1_Process, "炒锅1主进程");
  72. }
  73. if (morkBF.FirePan2_Order.Count == 0 && !morkBF.FirePan2_Busy)
  74. {
  75. ThreadManage.GetInstance().Start(FirePot2_Process, "炒锅2主进程");
  76. }
  77. }
  78. private void FirePot1_Process()
  79. {
  80. morkBF.FirePan1_Busy = true;
  81. morkBF.FirePan1_Date = DateTime.Now;
  82. while (morkBF.FirePan1_Date.AddMinutes(1)> DateTime.Now)
  83. {
  84. Thread.Sleep(500);
  85. }
  86. ThreadManage.GetInstance().StopTask("炒锅1主进程");
  87. }
  88. private void FirePot2_Process()
  89. {
  90. morkBF.FirePan2_Busy = true;
  91. morkBF.FirePan2_Date = DateTime.Now;
  92. while (morkBF.FirePan2_Date.AddMinutes(1) > DateTime.Now)
  93. {
  94. Thread.Sleep(500);
  95. }
  96. ThreadManage.GetInstance().StopTask("炒锅2主进程");
  97. }
  98. public override void ReadData()
  99. {
  100. }
  101. public override void ResetProgram()
  102. {
  103. morkBF = null;
  104. morkBF = new GVL_MorkBF();
  105. }
  106. public override void SimOrder()
  107. {
  108. }
  109. public override void Stop()
  110. {
  111. }
  112. }
  113. }