ReservoirDiReplenHelper.cs 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. using Aitex.Core.RT.Device;
  2. using Aitex.Core.RT.Log;
  3. using Aitex.Core.RT.SCCore;
  4. using CyberX8_RT.Devices.Facilities;
  5. using MECF.Framework.Common.Alarm;
  6. using MECF.Framework.Common.Persistent.Reservoirs;
  7. using System;
  8. namespace CyberX8_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. LOG.WriteLog(eEvent.INFO_RESERVOIR, _module, $"Time is over config DIValveMaxOnTimePeriod:{diValveMaxOnTimePeriod} hour. Restart timer");
  51. maxTimeout = false;
  52. _persistentValue.PeriodStartTime = DateTime.Now;
  53. _persistentValue.TotalReplen = 0;
  54. _persistentValue.LastTotalReplen = 0;
  55. ReservoirsPersistentManager.Instance.UpdatePersistentValue(_module);
  56. }
  57. }
  58. }
  59. /// <summary>
  60. /// 监控手动注水
  61. /// </summary>
  62. public bool MonitorManualDiReplenComplete(int replenSecond, Func<string, object[], bool> direplenOffAction, ref bool maxTimeout)
  63. {
  64. lock (_locker)
  65. {
  66. _persistentValue.TotalReplen = _persistentValue.LastTotalReplen + (int)DateTime.Now.Subtract(_persistentValue.DiReplenTime).TotalSeconds;
  67. }
  68. //周期内累计补水超时
  69. double diValveMaxOnTime = SC.GetValue<double>($"Reservoir.{_module}.DIValveMaxOnTime");
  70. if (_persistentValue.TotalReplen >= diValveMaxOnTime * 60)
  71. {
  72. bool result = direplenOffAction("", null);
  73. if (result)
  74. {
  75. maxTimeout = true;
  76. LOG.WriteLog(eEvent.WARN_RESERVOIR, _module, $"DiReplen time over config DIValveMaxOnTime:{diValveMaxOnTime} min");
  77. _persistentValue.LastTotalReplen = _persistentValue.TotalReplen;
  78. _persistentValue.IsDiReplenOn = false;
  79. ReservoirsPersistentManager.Instance.UpdatePersistentValue(_module);
  80. }
  81. return result;
  82. }
  83. if (DateTime.Now.Subtract(_persistentValue.DiReplenTime).TotalSeconds >= replenSecond)
  84. {
  85. bool result = direplenOffAction("", null);
  86. if (result)
  87. {
  88. _persistentValue.LastTotalReplen = _persistentValue.TotalReplen;
  89. _persistentValue.IsDiReplenOn = false;
  90. ReservoirsPersistentManager.Instance.UpdatePersistentValue(_module);
  91. LOG.WriteLog(eEvent.INFO_RESERVOIR, _module, "Manual DiReplen Complete");
  92. }
  93. return result;
  94. }
  95. return false;
  96. }
  97. /// <summary>
  98. /// 自动注水超时
  99. /// </summary>
  100. /// <returns></returns>
  101. public bool AutoDiReplenMonitorTimeOut(Func<string, object[], bool> direplenOffAction, ref bool maxTimeOut, ref bool perfillTimeOut)
  102. {
  103. lock (_locker)
  104. {
  105. _persistentValue.TotalReplen = _persistentValue.LastTotalReplen + (int)DateTime.Now.Subtract(_persistentValue.DiReplenTime).TotalSeconds;
  106. }
  107. //单次自动补水超时
  108. double diValveMaxOnTimePerFill = SC.GetValue<double>($"Reservoir.{_module}.DIValveMaxOnTimePerFill");
  109. if (DateTime.Now.Subtract(_persistentValue.DiReplenTime).TotalSeconds >= diValveMaxOnTimePerFill * 60)
  110. {
  111. bool result = direplenOffAction("", null);
  112. if (result)
  113. {
  114. perfillTimeOut = true;
  115. AlarmListManager.Instance.AddWarn(_module, $"", $"{_module} DiReplen time over config DIValveMaxOnTimePerFill:{diValveMaxOnTimePerFill} min");
  116. LOG.WriteLog(eEvent.WARN_RESERVOIR, _module, $"DiReplen time over conifg DIValveMaxOnTimePerFill:{diValveMaxOnTimePerFill} min");
  117. //补水超时关闭总的补水阀
  118. SystemFacilities systemFacilities = DEVICE.GetDevice<SystemFacilities>("System.Facilities");
  119. if (systemFacilities != null)
  120. {
  121. if (systemFacilities.DIReplenEnable) systemFacilities.DiReplenDisableOperation("DiReplenDisableOperation", null);
  122. }
  123. _persistentValue.LastTotalReplen = _persistentValue.TotalReplen;
  124. _persistentValue.IsDiReplenOn = false;
  125. ReservoirsPersistentManager.Instance.UpdatePersistentValue(_module);
  126. }
  127. return result;
  128. }
  129. //累计补水超时
  130. double diValveMaxOnTime = SC.GetValue<double>($"Reservoir.{_module}.DIValveMaxOnTime");
  131. if (_persistentValue.TotalReplen >= diValveMaxOnTime * 60)
  132. {
  133. bool result = direplenOffAction("", null);
  134. if (result)
  135. {
  136. maxTimeOut = true;
  137. AlarmListManager.Instance.AddWarn(_module, $"", $"{_module} DiReplen time over config DIValveMaxOnTime:{diValveMaxOnTime} min");
  138. LOG.WriteLog(eEvent.WARN_RESERVOIR, _module, $"DiReplen time over conifg DIValveMaxOnTime:{diValveMaxOnTime} min");
  139. _persistentValue.LastTotalReplen = _persistentValue.TotalReplen;
  140. _persistentValue.IsDiReplenOn = false;
  141. ReservoirsPersistentManager.Instance.UpdatePersistentValue(_module);
  142. }
  143. return result;
  144. }
  145. return false;
  146. }
  147. /// <summary>
  148. /// 自动注水是否结束
  149. /// </summary>
  150. /// <param name="level"></param>
  151. /// <param name="recipeLevel"></param>
  152. /// <param name="direplenOffAction"></param>
  153. /// <returns></returns>
  154. public bool AutoDiReplenMonitorComplete(double level, double recipeLevel, bool replenEnable,
  155. int direplenTimeRate, int direplenCurrentRate, Func<string, object[], bool> direplenOffAction)
  156. {
  157. double levelHysteresis = SC.GetValue<double>("Reservoir.LevelHysteresis");
  158. //按液位补水
  159. if (replenEnable && direplenTimeRate == 0 && direplenCurrentRate == 0 &&
  160. level >= recipeLevel)
  161. {
  162. LOG.WriteLog(eEvent.INFO_RESERVOIR, _module, "Auto DiReplen Complete");
  163. bool result = direplenOffAction("", null);
  164. if (result)
  165. {
  166. _persistentValue.LastTotalReplen = _persistentValue.TotalReplen;
  167. _persistentValue.IsDiReplenOn = false;
  168. ReservoirsPersistentManager.Instance.UpdatePersistentValue(_module);
  169. return result;
  170. }
  171. }
  172. return false;
  173. }
  174. }
  175. }