DMReservoirInitializeRoutine.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  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. End
  37. }
  38. #region 常量
  39. private const string AUTO = "Auto";
  40. private const string MANUAL = "Manual";
  41. private const int ENABLE = 5;
  42. #endregion
  43. #region 内部变量
  44. CAPumpOnRoutine _caPumpOnRoutine;
  45. ANPumpOnRoutine _anPumpOnRoutine;
  46. DMReservoirDevice _dmReservoirDevice;
  47. private ResRecipe _recipe;
  48. private PlatingCellDevice _platingCellDevices;
  49. private TemperatureController _temperatureController;
  50. private double _hedFlowLowLimit;
  51. private int _autoHedDelay = 0;
  52. private int _flowFaultHoldOffTime = 1000;
  53. private double _cellFlowStartLowLimit = 3;
  54. private double _anFlowStartLowLimit = 0.5;
  55. #endregion
  56. /// <summary>
  57. /// 构造函数
  58. /// </summary>
  59. /// <param name="module"></param>
  60. public DMReservoirInitializeRoutine(string module) : base(module)
  61. {
  62. }
  63. /// <summary>
  64. /// 中止
  65. /// </summary>
  66. public void Abort()
  67. {
  68. _caPumpOnRoutine.Abort();
  69. _anPumpOnRoutine.Abort();
  70. }
  71. /// <summary>
  72. /// 监控
  73. /// </summary>
  74. /// <returns></returns>
  75. public RState Monitor()
  76. {
  77. Runner.Run(InitializeStep.OpenIsolationValve, OpenIsolationValve,_delay_1ms)
  78. .Run(InitializeStep.CAPump, () => { return _caPumpOnRoutine.Start() == RState.Running; }, _delay_1s)
  79. .WaitWithStopCondition(InitializeStep.CAPumpWait, () => CommonFunction.CheckRoutineEndState(_caPumpOnRoutine), () => CommonFunction.CheckRoutineStopState(_caPumpOnRoutine))
  80. .Run(InitializeStep.ANPump, () => { return _anPumpOnRoutine.Start() == RState.Running; }, _delay_1ms)
  81. .WaitWithStopCondition(InitializeStep.ANPumpWait, () => CommonFunction.CheckRoutineEndState(_anPumpOnRoutine), () => CommonFunction.CheckRoutineStopState(_anPumpOnRoutine))
  82. .Delay(InitializeStep.CheckFlowWait, _flowFaultHoldOffTime)
  83. .RunIf(InitializeStep.CellManualCheckFlow,_dmReservoirDevice.OperationMode == MANUAL,ManualCheckFlow,_delay_1ms)
  84. .RunIf(InitializeStep.CellManualCheckFlow,_dmReservoirDevice.OperationMode == AUTO, AutoCheckFlow, _delay_1ms)
  85. .RunIf(InitializeStep.AutoDiReplen, _recipe.DIReplenEnable || _recipe.ANDIReplenEnable, CheckFacilitiesDiReplenStatus, _delay_1ms)
  86. .Run(InitializeStep.AutoCellAutoEnableHED, AutoHedOn, _delay_1ms)
  87. .End(InitializeStep.End, ClearAlarmDataError, _delay_1ms);
  88. return Runner.Status;
  89. }
  90. /// <summary>
  91. /// 打开Isolation valve
  92. /// </summary>
  93. /// <returns></returns>
  94. private bool OpenIsolationValve()
  95. {
  96. return _dmReservoirDevice.ANIsolationOn() && _dmReservoirDevice.CAIsolationOn();
  97. }
  98. /// <summary>
  99. /// 检查cell flow 和an flow是否大于配置项
  100. /// </summary>
  101. /// <returns></returns>
  102. private bool ManualCheckFlow()
  103. {
  104. //cell flow 校验待完成
  105. if(_dmReservoirDevice.ReservoirData.AnFlow < _anFlowStartLowLimit)
  106. {
  107. _dmReservoirDevice.AnPumpOff();
  108. _dmReservoirDevice.ANIsolationOff();
  109. return false;
  110. }
  111. return true;
  112. }
  113. /// <summary>
  114. /// 检查cell flow 和an flow是否大于recipe的设定
  115. /// </summary>
  116. /// <returns></returns>
  117. private bool AutoCheckFlow()
  118. {
  119. //cell flow 校验待完成
  120. if (_dmReservoirDevice.ReservoirData.AnFlow < _recipe.ANFlowRateErrorLow)
  121. {
  122. return false;
  123. }
  124. return true;
  125. }
  126. /// <summary>
  127. /// 检验总Di有没有开
  128. /// </summary>
  129. /// <returns></returns>
  130. private bool CheckFacilitiesDiReplenStatus()
  131. {
  132. SystemFacilities systemFacilities = DEVICE.GetDevice<SystemFacilities>("System.Facilities");
  133. if (systemFacilities != null)
  134. {
  135. bool result = systemFacilities.DIReplenEnable;
  136. if (!result)
  137. {
  138. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "Facilities DiReplen is disable");
  139. }
  140. return result;
  141. }
  142. return false;
  143. }
  144. /// <summary>
  145. /// 启用HED
  146. /// </summary>
  147. /// <returns></returns>
  148. private bool EnableHED()
  149. {
  150. return _temperatureController.EnableOperation("", null);
  151. }
  152. /// <summary>
  153. /// 检验所有Metal处于Manual
  154. /// </summary>
  155. /// <returns></returns>
  156. private bool CheckAutoAndAllMetalAuto()
  157. {
  158. //if (_reservoirDevice.OperationMode != AUTO)
  159. //{
  160. // return false;
  161. //}
  162. //for (int i = 0; i < _metalDevices.Count; i++)
  163. //{
  164. // CompactMembranMetalDevice hotMetalDevice = _metalDevices[i];
  165. // if (hotMetalDevice.OperationMode != AUTO)
  166. // {
  167. // return false;
  168. // }
  169. //}
  170. return true;
  171. }
  172. /// <summary>
  173. /// 自动HED On
  174. /// </summary>
  175. /// <returns></returns>
  176. private bool AutoHedOn()
  177. {
  178. bool result = _dmReservoirDevice.ReservoirData.CaFlow < _cellFlowStartLowLimit;
  179. if (result)
  180. {
  181. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"CA Flow {_dmReservoirDevice.ReservoirData.CaFlow} is less than CellFlowStartLowLimit{_cellFlowStartLowLimit}");
  182. return false;
  183. }
  184. _temperatureController.EnableOperation("", null);
  185. _temperatureController.SetTargetTemperatureOperation("", new object[] { _recipe.TemperatureSetPoint });
  186. return true;
  187. }
  188. /// <summary>
  189. /// 检验Hed是否成功
  190. /// </summary>
  191. /// <returns></returns>
  192. private bool AutoHedSuccess()
  193. {
  194. if (_temperatureController.TemperatureData.ControlOperationModel == 0)
  195. {
  196. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "Temperature control is disable");
  197. return false;
  198. }
  199. if (Math.Abs(_recipe.TemperatureSetPoint - _temperatureController.TemperatureData.TargetTemperature) >= 0.1 * _recipe.TemperatureSetPoint)
  200. {
  201. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"recipe temperature {_recipe.TemperatureSetPoint} is not match temperature target point {_temperatureController.TemperatureData.TargetTemperature}");
  202. return false;
  203. }
  204. return true;
  205. }
  206. /// <summary>
  207. /// 检验Metal A/B PowerSupplier通信状态
  208. /// </summary>
  209. /// <returns></returns>
  210. private bool AutoMetalsPowerSupplierCommuncationStatus()
  211. {
  212. //for (int i = 0; i < _metalDevices.Count; i++)
  213. //{
  214. // CompactMembranMetalDevice hotMetalDevice = _metalDevices[i];
  215. // if (hotMetalDevice.IsAuto)
  216. // {
  217. // if (hotMetalDevice.SideAPowerSupplier == null)
  218. // {
  219. // LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "Side A PowerSupplier is null");
  220. // return false;
  221. // }
  222. // if (hotMetalDevice.SideBPowerSupplier == null)
  223. // {
  224. // LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "Side B PowerSupplier is null");
  225. // return false;
  226. // }
  227. // if (!hotMetalDevice.SideAPowerSupplier.IsConnected)
  228. // {
  229. // LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"Side A PowerSupplier {hotMetalDevice.SideAPowerSupplier.Name} is not connected");
  230. // return false;
  231. // }
  232. // if (!hotMetalDevice.SideBPowerSupplier.IsConnected)
  233. // {
  234. // LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"Side B PowerSupplier {hotMetalDevice.SideBPowerSupplier.Name} is not connected");
  235. // return false;
  236. // }
  237. // }
  238. //}
  239. return true;
  240. }
  241. /// <summary>
  242. /// Auto Metal reset linmot
  243. /// </summary>
  244. /// <returns></returns>
  245. private bool AutoMetalResetLinmot()
  246. {
  247. //for (int i = 0; i < _metalDevices.Count; i++)
  248. //{
  249. // CompactMembranMetalDevice hotMetalDevice = _metalDevices[i];
  250. // if (hotMetalDevice.OperationMode == AUTO)
  251. // {
  252. // bool result = hotMetalDevice.ResetLinmot();
  253. // if (!result)
  254. // {
  255. // LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "Reset linmot error");
  256. // return false;
  257. // }
  258. // }
  259. //}
  260. return true;
  261. }
  262. /// <summary>
  263. /// Auto Metal reset linmot
  264. /// </summary>
  265. /// <returns></returns>
  266. private bool CheckAutoMetalResetStatus()
  267. {
  268. //if (_reservoirDevice.OperationMode == MANUAL)
  269. //{
  270. // return true;
  271. //}
  272. //for (int i = 0; i < _metalDevices.Count; i++)
  273. //{
  274. // CompactMembranMetalDevice metalDevice = _metalDevices[i];
  275. // if (metalDevice.OperationMode == AUTO)
  276. // {
  277. // bool result = metalDevice.CheckLinmotRoutineEnd();
  278. // if (!result)
  279. // {
  280. // return false;
  281. // }
  282. // }
  283. //}
  284. return true;
  285. }
  286. /// <summary>
  287. /// Auto Metal reset linmot
  288. /// </summary>
  289. /// <returns></returns>
  290. private bool CheckAutoMetalResetStopStatus()
  291. {
  292. //if (_reservoirDevice.OperationMode == MANUAL)
  293. //{
  294. // return false;
  295. //}
  296. //for (int i = 0; i < _metalDevices.Count; i++)
  297. //{
  298. // CompactMembranMetalDevice hotMetalDevice = _metalDevices[i];
  299. // if (hotMetalDevice.OperationMode == AUTO)
  300. // {
  301. // bool result = hotMetalDevice.CheckLinmotRoutineError();
  302. // if (result)
  303. // {
  304. // return true;
  305. // }
  306. // }
  307. //}
  308. return false;
  309. }
  310. /// Metal WS Unclamp
  311. /// </summary>
  312. /// <returns></returns>
  313. private bool MetalsWHUnclampOn()
  314. {
  315. //for (int i = 0; i < _metalDevices.Count; i++)
  316. //{
  317. // CompactMembranMetalDevice hotMetalDevice = _metalDevices[i];
  318. // if (hotMetalDevice != null && !hotMetalDevice.IsDisable)
  319. // {
  320. // bool result = hotMetalDevice.WaferHolderUnclampOn("", null);
  321. // if (!result)
  322. // {
  323. // return false;
  324. // }
  325. // }
  326. //}
  327. //_reservoirDevice.InitializeCrossDose(true);
  328. return true;
  329. }
  330. /// <summary>
  331. /// 清除alarm界面相关的dataerror
  332. /// </summary>
  333. private bool ClearAlarmDataError()
  334. {
  335. //AlarmListManager.Instance.RemoveDataError(Module);
  336. //_dmReservoirDevice.ClearErrorLogSet(Module); //清除device里面的ErrorLogSet
  337. return true;
  338. }
  339. /// <summary>
  340. /// 启动
  341. /// </summary>
  342. /// <param name="objs"></param>
  343. /// <returns></returns>
  344. public RState Start(params object[] objs)
  345. {
  346. _caPumpOnRoutine = new CAPumpOnRoutine(Module);
  347. _anPumpOnRoutine = new ANPumpOnRoutine(Module);
  348. _dmReservoirDevice = DEVICE.GetDevice<DMReservoirDevice>(Module);
  349. //_dmReservoirDevice.ClearErrorLogSet(Module);
  350. _platingCellDevices = (PlatingCellDevice)objs[0];
  351. _temperatureController = (TemperatureController)objs[1];
  352. _recipe = _dmReservoirDevice.Recipe;
  353. _flowFaultHoldOffTime = SC.GetValue<int>($"PlatingCell.FlowFaultHoldOffTime");
  354. _cellFlowStartLowLimit = SC.GetValue<double>($"PlatingCell.CellFlowStartLowLimit");
  355. _anFlowStartLowLimit = SC.GetValue<double>($"PlatingCell.ANFlowStartLowLimit");
  356. if (!CheckPreCondition())
  357. {
  358. return RState.Failed;
  359. }
  360. return Runner.Start(Module, "Start D&M Initialize");
  361. }
  362. /// <summary>
  363. /// 检验前置条件
  364. /// </summary>
  365. /// <returns></returns>
  366. private bool CheckPreCondition()
  367. {
  368. if (_recipe == null)
  369. {
  370. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "recipe is null");
  371. return false;
  372. }
  373. if (!_temperatureController.IsConnected)
  374. {
  375. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "Temperature is not connected");
  376. return false;
  377. }
  378. if (!CheckFacility())
  379. {
  380. return false;
  381. }
  382. return true;
  383. }
  384. /// <summary>
  385. /// 检验facility
  386. /// </summary>
  387. /// <returns></returns>
  388. private bool CheckFacility()
  389. {
  390. SystemFacilities systemFacilities = DEVICE.GetDevice<SystemFacilities>("System.Facilities");
  391. if (systemFacilities == null)
  392. {
  393. if (systemFacilities.HouseChilledWaterEnable)
  394. {
  395. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "HouseChilledWaterEnable is false");
  396. return false;
  397. }
  398. if (systemFacilities.DIFillEnable)
  399. {
  400. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "DIFillEnable is false");
  401. return false;
  402. }
  403. if (systemFacilities.DIReplenEnable)
  404. {
  405. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "DIReplenEnable is false");
  406. return false;
  407. }
  408. }
  409. return true;
  410. }
  411. }
  412. }