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.
 
 

114 lines
3.5 KiB

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