ReservoirDiReplenHelper.cs 8.1 KB

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