CompactEmbranceInitializeRoutine.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. using Aitex.Core.RT.Routine;
  2. using MECF.Framework.Common.Routine;
  3. using MECF.Framework.Common.Utilities;
  4. using CyberX8_Core;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using CyberX8_RT.Devices.Reservoir;
  11. using Aitex.Core.RT.Device;
  12. using MECF.Framework.Common.RecipeCenter;
  13. using Aitex.Core.RT.Log;
  14. using CyberX8_RT.Devices.PowerSupplier;
  15. using CyberX8_RT.Devices.Temperature;
  16. using CyberX8_RT.Devices.Metal;
  17. using Aitex.Core.RT.SCCore;
  18. using CyberX8_RT.Devices.Facilities;
  19. namespace CyberX8_RT.Modules.Reservoir
  20. {
  21. public class CompactEmbranceInitializeRoutine : RoutineBase, IRoutine
  22. {
  23. private enum InitializeStep
  24. {
  25. AutoDiReplen,
  26. CAPump,
  27. CAPumpWait,
  28. ANPump,
  29. ANPumpWait,
  30. ManualCellDisableHED,
  31. AutoCellAutoEnableHED,
  32. AutoCellAutoEnableHEDDelay,
  33. AutoCellAutoEnableHEDCheck,
  34. AutoCellAutoCheckPowerSupplier,
  35. AutoCellAutoLinmotReset,
  36. AutoCellAutoLinmotResetCheck,
  37. CellWSUnclamp,
  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. CompactMembranReservoirDevice _reservoirDevice;
  49. private ResRecipe _recipe;
  50. private List<CompactMembranMetalDevice> _metalDevices = new List<CompactMembranMetalDevice>();
  51. private TemperatureController _temperatureController;
  52. private double _hedFlowLowLimit;
  53. private int _autoHedDelay = 0;
  54. #endregion
  55. /// <summary>
  56. /// 构造函数
  57. /// </summary>
  58. /// <param name="module"></param>
  59. public CompactEmbranceInitializeRoutine(string module) : base(module)
  60. {
  61. }
  62. /// <summary>
  63. /// 中止
  64. /// </summary>
  65. public void Abort()
  66. {
  67. _caPumpOnRoutine.Abort();
  68. _anPumpOnRoutine.Abort();
  69. }
  70. /// <summary>
  71. /// 监控
  72. /// </summary>
  73. /// <returns></returns>
  74. public RState Monitor()
  75. {
  76. Runner.RunIf(InitializeStep.AutoDiReplen,_recipe.DIReplenEnable||_recipe.ANDIReplenEnable,CheckFacilitiesDiReplenStatus,_delay_1ms)
  77. .Run(InitializeStep.CAPump, () => { return _caPumpOnRoutine.Start() == RState.Running; }, _delay_1s)
  78. .WaitWithStopCondition(InitializeStep.CAPumpWait, () => CommonFunction.CheckRoutineEndState(_caPumpOnRoutine), () => CommonFunction.CheckRoutineStopState(_caPumpOnRoutine))
  79. .Run(InitializeStep.ANPump, () => { return _anPumpOnRoutine.Start() == RState.Running; }, _delay_1ms)
  80. .WaitWithStopCondition(InitializeStep.ANPumpWait, () => CommonFunction.CheckRoutineEndState(_anPumpOnRoutine), () => CommonFunction.CheckRoutineStopState(_anPumpOnRoutine))
  81. //Manual cell Bypass同时Enable HED
  82. .Run(InitializeStep.AutoCellAutoEnableHED, AutoHedOn, _delay_1ms)
  83. .Delay(InitializeStep.AutoCellAutoEnableHEDDelay, _autoHedDelay)
  84. .Run(InitializeStep.AutoCellAutoEnableHEDCheck, AutoHedSuccess, _delay_1ms)
  85. //检验PowerSupplier通信
  86. .Run(InitializeStep.AutoCellAutoCheckPowerSupplier, AutoMetalsPowerSupplierCommuncationStatus, _delay_1ms)
  87. //Cell Linmot Reset
  88. .RunIf(InitializeStep.AutoCellAutoLinmotReset, _reservoirDevice.OperationMode == AUTO, AutoMetalResetLinmot, _delay_1ms)
  89. .WaitWithStopCondition(InitializeStep.AutoCellAutoLinmotResetCheck, CheckAutoMetalResetStatus, CheckAutoMetalResetStopStatus)
  90. //Cell Unclamp
  91. .Run(InitializeStep.CellWSUnclamp, MetalsWHUnclampOn, _delay_1ms)
  92. .End(InitializeStep.End, NullFun, _delay_1ms);
  93. return Runner.Status;
  94. }
  95. /// <summary>
  96. /// 检验总Di有没有开
  97. /// </summary>
  98. /// <returns></returns>
  99. private bool CheckFacilitiesDiReplenStatus()
  100. {
  101. SystemFacilities systemFacilities = DEVICE.GetDevice<SystemFacilities>("System.Facilities");
  102. if (systemFacilities != null)
  103. {
  104. bool result= systemFacilities.DIReplenEnable;
  105. if (!result)
  106. {
  107. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "Facilities DiReplen is disable");
  108. }
  109. return result;
  110. }
  111. return false;
  112. }
  113. /// <summary>
  114. /// 启用HED
  115. /// </summary>
  116. /// <returns></returns>
  117. private bool EnableHED()
  118. {
  119. return _temperatureController.EnableOperation("", null);
  120. }
  121. /// <summary>
  122. /// 检验所有Metal处于Manual
  123. /// </summary>
  124. /// <returns></returns>
  125. private bool CheckAutoAndAllMetalAuto()
  126. {
  127. if (_reservoirDevice.OperationMode != AUTO)
  128. {
  129. return false;
  130. }
  131. for (int i = 0; i < _metalDevices.Count; i++)
  132. {
  133. CompactMembranMetalDevice hotMetalDevice = _metalDevices[i];
  134. if (hotMetalDevice.OperationMode != AUTO)
  135. {
  136. return false;
  137. }
  138. }
  139. return true;
  140. }
  141. /// <summary>
  142. /// 自动HED On
  143. /// </summary>
  144. /// <returns></returns>
  145. private bool AutoHedOn()
  146. {
  147. double hedFlow = _reservoirDevice.ReservoirData.CAHedFlow;
  148. bool result = hedFlow > _hedFlowLowLimit;
  149. if (!result)
  150. {
  151. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"HED Flow {hedFlow} is less than {_hedFlowLowLimit}");
  152. return false;
  153. }
  154. _autoHedDelay = _delay_2s;
  155. _temperatureController.EnableOperation("", null);
  156. _temperatureController.SetTargetTemperatureOperation("", new object[] { _recipe.TemperatureSetPoint });
  157. return true;
  158. }
  159. /// <summary>
  160. /// 检验Hed是否成功
  161. /// </summary>
  162. /// <returns></returns>
  163. private bool AutoHedSuccess()
  164. {
  165. if (_temperatureController.TemperatureData.ControlOperationModel == 0)
  166. {
  167. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "Temperature control is disable");
  168. return false;
  169. }
  170. if (Math.Abs(_recipe.TemperatureSetPoint - _temperatureController.TemperatureData.TargetTemperature) >= 0.1 * _recipe.TemperatureSetPoint)
  171. {
  172. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"recipe temperature {_recipe.TemperatureSetPoint} is not match temperature target point {_temperatureController.TemperatureData.TargetTemperature}");
  173. return false;
  174. }
  175. return true;
  176. }
  177. /// <summary>
  178. /// 检验Metal A/B PowerSupplier通信状态
  179. /// </summary>
  180. /// <returns></returns>
  181. private bool AutoMetalsPowerSupplierCommuncationStatus()
  182. {
  183. for (int i = 0; i < _metalDevices.Count; i++)
  184. {
  185. CompactMembranMetalDevice hotMetalDevice = _metalDevices[i];
  186. if (hotMetalDevice.IsAuto)
  187. {
  188. if (hotMetalDevice.SideAPowerSupplier == null)
  189. {
  190. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "Side A PowerSupplier is null");
  191. return false;
  192. }
  193. if (hotMetalDevice.SideBPowerSupplier == null)
  194. {
  195. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "Side B PowerSupplier is null");
  196. return false;
  197. }
  198. if (!hotMetalDevice.SideAPowerSupplier.IsConnected)
  199. {
  200. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"Side A PowerSupplier {hotMetalDevice.SideAPowerSupplier.Name} is not connected");
  201. return false;
  202. }
  203. if (!hotMetalDevice.SideBPowerSupplier.IsConnected)
  204. {
  205. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"Side B PowerSupplier {hotMetalDevice.SideBPowerSupplier.Name} is not connected");
  206. return false;
  207. }
  208. }
  209. }
  210. return true;
  211. }
  212. /// <summary>
  213. /// Auto Metal reset linmot
  214. /// </summary>
  215. /// <returns></returns>
  216. private bool AutoMetalResetLinmot()
  217. {
  218. for (int i = 0; i < _metalDevices.Count; i++)
  219. {
  220. CompactMembranMetalDevice hotMetalDevice = _metalDevices[i];
  221. if (hotMetalDevice.OperationMode == AUTO)
  222. {
  223. bool result = hotMetalDevice.ResetLinmot();
  224. if (!result)
  225. {
  226. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "Reset linmot error");
  227. return false;
  228. }
  229. }
  230. }
  231. return true;
  232. }
  233. /// <summary>
  234. /// Auto Metal reset linmot
  235. /// </summary>
  236. /// <returns></returns>
  237. private bool CheckAutoMetalResetStatus()
  238. {
  239. if (_reservoirDevice.OperationMode == MANUAL)
  240. {
  241. return true;
  242. }
  243. for (int i = 0; i < _metalDevices.Count; i++)
  244. {
  245. CompactMembranMetalDevice metalDevice = _metalDevices[i];
  246. if (metalDevice.OperationMode == AUTO)
  247. {
  248. bool result = metalDevice.CheckLinmotRoutineEnd();
  249. if (!result)
  250. {
  251. return false;
  252. }
  253. }
  254. }
  255. return true;
  256. }
  257. /// <summary>
  258. /// Auto Metal reset linmot
  259. /// </summary>
  260. /// <returns></returns>
  261. private bool CheckAutoMetalResetStopStatus()
  262. {
  263. if (_reservoirDevice.OperationMode == MANUAL)
  264. {
  265. return false;
  266. }
  267. for (int i = 0; i < _metalDevices.Count; i++)
  268. {
  269. CompactMembranMetalDevice hotMetalDevice = _metalDevices[i];
  270. if (hotMetalDevice.OperationMode == AUTO)
  271. {
  272. bool result = hotMetalDevice.CheckLinmotRoutineError();
  273. if (result)
  274. {
  275. return true;
  276. }
  277. }
  278. }
  279. return false;
  280. }
  281. /// Metal WS Unclamp
  282. /// </summary>
  283. /// <returns></returns>
  284. private bool MetalsWHUnclampOn()
  285. {
  286. for (int i = 0; i < _metalDevices.Count; i++)
  287. {
  288. CompactMembranMetalDevice hotMetalDevice = _metalDevices[i];
  289. if (hotMetalDevice != null && !hotMetalDevice.IsDisable)
  290. {
  291. bool result = hotMetalDevice.WaferHolderUnclampOn("", null);
  292. if (!result)
  293. {
  294. return false;
  295. }
  296. }
  297. }
  298. _reservoirDevice.InitializeCrossDose(true);
  299. return true;
  300. }
  301. /// <summary>
  302. /// 启动
  303. /// </summary>
  304. /// <param name="objs"></param>
  305. /// <returns></returns>
  306. public RState Start(params object[] objs)
  307. {
  308. _caPumpOnRoutine = new CAPumpOnRoutine(Module);
  309. _anPumpOnRoutine = new ANPumpOnRoutine(Module);
  310. _reservoirDevice = DEVICE.GetDevice<CompactMembranReservoirDevice>(Module);
  311. List<MetalCellDevice> lstDevice = (List<MetalCellDevice>)objs[0];
  312. _metalDevices.Clear();
  313. for (int i = 0; i < lstDevice.Count; i++)
  314. {
  315. _metalDevices.Add((CompactMembranMetalDevice)lstDevice[i]);
  316. }
  317. _temperatureController = (TemperatureController)objs[1];
  318. _recipe = _reservoirDevice.Recipe;
  319. _autoHedDelay = 0;
  320. _hedFlowLowLimit = SC.GetValue<double>($"Reservoir.{Module}.HEDFlowLowLimit");
  321. if (!CheckPreCondition())
  322. {
  323. return RState.Failed;
  324. }
  325. _reservoirDevice.InitializeCrossDose(false);
  326. return Runner.Start(Module, "Start C&M Initialize");
  327. }
  328. /// <summary>
  329. /// 检验前置条件
  330. /// </summary>
  331. /// <returns></returns>
  332. private bool CheckPreCondition()
  333. {
  334. if (_recipe == null)
  335. {
  336. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "recipe is null");
  337. return false;
  338. }
  339. if (!_temperatureController.IsConnected)
  340. {
  341. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "Temperature is not connected");
  342. return false;
  343. }
  344. return true;
  345. }
  346. }
  347. }