ReservoirDiReplenHelper.cs 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. using Aitex.Core.RT.Device;
  2. using Aitex.Core.RT.Log;
  3. using Aitex.Core.RT.SCCore;
  4. using MECF.Framework.Common.Alarm;
  5. using MECF.Framework.Common.CommonData.Reservoir;
  6. using MECF.Framework.Common.Persistent.Reservoirs;
  7. using PunkHPX8_RT.Devices.Facilities;
  8. using System;
  9. using System.Reflection;
  10. namespace PunkHPX8_RT.Devices.Reservoir
  11. {
  12. public class ReservoirDiReplenHelper
  13. {
  14. #region 内部变量
  15. /// <summary>
  16. /// 模块名称
  17. /// </summary>
  18. private string _module;
  19. /// <summary>
  20. /// 持久化对象
  21. /// </summary>
  22. private ReservoirsPersistentValue _persistentValue;
  23. /// <summary>
  24. /// 锁
  25. /// </summary>
  26. private object _locker = new object();
  27. #endregion
  28. /// <summary>
  29. /// 构造函数
  30. /// </summary>
  31. /// <param name="module"></param>
  32. /// <param name="persistentValue"></param>
  33. /// <param name="resRecipe"></param>
  34. public ReservoirDiReplenHelper(string module, ReservoirsPersistentValue persistentValue)
  35. {
  36. _module = module;
  37. _persistentValue = persistentValue;
  38. }
  39. /// <summary>
  40. /// 监控
  41. /// </summary>
  42. public void MonitorPeriodTime(ref bool maxTimeout)
  43. {
  44. //double levelHysteresis = SC.GetValue<double>("Reservoir.LevelHysteresis");
  45. double diValveMaxOnTimePeriod = SC.GetValue<double>($"Reservoir.{_module}.DIValveMaxOnTimePeriod");
  46. //没有在注水
  47. if (_persistentValue != null && !_persistentValue.IsDiReplenOn)
  48. {
  49. //超过时间
  50. if (DateTime.Now.Subtract(_persistentValue.PeriodStartTime).TotalMinutes >= diValveMaxOnTimePeriod * 60)
  51. {
  52. maxTimeout = false;
  53. _persistentValue.PeriodStartTime = DateTime.Now;
  54. _persistentValue.TotalReplen = 0;
  55. _persistentValue.LastTotalReplen = 0;
  56. ReservoirsPersistentManager.Instance.UpdatePersistentValue(_module);
  57. }
  58. }
  59. }
  60. /// <summary>
  61. /// 监控手动注水
  62. /// </summary>
  63. public bool MonitorManualDiReplenComplete(int replenSecond, Func<string, object[], bool> direplenOffAction, ref bool maxTimeout)
  64. {
  65. lock (_locker)
  66. {
  67. _persistentValue.TotalReplen = _persistentValue.LastTotalReplen + (int)DateTime.Now.Subtract(_persistentValue.DiReplenTime).TotalSeconds;
  68. }
  69. //周期内累计补水超时
  70. double diValveMaxOnTime = SC.GetValue<double>($"Reservoir.{_module}.DIValveMaxOnTime");
  71. if (_persistentValue.TotalReplen >= diValveMaxOnTime * 60)
  72. {
  73. bool result = direplenOffAction("", null);
  74. if (result)
  75. {
  76. maxTimeout = true;
  77. LOG.WriteLog(eEvent.WARN_RESERVOIR, _module, $"DiReplen time over conifg's DIValveMaxOnTime:{diValveMaxOnTime} min");
  78. _persistentValue.LastTotalReplen = _persistentValue.TotalReplen;
  79. _persistentValue.IsDiReplenOn = false;
  80. ReservoirsPersistentManager.Instance.UpdatePersistentValue(_module);
  81. }
  82. return result;
  83. }
  84. if (DateTime.Now.Subtract(_persistentValue.DiReplenTime).TotalSeconds >= replenSecond)
  85. {
  86. bool result = direplenOffAction("", null);
  87. if (result)
  88. {
  89. _persistentValue.LastTotalReplen = _persistentValue.TotalReplen;
  90. _persistentValue.IsDiReplenOn = false;
  91. ReservoirsPersistentManager.Instance.UpdatePersistentValue(_module);
  92. LOG.WriteLog(eEvent.INFO_RESERVOIR, _module, "Manual DiReplen complete");
  93. }
  94. return result;
  95. }
  96. return false;
  97. }
  98. /// <summary>
  99. /// 单次自动注水超时
  100. /// </summary>
  101. /// <returns></returns>
  102. public bool AutoDiReplenMonitorTimeOut(Func<string, object[], bool> direplenOffAction, ref bool maxTimeOut, ref bool perfillTimeOut)
  103. {
  104. lock (_locker)
  105. {
  106. _persistentValue.TotalReplen = _persistentValue.LastTotalReplen + (int)DateTime.Now.Subtract(_persistentValue.DiReplenTime).TotalSeconds;
  107. }
  108. //单次补水超时
  109. double diValveMaxOnTimePerFill = SC.GetValue<double>($"Reservoir.{_module}.DIValveMaxOnTimePerFill");
  110. if (DateTime.Now.Subtract(_persistentValue.DiReplenTime).TotalSeconds >= diValveMaxOnTimePerFill * 60)
  111. {
  112. bool result = direplenOffAction("", null);
  113. if (result)
  114. {
  115. perfillTimeOut = true;
  116. LOG.WriteLog(eEvent.WARN_RESERVOIR, _module, $"DiReplen time over conifg's DIValveMaxOnTimePerFill:{diValveMaxOnTimePerFill} min");
  117. AlarmListManager.Instance.AddWarn(_module, $"", $"{_module} DiReplen time over config DIValveMaxOnTimePerFill:{diValveMaxOnTimePerFill} min");
  118. //补水超时关闭总的补水阀
  119. SystemFacilities systemFacilities = DEVICE.GetDevice<SystemFacilities>("System.Facilities");
  120. if (systemFacilities != null)
  121. {
  122. if (systemFacilities.DIReplenEnable) systemFacilities.DiReplenDisableOperation("DiReplenDisableOperation", null);
  123. }
  124. _persistentValue.LastTotalReplen = _persistentValue.TotalReplen;
  125. _persistentValue.IsDiReplenOn = false;
  126. ReservoirsPersistentManager.Instance.UpdatePersistentValue(_module);
  127. }
  128. return result;
  129. }
  130. //周期内累计补水超时
  131. double diValveMaxOnTime = SC.GetValue<double>($"Reservoir.{_module}.DIValveMaxOnTime");
  132. if (_persistentValue.TotalReplen >= diValveMaxOnTime * 60)
  133. {
  134. bool result = direplenOffAction("", null);
  135. if (result)
  136. {
  137. maxTimeOut = true;
  138. AlarmListManager.Instance.AddWarn(_module, $"", $"{_module} DiReplen time over config DIValveMaxOnTime:{diValveMaxOnTime} min");
  139. LOG.WriteLog(eEvent.WARN_RESERVOIR, _module, $"DiReplen time over config DIValveMaxOnTime:{diValveMaxOnTime} min");
  140. _persistentValue.LastTotalReplen = _persistentValue.TotalReplen;
  141. _persistentValue.IsDiReplenOn = false;
  142. ReservoirsPersistentManager.Instance.UpdatePersistentValue(_module);
  143. }
  144. return result;
  145. }
  146. return false;
  147. }
  148. /// <summary>
  149. /// 自动注水是否结束
  150. /// </summary>
  151. /// <param name="level"></param>
  152. /// <param name="recipeLevel"></param>
  153. /// <param name="direplenOffAction"></param>
  154. /// <returns></returns>
  155. public bool AutoDiReplenMonitorComplete(double level, double recipeLevel, bool replenEnable,
  156. int direplenTimeRate, int direplenCurrentRate, Func<string, object[], bool> direplenOffAction)
  157. {
  158. double levelHysteresis = SC.GetValue<double>("Reservoir.LevelHysteresis");
  159. //按液位补水
  160. if (replenEnable && direplenTimeRate == 0 && direplenCurrentRate == 0 &&
  161. level >= recipeLevel)
  162. {
  163. LOG.WriteLog(eEvent.INFO_RESERVOIR, _module, "Auto DiReplen complete");
  164. bool result = direplenOffAction("", null);
  165. if (result)
  166. {
  167. _persistentValue.LastTotalReplen = _persistentValue.TotalReplen;
  168. _persistentValue.IsDiReplenOn = false;
  169. ReservoirsPersistentManager.Instance.UpdatePersistentValue(_module);
  170. return result;
  171. }
  172. }
  173. return false;
  174. }
  175. }
  176. }