终端一体化运控平台
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

CommandHandler.cs 4.3 KiB

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