Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 

105 rader
3.7 KiB

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