DMReservoirInitializeRoutine.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. using Aitex.Core.RT.Device;
  2. using Aitex.Core.RT.Log;
  3. using Aitex.Core.RT.Routine;
  4. using Aitex.Core.RT.SCCore;
  5. using MECF.Framework.Common.Alarm;
  6. using MECF.Framework.Common.RecipeCenter;
  7. using MECF.Framework.Common.Routine;
  8. using MECF.Framework.Common.Utilities;
  9. using PunkHPX8_Core;
  10. using PunkHPX8_RT.Devices.Facilities;
  11. using PunkHPX8_RT.Devices.PlatingCell;
  12. using PunkHPX8_RT.Devices.Reservoir;
  13. using PunkHPX8_RT.Devices.Temperature;
  14. using System;
  15. using System.Collections.Generic;
  16. using System.Linq;
  17. using System.Text;
  18. using System.Threading.Tasks;
  19. namespace PunkHPX8_RT.Modules.Reservoir
  20. {
  21. public class DMReservoirInitializeRoutine : RoutineBase, IRoutine
  22. {
  23. private enum InitializeStep
  24. {
  25. OpenIsolationValve,
  26. CAPump,
  27. CAPumpWait,
  28. ANPump,
  29. ANPumpWait,
  30. CheckFlowWait,
  31. CellManualCheckFlow,
  32. CellAutoCheckFlow,
  33. CheckDiReplen,
  34. AutoDiReplen,
  35. AutoCellAutoEnableHED,
  36. AutoCellAutoEnableHEDDelay,
  37. AutoCellAutoEnableHEDCheck,
  38. End
  39. }
  40. #region 常量
  41. private const string AUTO = "Auto";
  42. private const string MANUAL = "Manual";
  43. private const int ENABLE = 5;
  44. #endregion
  45. #region 内部变量
  46. CAPumpOnRoutine _caPumpOnRoutine;
  47. ANPumpOnRoutine _anPumpOnRoutine;
  48. DMReservoirDevice _dmReservoirDevice;
  49. private ResRecipe _recipe;
  50. private PlatingCellDevice _platingCellDevices;
  51. private TemperatureController _temperatureController;
  52. private double _hedFlowLowLimit;
  53. private int _autoHedDelay = 0;
  54. private int _flowFaultHoldOffTime = 1000;
  55. private double _cellFlowStartLowLimit = 3;
  56. private double _anFlowStartLowLimit = 0.5;
  57. #endregion
  58. /// <summary>
  59. /// 构造函数
  60. /// </summary>
  61. /// <param name="module"></param>
  62. public DMReservoirInitializeRoutine(string module) : base(module)
  63. {
  64. }
  65. /// <summary>
  66. /// 中止
  67. /// </summary>
  68. public void Abort()
  69. {
  70. _caPumpOnRoutine.Abort();
  71. _anPumpOnRoutine.Abort();
  72. }
  73. /// <summary>
  74. /// 监控
  75. /// </summary>
  76. /// <returns></returns>
  77. public RState Monitor()
  78. {
  79. Runner.Run(InitializeStep.OpenIsolationValve, OpenIsolationValve,_delay_1ms)
  80. .Run(InitializeStep.CAPump, () => { return _caPumpOnRoutine.Start() == RState.Running; }, _delay_1s)
  81. .WaitWithStopCondition(InitializeStep.CAPumpWait, () => CommonFunction.CheckRoutineEndState(_caPumpOnRoutine), () => CommonFunction.CheckRoutineStopState(_caPumpOnRoutine))
  82. .Run(InitializeStep.ANPump, () => { return _anPumpOnRoutine.Start() == RState.Running; }, _delay_1ms)
  83. .WaitWithStopCondition(InitializeStep.ANPumpWait, () => CommonFunction.CheckRoutineEndState(_anPumpOnRoutine), () => CommonFunction.CheckRoutineStopState(_anPumpOnRoutine))
  84. .Delay(InitializeStep.CheckFlowWait, _flowFaultHoldOffTime)
  85. .RunIf(InitializeStep.CellManualCheckFlow,_dmReservoirDevice.OperationMode == MANUAL,ManualCheckFlow,_delay_1ms)
  86. .RunIf(InitializeStep.CellAutoCheckFlow,_dmReservoirDevice.OperationMode == AUTO, AutoCheckFlow, _delay_1ms)
  87. .RunIf(InitializeStep.AutoDiReplen, _recipe.DIReplenEnable || _recipe.ANDIReplenEnable, CheckFacilitiesDiReplenStatus, _delay_1ms)
  88. .Run(InitializeStep.AutoCellAutoEnableHED, AutoHedOn, _delay_1ms)
  89. .Delay(InitializeStep.AutoCellAutoEnableHEDDelay, _autoHedDelay)
  90. .Run(InitializeStep.AutoCellAutoEnableHEDCheck, AutoHedSuccess, _delay_1ms)
  91. .End(InitializeStep.End, ClearAlarmDataError, _delay_1ms);
  92. return Runner.Status;
  93. }
  94. /// <summary>
  95. /// 打开Isolation valve
  96. /// </summary>
  97. /// <returns></returns>
  98. private bool OpenIsolationValve()
  99. {
  100. return _dmReservoirDevice.ANIsolationOn() && _dmReservoirDevice.CAIsolationOn() && _dmReservoirDevice.ReturnValveOn("",null);
  101. }
  102. /// <summary>
  103. /// 检查cell flow 和an flow是否大于配置项
  104. /// </summary>
  105. /// <returns></returns>
  106. private bool ManualCheckFlow()
  107. {
  108. if(_dmReservoirDevice.ReservoirData.CaFlow < _cellFlowStartLowLimit)
  109. {
  110. _dmReservoirDevice.CAPumpOff("",null);
  111. _dmReservoirDevice.CAIsolationOff();
  112. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "CA Flow is less than cellFlowStartLowLimit ");
  113. return false;
  114. }
  115. if(_dmReservoirDevice.ReservoirData.AnFlow < _anFlowStartLowLimit)
  116. {
  117. _dmReservoirDevice.AnPumpOff();
  118. _dmReservoirDevice.ANIsolationOff();
  119. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "AN Flow is less than ANFlowStartLowLimit");
  120. return false;
  121. }
  122. return true;
  123. }
  124. /// <summary>
  125. /// 检查cell flow 和an flow是否大于recipe的设定
  126. /// </summary>
  127. /// <returns></returns>
  128. private bool AutoCheckFlow()
  129. {
  130. if (_dmReservoirDevice.ReservoirData.CaFlow < _recipe.CAFlowRateErrorLow)
  131. {
  132. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "CA Flow is less than recipe CAFlowRateErrorLow");
  133. return false;
  134. }
  135. if (_dmReservoirDevice.ReservoirData.AnFlow < _recipe.ANFlowRateErrorLow)
  136. {
  137. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "AN Flow is less than recipe ANFlowRateErrorLow");
  138. return false;
  139. }
  140. return true;
  141. }
  142. /// <summary>
  143. /// 检验总Di有没有开
  144. /// </summary>
  145. /// <returns></returns>
  146. private bool CheckFacilitiesDiReplenStatus()
  147. {
  148. SystemFacilities systemFacilities = DEVICE.GetDevice<SystemFacilities>("System.Facilities");
  149. if (systemFacilities != null)
  150. {
  151. bool result = systemFacilities.DIReplenEnable;
  152. if (!result)
  153. {
  154. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "Facilities DiReplen is disable");
  155. }
  156. return result;
  157. }
  158. return false;
  159. }
  160. /// <summary>
  161. /// 自动HED On
  162. /// </summary>
  163. /// <returns></returns>
  164. private bool AutoHedOn()
  165. {
  166. bool result = _dmReservoirDevice.ReservoirData.CaFlow < _cellFlowStartLowLimit;
  167. if (result)
  168. {
  169. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"CA Flow {_dmReservoirDevice.ReservoirData.CaFlow} is less than CellFlowStartLowLimit{_cellFlowStartLowLimit}");
  170. return false;
  171. }
  172. _autoHedDelay = _delay_2s;
  173. result = _temperatureController.EnableOperation("", null);
  174. if (!result)
  175. {
  176. return false;
  177. }
  178. result = _temperatureController.SetTargetTemperatureOperation("", new object[] { _recipe.TemperatureSetPoint });
  179. if (!result)
  180. {
  181. return false;
  182. }
  183. return true;
  184. }
  185. /// <summary>
  186. /// 检验Hed是否成功
  187. /// </summary>
  188. /// <returns></returns>
  189. private bool AutoHedSuccess()
  190. {
  191. if (_temperatureController.TemperatureData.ControlOperationModel == 0)
  192. {
  193. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "Temperature control is disable");
  194. return false;
  195. }
  196. if (Math.Abs(_recipe.TemperatureSetPoint - _temperatureController.TemperatureData.TargetTemperature) >= 0.1 * _recipe.TemperatureSetPoint)
  197. {
  198. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"recipe temperature {_recipe.TemperatureSetPoint} is not match temperature target point {_temperatureController.TemperatureData.TargetTemperature}");
  199. return false;
  200. }
  201. return true;
  202. }
  203. /// <summary>
  204. /// 清除alarm界面相关的dataerror
  205. /// </summary>
  206. private bool ClearAlarmDataError()
  207. {
  208. //AlarmListManager.Instance.RemoveDataError(Module);
  209. //_dmReservoirDevice.ClearErrorLogSet(Module); //清除device里面的ErrorLogSet
  210. return true;
  211. }
  212. /// <summary>
  213. /// 启动
  214. /// </summary>
  215. /// <param name="objs"></param>
  216. /// <returns></returns>
  217. public RState Start(params object[] objs)
  218. {
  219. _caPumpOnRoutine = new CAPumpOnRoutine(Module);
  220. _anPumpOnRoutine = new ANPumpOnRoutine(Module);
  221. _dmReservoirDevice = DEVICE.GetDevice<DMReservoirDevice>(Module);
  222. //_dmReservoirDevice.ClearErrorLogSet(Module);
  223. _platingCellDevices = (PlatingCellDevice)objs[0];
  224. _temperatureController = (TemperatureController)objs[1];
  225. _recipe = _dmReservoirDevice.Recipe;
  226. _flowFaultHoldOffTime = SC.GetValue<int>($"PlatingCell.FlowFaultHoldOffTime");
  227. _cellFlowStartLowLimit = SC.GetValue<double>($"PlatingCell.CellFlowStartLowLimit");
  228. _anFlowStartLowLimit = SC.GetValue<double>($"PlatingCell.ANFlowStartLowLimit");
  229. if (!CheckPreCondition())
  230. {
  231. return RState.Failed;
  232. }
  233. return Runner.Start(Module, "Start D&M Initialize");
  234. }
  235. /// <summary>
  236. /// 检验前置条件
  237. /// </summary>
  238. /// <returns></returns>
  239. private bool CheckPreCondition()
  240. {
  241. if (_recipe == null)
  242. {
  243. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "recipe is null");
  244. return false;
  245. }
  246. if (!_temperatureController.IsConnected)
  247. {
  248. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "Temperature is not connected");
  249. return false;
  250. }
  251. if (!CheckFacility())
  252. {
  253. return false;
  254. }
  255. return true;
  256. }
  257. /// <summary>
  258. /// 检验facility
  259. /// </summary>
  260. /// <returns></returns>
  261. private bool CheckFacility()
  262. {
  263. SystemFacilities systemFacilities = DEVICE.GetDevice<SystemFacilities>("System.Facilities");
  264. if (systemFacilities != null)
  265. {
  266. if (!systemFacilities.HouseChilledWaterEnable)
  267. {
  268. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "HouseChilledWaterEnable is false");
  269. return false;
  270. }
  271. if (!systemFacilities.DIFillEnable)
  272. {
  273. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "DIFillEnable is false");
  274. return false;
  275. }
  276. if (!systemFacilities.DIReplenEnable)
  277. {
  278. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "DIReplenEnable is false");
  279. return false;
  280. }
  281. }
  282. else
  283. {
  284. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "DIReplenEnable is false");
  285. return false;
  286. }
  287. return true;
  288. }
  289. }
  290. }