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.
 
 

94 lines
3.3 KiB

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