终端一体化运控平台
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

135 lines
5.3 KiB

  1. using BPASmartClient.Message;
  2. using BPASmartClient.MessageCommunication;
  3. using BPASmartClient.MessageCommunication.MsgControl;
  4. using BPASmartClient.SerialPort;
  5. using System;
  6. using System.Threading;
  7. namespace BPASmartClient.GSIceCream
  8. {
  9. /// <summary>
  10. /// 指令封装
  11. /// </summary>
  12. internal class CommandHandler
  13. {
  14. byte[] cmdHeartDW;
  15. private SerialPortClient commProxy;
  16. public Action<bool> PauseAsk { get; set; }
  17. /// <summary>
  18. /// 初始化
  19. /// </summary>
  20. internal void Init(SerialPortClient commProxy)
  21. {
  22. this.commProxy = commProxy;
  23. ICMSG_Heart_DW heartDW = new ICMSG_Heart_DW();
  24. cmdHeartDW = IcPack.StructureToByte(heartDW);
  25. Class_InnerMessageBus.GetInstance().ListenMessage(this,Class_MessageName.GSIceCream_ModeSet,"ModeSetHandler");
  26. Class_InnerMessageBus.GetInstance().ListenMessage(this,Class_MessageName.GSIceCream_Discharge,"DischargeHandler");
  27. }
  28. /// <summary>
  29. /// 发送心跳
  30. /// </summary>
  31. internal byte[] GetHeartDW()
  32. {
  33. return cmdHeartDW;
  34. }
  35. /// <summary>
  36. /// 模式设置
  37. /// </summary>
  38. public void ModeSetHandler(object sender,InnerMessageEventArgs e)
  39. {
  40. try
  41. {
  42. if (e.obj_MessageObj is MORKI_MODE)
  43. {
  44. PauseAsk?.Invoke(true);
  45. Thread.Sleep(200);
  46. var data = IcPack.StructureToByte(ICMSG_MODE_DW.Build((MORKI_MODE)(e.obj_MessageObj)));
  47. commProxy.SendData(data);
  48. Thread.Sleep(200);
  49. PauseAsk?.Invoke(false);
  50. MessageLog.GetInstance.Show(string.Format("设置模式[{0}]",Enum.GetName(typeof(MORKI_MODE),(MORKI_MODE)e.obj_MessageObj)));
  51. }
  52. }
  53. catch (Exception ex)
  54. {
  55. MessageLog.GetInstance.Show($"BPASmartClient.GSIceCream 中引发错误,ModeSetHandler 类,描述:[{ex.Message}]");
  56. }
  57. }
  58. /// <summary>
  59. /// 打料
  60. /// </summary>
  61. public void DischargeHandler(object sender,InnerMessageEventArgs e)
  62. {
  63. try
  64. {
  65. if (e.obj_MessageObj is MORKI_MODE)
  66. {
  67. if (MorkIStatus.GetInstance().Fault != MORKI_FAULT.未发生故障)
  68. {
  69. MessageLog.GetInstance.Show(string.Format("当前存在故障[{0}%],不允许制作",MorkIStatus.GetInstance().Fault));
  70. //callBack?.Invoke(false);
  71. return;
  72. }
  73. if (MorkIStatus.GetInstance().CXB <= 86)
  74. {
  75. MessageLog.GetInstance.Show(string.Format("当前成型比[{0}%],低于86%,不允许制作",MorkIStatus.GetInstance().CXB));
  76. //callBack?.Invoke(false);
  77. return;
  78. }
  79. bool modeRight = MorkIStatus.GetInstance().CurrentMode == MORKI_MODE.制冷模式;
  80. if (!modeRight)
  81. {
  82. PauseAsk?.Invoke(true);
  83. Thread.Sleep(200);
  84. var temp = IcPack.StructureToByte(ICMSG_MODE_DW.Build(MORKI_MODE.制冷模式));
  85. commProxy.SendData(temp);
  86. Thread.Sleep(200);
  87. PauseAsk?.Invoke(false);
  88. MessageLog.GetInstance.Show(string.Format("出料操作->设置模式[{0}]",MORKI_MODE.制冷模式));
  89. DateTime freeTime = DateTime.Now.AddSeconds(5);
  90. while (DateTime.Now < freeTime)
  91. {
  92. Thread.Sleep(10);
  93. modeRight = MorkIStatus.GetInstance().CurrentMode == MORKI_MODE.制冷模式;
  94. if (modeRight)
  95. break;
  96. }
  97. }
  98. if (modeRight)
  99. {
  100. PauseAsk?.Invoke(true);
  101. Thread.Sleep(200);
  102. var data = IcPack.StructureToByte(ICMSG_MODE_DW.Build(MORKI_MODE.打料));
  103. commProxy.SendData(data);
  104. Thread.Sleep(200);
  105. PauseAsk?.Invoke(false);
  106. Class_InnerMessageBus.GetInstance().PostMessage(this,Class_MessageName.GSIceCream_EndCook,"");
  107. MessageLog.GetInstance.Show(string.Format("出料操作->设置模式[{0}]",MORKI_MODE.打料));
  108. //callBack?.Invoke(true);
  109. }
  110. else
  111. {
  112. MessageLog.GetInstance.Show(string.Format("出料操作->模式切换失败,当前模式[{0}],不允许出料",MorkIStatus.GetInstance().CurrentMode));
  113. //callBack?.Invoke(false);
  114. }
  115. }
  116. }
  117. catch (Exception ex)
  118. {
  119. MessageLog.GetInstance.Show($"BPASmartClient.GSIceCream 中引发错误,ModeSetHandler 类,描述:[{ex.Message}]");
  120. }
  121. }
  122. }
  123. }