终端一体化运控平台
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 

119 righe
4.3 KiB

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