终端一体化运控平台
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 

120 строки
4.2 KiB

  1. using BPA.Helper;
  2. using BPASmartClient.GSIceCream;
  3. using BPASmartClient.Model;
  4. using BPASmartClient.Model.冰淇淋.Enum;
  5. using BPASmartClient.SerialPort;
  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 BPA.Helper.EventBus;
  13. namespace BPASmartClient.DRCoffee
  14. {
  15. /// <summary>
  16. /// 指令封装
  17. /// </summary>
  18. internal class CommandHandler
  19. {
  20. byte[] cmdHeartDW;
  21. private SerialPortClient commProxy;
  22. private GSIceCream_EndCookEvent iceCreamEndCook = new GSIceCream_EndCookEvent();
  23. public Action<bool> PauseAsk { get; set; }
  24. /// <summary>
  25. /// 初始化
  26. /// </summary>
  27. internal void Init(SerialPortClient commProxy)
  28. {
  29. this.commProxy = commProxy;
  30. ICMSG_Heart_DW heartDW = new ICMSG_Heart_DW();
  31. cmdHeartDW = IcPack.StructureToByte(heartDW);
  32. EventBus.GetInstance.Subscribe<GSIceCream_ModeSetEvent>(0, ModeSetEventHandle);
  33. EventBus.GetInstance.Subscribe<GSIceCream_DischargeEvent>(0, DischargeEventHandle);
  34. }
  35. /// <summary>
  36. /// 发送心跳
  37. /// </summary>
  38. internal byte[] GetHeartDW()
  39. {
  40. return cmdHeartDW;
  41. }
  42. public void ModeSetEventHandle(IEvent @event, EventCallBackHandle callBack = null)
  43. {
  44. PauseAsk?.Invoke(true);
  45. Thread.Sleep(200);
  46. var data = IcPack.StructureToByte(ICMSG_MODE_DW.Build(((GSIceCream_ModeSetEvent)@event).Mode));
  47. commProxy.SendData(data);
  48. Thread.Sleep(200);
  49. PauseAsk?.Invoke(false);
  50. MessageLog.GetInstance.Show(string.Format("设置模式[{0}]", ((GSIceCream_ModeSetEvent)@event).Mode));
  51. }
  52. public void DischargeEventHandle(IEvent @event, EventCallBackHandle callBack = null)
  53. {
  54. if (MorkIStatus.GetInstance.Fault != MORKI_FAULT.未发生故障)
  55. {
  56. MessageLog.GetInstance.Show(string.Format("当前存在故障[{0}%],不允许制作", MorkIStatus.GetInstance.Fault));
  57. callBack?.Invoke(false);
  58. return;
  59. }
  60. if (MorkIStatus.GetInstance.CXB <= 86)
  61. {
  62. MessageLog.GetInstance.Show(string.Format("当前成型比[{0}%],低于86%,不允许制作", MorkIStatus.GetInstance.CXB));
  63. callBack?.Invoke(false);
  64. return;
  65. }
  66. bool modeRight = MorkIStatus.GetInstance.CurrentMode == MORKI_MODE.制冷模式;
  67. if (!modeRight)
  68. {
  69. PauseAsk?.Invoke(true);
  70. Thread.Sleep(200);
  71. var temp = IcPack.StructureToByte(ICMSG_MODE_DW.Build(MORKI_MODE.制冷模式));
  72. commProxy.SendData(temp);
  73. Thread.Sleep(200);
  74. PauseAsk?.Invoke(false);
  75. MessageLog.GetInstance.Show(string.Format("出料操作->设置模式[{0}]", MORKI_MODE.制冷模式));
  76. DateTime freeTime = DateTime.Now.AddSeconds(5);
  77. while (DateTime.Now < freeTime)
  78. {
  79. Thread.Sleep(10);
  80. modeRight = MorkIStatus.GetInstance.CurrentMode == MORKI_MODE.制冷模式;
  81. if (modeRight)
  82. break;
  83. }
  84. }
  85. if (modeRight)
  86. {
  87. PauseAsk?.Invoke(true);
  88. Thread.Sleep(200);
  89. var data = IcPack.StructureToByte(ICMSG_MODE_DW.Build(MORKI_MODE.打料));
  90. commProxy.SendData(data);
  91. Thread.Sleep(200);
  92. PauseAsk?.Invoke(false);
  93. iceCreamEndCook.Publish();
  94. MessageLog.GetInstance.Show(string.Format("出料操作->设置模式[{0}]", MORKI_MODE.打料));
  95. callBack?.Invoke(true);
  96. }
  97. else
  98. {
  99. MessageLog.GetInstance.Show(string.Format("出料操作->模式切换失败,当前模式[{0}],不允许出料", MorkIStatus.GetInstance.CurrentMode));
  100. callBack?.Invoke(false);
  101. }
  102. }
  103. }
  104. }