终端一体化运控平台
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 

131 Zeilen
4.1 KiB

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