DMReservoirInitializeRoutine.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  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
  162. /// </summary>
  163. /// <returns></returns>
  164. private bool EnableHED()
  165. {
  166. return _temperatureController.EnableOperation("", null);
  167. }
  168. /// <summary>
  169. /// 检验所有Metal处于Manual
  170. /// </summary>
  171. /// <returns></returns>
  172. private bool CheckAutoAndAllMetalAuto()
  173. {
  174. //if (_reservoirDevice.OperationMode != AUTO)
  175. //{
  176. // return false;
  177. //}
  178. //for (int i = 0; i < _metalDevices.Count; i++)
  179. //{
  180. // CompactMembranMetalDevice hotMetalDevice = _metalDevices[i];
  181. // if (hotMetalDevice.OperationMode != AUTO)
  182. // {
  183. // return false;
  184. // }
  185. //}
  186. return true;
  187. }
  188. /// <summary>
  189. /// 自动HED On
  190. /// </summary>
  191. /// <returns></returns>
  192. private bool AutoHedOn()
  193. {
  194. bool result = _dmReservoirDevice.ReservoirData.CaFlow < _cellFlowStartLowLimit;
  195. if (result)
  196. {
  197. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"CA Flow {_dmReservoirDevice.ReservoirData.CaFlow} is less than CellFlowStartLowLimit{_cellFlowStartLowLimit}");
  198. return false;
  199. }
  200. _autoHedDelay = _delay_2s;
  201. result = _temperatureController.EnableOperation("", null);
  202. if (!result)
  203. {
  204. return false;
  205. }
  206. result = _temperatureController.SetTargetTemperatureOperation("", new object[] { _recipe.TemperatureSetPoint });
  207. if (!result)
  208. {
  209. return false;
  210. }
  211. return true;
  212. }
  213. /// <summary>
  214. /// 检验Hed是否成功
  215. /// </summary>
  216. /// <returns></returns>
  217. private bool AutoHedSuccess()
  218. {
  219. if (_temperatureController.TemperatureData.ControlOperationModel == 0)
  220. {
  221. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "Temperature control is disable");
  222. return false;
  223. }
  224. if (Math.Abs(_recipe.TemperatureSetPoint - _temperatureController.TemperatureData.TargetTemperature) >= 0.1 * _recipe.TemperatureSetPoint)
  225. {
  226. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"recipe temperature {_recipe.TemperatureSetPoint} is not match temperature target point {_temperatureController.TemperatureData.TargetTemperature}");
  227. return false;
  228. }
  229. return true;
  230. }
  231. /// <summary>
  232. /// 检验Metal A/B PowerSupplier通信状态
  233. /// </summary>
  234. /// <returns></returns>
  235. private bool AutoMetalsPowerSupplierCommuncationStatus()
  236. {
  237. //for (int i = 0; i < _metalDevices.Count; i++)
  238. //{
  239. // CompactMembranMetalDevice hotMetalDevice = _metalDevices[i];
  240. // if (hotMetalDevice.IsAuto)
  241. // {
  242. // if (hotMetalDevice.SideAPowerSupplier == null)
  243. // {
  244. // LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "Side A PowerSupplier is null");
  245. // return false;
  246. // }
  247. // if (hotMetalDevice.SideBPowerSupplier == null)
  248. // {
  249. // LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "Side B PowerSupplier is null");
  250. // return false;
  251. // }
  252. // if (!hotMetalDevice.SideAPowerSupplier.IsConnected)
  253. // {
  254. // LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"Side A PowerSupplier {hotMetalDevice.SideAPowerSupplier.Name} is not connected");
  255. // return false;
  256. // }
  257. // if (!hotMetalDevice.SideBPowerSupplier.IsConnected)
  258. // {
  259. // LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"Side B PowerSupplier {hotMetalDevice.SideBPowerSupplier.Name} is not connected");
  260. // return false;
  261. // }
  262. // }
  263. //}
  264. return true;
  265. }
  266. /// <summary>
  267. /// Auto Metal reset linmot
  268. /// </summary>
  269. /// <returns></returns>
  270. private bool AutoMetalResetLinmot()
  271. {
  272. //for (int i = 0; i < _metalDevices.Count; i++)
  273. //{
  274. // CompactMembranMetalDevice hotMetalDevice = _metalDevices[i];
  275. // if (hotMetalDevice.OperationMode == AUTO)
  276. // {
  277. // bool result = hotMetalDevice.ResetLinmot();
  278. // if (!result)
  279. // {
  280. // LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "Reset linmot error");
  281. // return false;
  282. // }
  283. // }
  284. //}
  285. return true;
  286. }
  287. /// <summary>
  288. /// Auto Metal reset linmot
  289. /// </summary>
  290. /// <returns></returns>
  291. private bool CheckAutoMetalResetStatus()
  292. {
  293. //if (_reservoirDevice.OperationMode == MANUAL)
  294. //{
  295. // return true;
  296. //}
  297. //for (int i = 0; i < _metalDevices.Count; i++)
  298. //{
  299. // CompactMembranMetalDevice metalDevice = _metalDevices[i];
  300. // if (metalDevice.OperationMode == AUTO)
  301. // {
  302. // bool result = metalDevice.CheckLinmotRoutineEnd();
  303. // if (!result)
  304. // {
  305. // return false;
  306. // }
  307. // }
  308. //}
  309. return true;
  310. }
  311. /// <summary>
  312. /// Auto Metal reset linmot
  313. /// </summary>
  314. /// <returns></returns>
  315. private bool CheckAutoMetalResetStopStatus()
  316. {
  317. //if (_reservoirDevice.OperationMode == MANUAL)
  318. //{
  319. // return false;
  320. //}
  321. //for (int i = 0; i < _metalDevices.Count; i++)
  322. //{
  323. // CompactMembranMetalDevice hotMetalDevice = _metalDevices[i];
  324. // if (hotMetalDevice.OperationMode == AUTO)
  325. // {
  326. // bool result = hotMetalDevice.CheckLinmotRoutineError();
  327. // if (result)
  328. // {
  329. // return true;
  330. // }
  331. // }
  332. //}
  333. return false;
  334. }
  335. /// Metal WS Unclamp
  336. /// </summary>
  337. /// <returns></returns>
  338. private bool MetalsWHUnclampOn()
  339. {
  340. //for (int i = 0; i < _metalDevices.Count; i++)
  341. //{
  342. // CompactMembranMetalDevice hotMetalDevice = _metalDevices[i];
  343. // if (hotMetalDevice != null && !hotMetalDevice.IsDisable)
  344. // {
  345. // bool result = hotMetalDevice.WaferHolderUnclampOn("", null);
  346. // if (!result)
  347. // {
  348. // return false;
  349. // }
  350. // }
  351. //}
  352. //_reservoirDevice.InitializeCrossDose(true);
  353. return true;
  354. }
  355. /// <summary>
  356. /// 清除alarm界面相关的dataerror
  357. /// </summary>
  358. private bool ClearAlarmDataError()
  359. {
  360. //AlarmListManager.Instance.RemoveDataError(Module);
  361. //_dmReservoirDevice.ClearErrorLogSet(Module); //清除device里面的ErrorLogSet
  362. return true;
  363. }
  364. /// <summary>
  365. /// 启动
  366. /// </summary>
  367. /// <param name="objs"></param>
  368. /// <returns></returns>
  369. public RState Start(params object[] objs)
  370. {
  371. _caPumpOnRoutine = new CAPumpOnRoutine(Module);
  372. _anPumpOnRoutine = new ANPumpOnRoutine(Module);
  373. _dmReservoirDevice = DEVICE.GetDevice<DMReservoirDevice>(Module);
  374. //_dmReservoirDevice.ClearErrorLogSet(Module);
  375. _platingCellDevices = (PlatingCellDevice)objs[0];
  376. _temperatureController = (TemperatureController)objs[1];
  377. _recipe = _dmReservoirDevice.Recipe;
  378. _flowFaultHoldOffTime = SC.GetValue<int>($"PlatingCell.FlowFaultHoldOffTime");
  379. _cellFlowStartLowLimit = SC.GetValue<double>($"PlatingCell.CellFlowStartLowLimit");
  380. _anFlowStartLowLimit = SC.GetValue<double>($"PlatingCell.ANFlowStartLowLimit");
  381. if (!CheckPreCondition())
  382. {
  383. return RState.Failed;
  384. }
  385. return Runner.Start(Module, "Start D&M Initialize");
  386. }
  387. /// <summary>
  388. /// 检验前置条件
  389. /// </summary>
  390. /// <returns></returns>
  391. private bool CheckPreCondition()
  392. {
  393. if (_recipe == null)
  394. {
  395. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "recipe is null");
  396. return false;
  397. }
  398. if (!_temperatureController.IsConnected)
  399. {
  400. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "Temperature is not connected");
  401. return false;
  402. }
  403. if (!CheckFacility())
  404. {
  405. return false;
  406. }
  407. return true;
  408. }
  409. /// <summary>
  410. /// 检验facility
  411. /// </summary>
  412. /// <returns></returns>
  413. private bool CheckFacility()
  414. {
  415. SystemFacilities systemFacilities = DEVICE.GetDevice<SystemFacilities>("System.Facilities");
  416. if (systemFacilities != null)
  417. {
  418. if (!systemFacilities.HouseChilledWaterEnable)
  419. {
  420. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "HouseChilledWaterEnable is false");
  421. return false;
  422. }
  423. if (!systemFacilities.DIFillEnable)
  424. {
  425. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "DIFillEnable is false");
  426. return false;
  427. }
  428. if (!systemFacilities.DIReplenEnable)
  429. {
  430. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "DIReplenEnable is false");
  431. return false;
  432. }
  433. }
  434. else
  435. {
  436. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "DIReplenEnable is false");
  437. return false;
  438. }
  439. return true;
  440. }
  441. }
  442. }