ReservoirDiReplenHelper.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. using Aitex.Core.RT.Log;
  2. using Aitex.Core.RT.SCCore;
  3. using MECF.Framework.Common.Persistent.Reservoirs;
  4. using MECF.Framework.Common.RecipeCenter;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Reflection;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. namespace CyberX8_RT.Devices.Reservoir
  12. {
  13. public class ReservoirDiReplenHelper
  14. {
  15. #region 内部变量
  16. /// <summary>
  17. /// 模块名称
  18. /// </summary>
  19. private string _module;
  20. /// <summary>
  21. /// 持久化对象
  22. /// </summary>
  23. private ReservoirsPersistentValue _persistentValue;
  24. /// <summary>
  25. /// 锁
  26. /// </summary>
  27. private object _locker = new object();
  28. #endregion
  29. /// <summary>
  30. /// 构造函数
  31. /// </summary>
  32. /// <param name="module"></param>
  33. /// <param name="persistentValue"></param>
  34. /// <param name="resRecipe"></param>
  35. public ReservoirDiReplenHelper(string module,ReservoirsPersistentValue persistentValue)
  36. {
  37. _module = module;
  38. _persistentValue = persistentValue;
  39. }
  40. /// <summary>
  41. /// 监控
  42. /// </summary>
  43. public void MonitorPeriodTime()
  44. {
  45. double levelHysteresis = SC.GetValue<double>("Reservoir.LevelHysteresis");
  46. double diValveMaxOnTimePeriod = SC.GetValue<double>($"Reservoir.{_module}.DIValveMaxOnTimePeriod");
  47. //没有在注水
  48. if (_persistentValue != null && !_persistentValue.IsDiReplenOn)
  49. {
  50. //超过时间
  51. if (DateTime.Now.Subtract(_persistentValue.PeriodStartTime).TotalMinutes >= diValveMaxOnTimePeriod * 60)
  52. {
  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)
  64. {
  65. lock (_locker)
  66. {
  67. _persistentValue.TotalReplen = _persistentValue.LastTotalReplen + (int)DateTime.Now.Subtract(_persistentValue.DiReplenTime).TotalSeconds;
  68. }
  69. if(DateTime.Now.Subtract(_persistentValue.DiReplenTime).TotalSeconds >= replenSecond)
  70. {
  71. bool result = direplenOffAction("",null);
  72. if(result)
  73. {
  74. _persistentValue.LastTotalReplen = _persistentValue.TotalReplen;
  75. _persistentValue.IsDiReplenOn = false;
  76. ReservoirsPersistentManager.Instance.UpdatePersistentValue(_module);
  77. LOG.WriteLog(eEvent.INFO_RESERVOIR, _module, "Manual Direplen complete");
  78. }
  79. return result;
  80. }
  81. return false;
  82. }
  83. /// <summary>
  84. /// 单次自动注水超时
  85. /// </summary>
  86. /// <returns></returns>
  87. public bool AutoDiReplenMonitorTimeOut(Func<string, object[], bool> direplenOffAction)
  88. {
  89. lock (_locker)
  90. {
  91. _persistentValue.TotalReplen = _persistentValue.LastTotalReplen+(int)DateTime.Now.Subtract(_persistentValue.DiReplenTime).TotalSeconds;
  92. }
  93. double diValveMaxOnTimePerFill = SC.GetValue<double>($"Reservoir.{_module}.DIValveMaxOnTimePerFill");
  94. if(DateTime.Now.Subtract(_persistentValue.DiReplenTime).TotalSeconds >= diValveMaxOnTimePerFill * 60)
  95. {
  96. bool result = direplenOffAction("", null);
  97. if(result)
  98. {
  99. LOG.WriteLog(eEvent.WARN_RESERVOIR, _module, $"Direplen time over {diValveMaxOnTimePerFill}");
  100. _persistentValue.LastTotalReplen = _persistentValue.TotalReplen;
  101. _persistentValue.IsDiReplenOn = false;
  102. ReservoirsPersistentManager.Instance.UpdatePersistentValue(_module);
  103. }
  104. return result;
  105. }
  106. return false;
  107. }
  108. /// <summary>
  109. /// 自动注水是否结束
  110. /// </summary>
  111. /// <param name="level"></param>
  112. /// <param name="recipeLevel"></param>
  113. /// <param name="direplenOffAction"></param>
  114. /// <returns></returns>
  115. public bool AutoDiReplenMonitorComplete(double level,double recipeLevel,ResRecipe _recipe,Func<string, object[], bool> direplenOffAction)
  116. {
  117. double levelHysteresis = SC.GetValue<double>("Reservoir.LevelHysteresis");
  118. //按液位补水
  119. if (_recipe.DIReplenEnable && _recipe.DIReplenTimeRate == 0 && _recipe.DIReplenCurrentRate == 0 &&
  120. level >= recipeLevel)
  121. {
  122. LOG.WriteLog(eEvent.INFO_RESERVOIR, _module, "Auto replen complete");
  123. bool result= direplenOffAction("",null);
  124. if(result)
  125. {
  126. _persistentValue.LastTotalReplen = _persistentValue.TotalReplen;
  127. _persistentValue.IsDiReplenOn = false;
  128. ReservoirsPersistentManager.Instance.UpdatePersistentValue(_module);
  129. }
  130. }
  131. return false;
  132. }
  133. }
  134. }