VpwExtendCleanRoutine.cs 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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 Aitex.Core.Util;
  6. using MECF.Framework.Common.Alarm;
  7. using MECF.Framework.Common.Equipment;
  8. using MECF.Framework.Common.RecipeCenter;
  9. using MECF.Framework.Common.Routine;
  10. using MECF.Framework.Common.SubstrateTrackings;
  11. using PunkHPX8_Core;
  12. using PunkHPX8_RT.Devices.AXIS;
  13. using PunkHPX8_RT.Devices.VpwCell;
  14. using PunkHPX8_RT.Devices.VpwMain;
  15. using PunkHPX8_RT.Modules.VpwMain;
  16. using System;
  17. using System.Collections.Generic;
  18. using System.Diagnostics;
  19. using System.Linq;
  20. using System.Text;
  21. using System.Threading.Tasks;
  22. namespace PunkHPX8_RT.Modules.VpwCell
  23. {
  24. public class VpwExtendCleanRoutine : RoutineBase, IRoutine
  25. {
  26. private enum PrepareStep
  27. {
  28. OpenDrainValve,
  29. OpenCellValve,
  30. LoopStart,
  31. LoopRun,
  32. LoopEnd,
  33. End
  34. }
  35. #region 内部变量
  36. /// <summary>
  37. /// recipe
  38. /// </summary>
  39. private VpwRecipe _recipe;
  40. /// <summary>
  41. /// 设备
  42. /// </summary>
  43. private VpwCellDevice _vpwCellDevice;
  44. /// <summary>
  45. /// Main设备
  46. /// </summary>
  47. private VpwMainDevice _mainDevice;
  48. /// <summary>
  49. /// 总时长
  50. /// </summary>
  51. private int _totalMicrosecond = 0;
  52. /// <summary>
  53. /// 步骤
  54. /// </summary>
  55. private int _stepIndex = 0;
  56. /// <summary>
  57. /// 启动步骤时间
  58. /// </summary>
  59. private DateTime _startStepTime = DateTime.Now;
  60. #endregion
  61. /// <summary>
  62. /// 构造函数
  63. /// </summary>
  64. /// <param name="module"></param>
  65. public VpwExtendCleanRoutine(string module) : base(module)
  66. {
  67. }
  68. /// <summary>
  69. /// 中止
  70. /// </summary>
  71. public void Abort()
  72. {
  73. Runner.Stop("Manual abort");
  74. }
  75. /// <summary>
  76. /// 监控
  77. /// </summary>
  78. /// <returns></returns>
  79. public RState Monitor()
  80. {
  81. Runner.Run(PrepareStep.OpenDrainValve, OpenDrainValve, _delay_1ms)
  82. .Run(PrepareStep.OpenCellValve,OpenCellValve,_delay_1ms)
  83. .LoopStart(PrepareStep.LoopStart,"Loop Step",_recipe.VentRinseStep.Count,NullFun,_delay_1ms)
  84. .LoopRunWithStopStatus(PrepareStep.LoopRun, CheckStepComplete, () => { return false; }, _totalMicrosecond + 60 * 1000)//总时长再延迟1分种
  85. .LoopEnd(PrepareStep.LoopEnd,NullFun,_delay_1ms)
  86. .End(PrepareStep.End,NullFun,_delay_1ms);
  87. return Runner.Status;
  88. }
  89. /// <summary>
  90. /// open vent valve
  91. /// </summary>
  92. /// <returns></returns>
  93. private bool OpenDrainValve()
  94. {
  95. bool result = _vpwCellDevice.DrainValveOn();
  96. if (!result)
  97. {
  98. NotifyError(eEvent.ERR_VPW, "open drain valve failed", 0);
  99. }
  100. return result;
  101. }
  102. /// <summary>
  103. /// 打开相应的cell valve
  104. /// </summary>
  105. /// <returns></returns>
  106. private bool OpenCellValve()
  107. {
  108. int count = 0;
  109. int enableCount = 0;
  110. if (_recipe.ExtendCleanDripEnable)
  111. {
  112. count += _vpwCellDevice.FlowDripOn()?1:0;
  113. enableCount++;
  114. }
  115. if (_recipe.ExtendCleanLargeEnable)
  116. {
  117. count += _vpwCellDevice.FlowLargeOn() ? 1 : 0;
  118. enableCount++;
  119. }
  120. if (_recipe.ExtendCleanSmallEnable)
  121. {
  122. count += _vpwCellDevice.FlowSmallOn() ? 1 : 0;
  123. enableCount++;
  124. }
  125. bool result= count == enableCount;
  126. if (!result)
  127. {
  128. NotifyError(eEvent.ERR_VPW, "open cell valve failed", 0);
  129. }
  130. foreach (var item in _recipe.ExtendCleanRinseStep)
  131. {
  132. _totalMicrosecond += item.DurationSeconds * 1000;
  133. }
  134. _startStepTime = DateTime.Now;
  135. _stepIndex = 0;
  136. return result;
  137. }
  138. /// <summary>
  139. /// 检验步骤是否完成
  140. /// </summary>
  141. /// <returns></returns>
  142. private bool CheckStepComplete()
  143. {
  144. _mainDevice.CellFlow = _vpwCellDevice.CommonData.DiwFlow;
  145. if (_stepIndex >= _recipe.ExtendCleanRinseStep.Count)
  146. {
  147. LOG.WriteLog(eEvent.INFO_VPW, Module, $"step {_stepIndex} is over step count {_recipe.ExtendCleanRinseStep.Count}");
  148. return true;
  149. }
  150. int length = _recipe.ExtendCleanRinseStep[_stepIndex].DurationSeconds;
  151. if (DateTime.Now.Subtract(_startStepTime).TotalSeconds >= length)
  152. {
  153. _stepIndex++;
  154. _startStepTime = DateTime.Now;
  155. if (_stepIndex >= _recipe.ExtendCleanRinseStep.Count)
  156. {
  157. LOG.WriteLog(eEvent.INFO_VPW, Module, $"step {_stepIndex} is over step count {_recipe.ExtendCleanRinseStep.Count}");
  158. return true;
  159. }
  160. bool result = _vpwCellDevice.ChangeRotationSpeed(_recipe.ExtendCleanRinseStep[_stepIndex].RotationSpeed*6);
  161. if (result)
  162. {
  163. LOG.WriteLog(eEvent.INFO_VPW, Module, $"step {_stepIndex} complete");
  164. }
  165. return result;
  166. }
  167. int firstDelay = SC.GetValue<int>($"{Module}.FlowCheckDelay") * 1000;
  168. if (DateTime.Now.Subtract(_startStepTime).TotalMilliseconds >= firstDelay)
  169. {
  170. bool abnormal = CheckDisable();
  171. if (abnormal)
  172. {
  173. return false;
  174. }
  175. }
  176. return false;
  177. }
  178. /// <summary>
  179. /// 检验数据
  180. /// </summary>
  181. /// <returns></returns>
  182. private bool CheckDisable()
  183. {
  184. double flow = _vpwCellDevice.CommonData.DiwFlow;
  185. double lowError = _recipe.ExtendCleanFlowSetPoint * (1 - (double)_recipe.ExtendCleanFlowErrorPercent / 100);
  186. double upError = _recipe.ExtendCleanFlowSetPoint * (1 + (double)_recipe.ExtendCleanFlowErrorPercent / 100);
  187. double lowWarn = _recipe.ExtendCleanFlowSetPoint * (1 - (double)_recipe.ExtendCleanFlowWarningPercent / 100);
  188. double upWarn = _recipe.ExtendCleanFlowSetPoint * (1 + (double)_recipe.ExtendCleanFlowWarningPercent / 100);
  189. if (flow<lowError)
  190. {
  191. NotifyError(eEvent.ERR_VPW, $"{Module} cell flow {flow} is less than {lowError} ", 0);
  192. Abort();
  193. return true;
  194. }
  195. if (flow > upError)
  196. {
  197. NotifyError(eEvent.ERR_VPW, $"{Module} cell flow {flow} is up than {upError} ", 0);
  198. Abort();
  199. return true;
  200. }
  201. if ((flow <= upError && flow >= upWarn) || (flow >= lowError && flow <= lowWarn))
  202. {
  203. string str = $"{Module} cell flow {flow} is in warning";
  204. if (AlarmListManager.Instance.AddWarn(Module, $"{Module} cell flow", str))
  205. {
  206. LOG.WriteLog(eEvent.WARN_VPW, Module, str);
  207. }
  208. }
  209. bool isSimulatorMode = SC.GetValue<bool>("System.IsSimulatorMode");
  210. if (!isSimulatorMode)
  211. {
  212. if (!_vpwCellDevice.CheckRotationRunning())
  213. {
  214. NotifyError(eEvent.ERR_VPW, $"{Module} rotation is stopped", 0);
  215. Abort();
  216. return true;
  217. }
  218. }
  219. return false;
  220. }
  221. /// <summary>
  222. /// 启动
  223. /// </summary>
  224. /// <param name="objs"></param>
  225. /// <returns></returns>
  226. public RState Start(params object[] objs)
  227. {
  228. _recipe=(VpwRecipe)objs[0];
  229. _vpwCellDevice = DEVICE.GetDevice<VpwCellDevice>(Module);
  230. _mainDevice = DEVICE.GetDevice<VpwMainDevice>(ModuleName.VPWMain1.ToString());
  231. _totalMicrosecond = 0;
  232. _stepIndex = 0;
  233. return Runner.Start(Module, $"{Module} extend clean");
  234. }
  235. /// <summary>
  236. /// 重试
  237. /// </summary>
  238. /// <param name="step"></param>
  239. public RState Retry(int step)
  240. {
  241. if (_recipe == null)
  242. {
  243. NotifyError(eEvent.ERR_VPW, "recipe is null", -1);
  244. return RState.Failed;
  245. }
  246. List<Enum> preStepIds = new List<Enum>();
  247. return Runner.Retry(PrepareStep.OpenDrainValve, preStepIds, Module, "Extend clean Retry");
  248. }
  249. }
  250. }