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.
 
 

113 lines
3.4 KiB

  1. using BPA.Utility;
  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. public bool CanDo
  54. {
  55. get
  56. {
  57. if (!OnLine)
  58. return false;
  59. if (Fault != MORKI_FAULT.未发生故障)
  60. return false;
  61. if (CXB < CXB_Threshold)
  62. return false;
  63. return true;
  64. }
  65. }
  66. private void ProcessHeart(ICMSG_Heart_UP heartUpMsg)
  67. {
  68. CurrentMode = heartUpMsg.MS;
  69. YLWD = BitConverter.ToInt16(new byte[] { heartUpMsg.YLWD_L, heartUpMsg.YLWD_H }, 0);
  70. HQWD = BitConverter.ToInt16(new byte[] { heartUpMsg.HQWD_L, heartUpMsg.HQWD_H }, 0);
  71. HJWD = BitConverter.ToInt16(new byte[] { heartUpMsg.HJWD_L, heartUpMsg.HJWD_H }, 0);
  72. DL = BitConverter.ToInt16(new byte[] { heartUpMsg.DL_L, heartUpMsg.DL_H }, 0);
  73. Fault = (MORKI_FAULT)BitConverter.ToInt16(new byte[] { heartUpMsg.GZ_L, heartUpMsg.GZ_H }, 0);
  74. CXB = heartUpMsg.CXB;
  75. Noticer.ShowEx(string.Format("当前模式为:{0}", CurrentMode));
  76. }
  77. private void ProcessModeUp(ICMSG_MODE_UP modeUpMsg)
  78. {
  79. Noticer.ShowEx(string.Format("模式返回为:{0}", modeUpMsg.Mode));
  80. }
  81. public void ProcessMsg(byte[] data)
  82. {
  83. lastRefreshTime = DateTime.Now;
  84. try
  85. {
  86. if (data.Length < 5)
  87. return;
  88. switch (data[2])
  89. {
  90. case (byte)IC_CMD.HEART:
  91. var msg = IcPack.ByteToStructure<ICMSG_Heart_UP>(data.ToArray());
  92. ProcessHeart(msg);
  93. break;
  94. case (byte)IC_CMD.MODE:
  95. var modeUp = IcPack.ByteToStructure<ICMSG_MODE_UP>(data.ToArray());
  96. ProcessModeUp(modeUp);
  97. break;
  98. }
  99. }
  100. catch (Exception ex)
  101. {
  102. }
  103. }
  104. }
  105. }