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.
 
 

96 lines
3.4 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. /// <summary>
  22. /// 初始化
  23. /// </summary>
  24. internal void Init(SerialPortClient commProxy)
  25. {
  26. this.commProxy = commProxy;
  27. ICMSG_Heart_DW heartDW = new ICMSG_Heart_DW();
  28. cmdHeartDW = IcPack.StructureToByte(heartDW);
  29. EventBus.GetInstance().Subscribe<ModeSetEvent>(ModeSetEventHandle);
  30. EventBus.GetInstance().Subscribe<DischargeEvent>(DischargeEventHandle);
  31. }
  32. /// <summary>
  33. /// 发送心跳
  34. /// </summary>
  35. internal byte[] GetHeartDW()
  36. {
  37. return cmdHeartDW;
  38. }
  39. public void ModeSetEventHandle(IEvent @event, EventCallBackHandle callBack = null)
  40. {
  41. var data = IcPack.StructureToByte(ICMSG_MODE_DW.Build(((ModeSetEvent)@event).Mode));
  42. commProxy.SendData(data);
  43. MessageLog.GetInstance.Show(string.Format("设置模式[{0}]", ((ModeSetEvent)@event).Mode));
  44. }
  45. public void DischargeEventHandle(IEvent @event, EventCallBackHandle callBack = null)
  46. {
  47. if (MorkIStatus.GetInstance().Fault != MORKI_FAULT.未发生故障)
  48. {
  49. MessageLog.GetInstance.Show(string.Format("当前存在故障[{0}%],不允许制作", MorkIStatus.GetInstance().Fault));
  50. return;
  51. }
  52. if (MorkIStatus.GetInstance().CXB <= 86)
  53. {
  54. MessageLog.GetInstance.Show(string.Format("当前成型比[{0}%],低于86%,不允许制作", MorkIStatus.GetInstance().CXB));
  55. return;
  56. }
  57. bool modeRight = MorkIStatus.GetInstance().CurrentMode == MORKI_MODE.制冷模式;
  58. if (!modeRight)
  59. {
  60. var temp = IcPack.StructureToByte(ICMSG_MODE_DW.Build(MORKI_MODE.制冷模式));
  61. commProxy.SendData(temp);
  62. MessageLog.GetInstance.Show(string.Format("出料操作->设置模式[{0}]", MORKI_MODE.制冷模式));
  63. DateTime freeTime = DateTime.Now.AddSeconds(5);
  64. while (DateTime.Now < freeTime)
  65. {
  66. Thread.Sleep(10);
  67. modeRight = MorkIStatus.GetInstance().CurrentMode == MORKI_MODE.制冷模式;
  68. if (modeRight)
  69. break;
  70. }
  71. }
  72. if (modeRight)
  73. {
  74. var data = IcPack.StructureToByte(ICMSG_MODE_DW.Build(MORKI_MODE.打料));
  75. commProxy.SendData(data);
  76. iceCreamEndCook.Publish();
  77. MessageLog.GetInstance.Show(string.Format("出料操作->设置模式[{0}]", MORKI_MODE.打料));
  78. }
  79. else
  80. {
  81. MessageLog.GetInstance.Show(string.Format("出料操作->模式切换失败,当前模式[{0}],不允许出料", MorkIStatus.GetInstance().CurrentMode));
  82. }
  83. }
  84. }
  85. }