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.
 
 

129 line
4.0 KiB

  1. using HBLConsole.Service;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using static HBLDevice.IceCream.MessageDefine;
  8. namespace HBLDevice.IceCream
  9. {
  10. public class MorkIStatus : Singleton<MorkIStatus>
  11. {
  12. private DateTime lastRefreshTime = DateTime.MinValue;
  13. /// <summary>
  14. /// 是否在线
  15. /// </summary>
  16. public bool OnLine { get { return DateTime.Now.Subtract(lastRefreshTime).TotalSeconds <= 3; } }
  17. /// <summary>
  18. /// 预冷温度
  19. /// </summary>
  20. public short YLWD { get; set; }
  21. /// <summary>
  22. /// 回气温度
  23. /// </summary>
  24. public short HQWD { get; set; }
  25. /// <summary>
  26. /// 环境温度
  27. /// </summary>
  28. public short HJWD { get; set; }
  29. /// <summary>
  30. /// 电流
  31. /// </summary>
  32. public short DL { get; set; }
  33. /// <summary>
  34. /// 电压
  35. /// </summary>
  36. public short DY { get; set; }
  37. /// <summary>
  38. /// 当前模式
  39. /// </summary>
  40. public MORKI_MODE CurrentMode { get; set; }
  41. /// <summary>
  42. /// 故障
  43. /// </summary>
  44. public MORKI_FAULT Fault { get; set; }
  45. /// <summary>
  46. /// 成型比
  47. /// </summary>
  48. public byte CXB { get; set; }
  49. /// <summary>
  50. /// 成型比(门限)
  51. /// </summary>
  52. public byte CXB_Threshold { get; set; }
  53. /// <summary>
  54. /// 打料完成(完成为true,正在打料为false)
  55. /// </summary>
  56. public bool DLCompleted { get; set; }
  57. public bool CanDo
  58. {
  59. get
  60. {
  61. if (!OnLine)
  62. return false;
  63. if (Fault != MORKI_FAULT.未发生故障)
  64. return false;
  65. if (CXB < CXB_Threshold)
  66. return false;
  67. return true;
  68. }
  69. }
  70. private void ProcessHeart(ICMSG_Heart_UP heartUpMsg)
  71. {
  72. CurrentMode = heartUpMsg.MS;
  73. YLWD = BitConverter.ToInt16(new byte[] { heartUpMsg.YLWD_L, heartUpMsg.YLWD_H }, 0);
  74. HQWD = BitConverter.ToInt16(new byte[] { heartUpMsg.HQWD_L, heartUpMsg.HQWD_H }, 0);
  75. HJWD = BitConverter.ToInt16(new byte[] { heartUpMsg.HJWD_L, heartUpMsg.HJWD_H }, 0);
  76. DL = BitConverter.ToInt16(new byte[] { heartUpMsg.DL_L, heartUpMsg.DL_H }, 0);
  77. Fault = (MORKI_FAULT)BitConverter.ToInt16(new byte[] { heartUpMsg.GZ_L, heartUpMsg.GZ_H }, 0);
  78. CXB = heartUpMsg.CXB;
  79. DLCompleted = (heartUpMsg.DLTJ >> 4 & 1) == 1;
  80. if (RTrig.GetInstance("打料完成检测").Start(DLCompleted))
  81. {
  82. MessageLog.GetInstance.Show("打料完成");
  83. }
  84. if (RTrig.GetInstance("打料中检测").Start(!DLCompleted))
  85. {
  86. MessageLog.GetInstance.Show("打料中");
  87. }
  88. //MessageLog.GetInstance.Show(string.Format("当前模式为:{0}", CurrentMode));
  89. }
  90. private void ProcessModeUp(ICMSG_MODE_UP modeUpMsg)
  91. {
  92. MessageLog.GetInstance.Show(string.Format("模式返回为:{0}", modeUpMsg.Mode));
  93. }
  94. public void ProcessMsg(byte[] data)
  95. {
  96. lastRefreshTime = DateTime.Now;
  97. try
  98. {
  99. if (data.Length < 5)
  100. return;
  101. switch (data[2])
  102. {
  103. case (byte)IC_CMD.HEART:
  104. var msg = IcPack.ByteToStructure<ICMSG_Heart_UP>(data.ToArray());
  105. ProcessHeart(msg);
  106. break;
  107. case (byte)IC_CMD.MODE:
  108. var modeUp = IcPack.ByteToStructure<ICMSG_MODE_UP>(data.ToArray());
  109. ProcessModeUp(modeUp);
  110. break;
  111. }
  112. }
  113. catch (Exception ex)
  114. {
  115. }
  116. }
  117. }
  118. }