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.
 
 

128 regels
4.0 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. /// <summary>
  55. /// 打料完成(完成为true,正在打料为false)
  56. /// </summary>
  57. public bool DLCompleted { get; set; }
  58. public bool CanDo
  59. {
  60. get
  61. {
  62. if (!OnLine)
  63. return false;
  64. if (Fault != MORKI_FAULT.未发生故障)
  65. return false;
  66. if (CXB < CXB_Threshold)
  67. return false;
  68. return true;
  69. }
  70. }
  71. private void ProcessHeart(ICMSG_Heart_UP heartUpMsg)
  72. {
  73. CurrentMode = heartUpMsg.MS;
  74. YLWD = BitConverter.ToInt16(new byte[] { heartUpMsg.YLWD_L, heartUpMsg.YLWD_H }, 0);
  75. HQWD = BitConverter.ToInt16(new byte[] { heartUpMsg.HQWD_L, heartUpMsg.HQWD_H }, 0);
  76. HJWD = BitConverter.ToInt16(new byte[] { heartUpMsg.HJWD_L, heartUpMsg.HJWD_H }, 0);
  77. DL = BitConverter.ToInt16(new byte[] { heartUpMsg.DL_L, heartUpMsg.DL_H }, 0);
  78. Fault = (MORKI_FAULT)BitConverter.ToInt16(new byte[] { heartUpMsg.GZ_L, heartUpMsg.GZ_H }, 0);
  79. CXB = heartUpMsg.CXB;
  80. DLCompleted = (heartUpMsg.DLTJ >> 4 & 1) == 1;
  81. if (RTrig.GetInstance("打料完成检测").Start(DLCompleted))
  82. {
  83. MessageLog.GetInstance.Show("打料完成");
  84. }
  85. if(RTrig.GetInstance("打料中检测").Start(!DLCompleted))
  86. {
  87. MessageLog.GetInstance.Show("打料中");
  88. }
  89. //MessageLog.GetInstance.Show(string.Format("当前模式为:{0}", CurrentMode));
  90. }
  91. private void ProcessModeUp(ICMSG_MODE_UP modeUpMsg)
  92. {
  93. MessageLog.GetInstance.Show(string.Format("模式返回为:{0}", modeUpMsg.Mode));
  94. }
  95. public void ProcessMsg(byte[] data)
  96. {
  97. lastRefreshTime = DateTime.Now;
  98. try
  99. {
  100. if (data.Length < 5)
  101. return;
  102. switch (data[2])
  103. {
  104. case (byte)IC_CMD.HEART:
  105. var msg = IcPack.ByteToStructure<ICMSG_Heart_UP>(data.ToArray());
  106. ProcessHeart(msg);
  107. break;
  108. case (byte)IC_CMD.MODE:
  109. var modeUp = IcPack.ByteToStructure<ICMSG_MODE_UP>(data.ToArray());
  110. ProcessModeUp(modeUp);
  111. break;
  112. }
  113. }
  114. catch (Exception ex)
  115. {
  116. }
  117. }
  118. }
  119. }