VpwExtendCleanRoutine.cs 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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. else
  116. {
  117. _vpwCellDevice.FlowDripOff();
  118. }
  119. if (_recipe.ExtendCleanLargeEnable)
  120. {
  121. count += _vpwCellDevice.FlowLargeOn() ? 1 : 0;
  122. enableCount++;
  123. }
  124. else
  125. {
  126. _vpwCellDevice.FlowLargeOff();
  127. }
  128. if (_recipe.ExtendCleanSmallEnable)
  129. {
  130. count += _vpwCellDevice.FlowSmallOn() ? 1 : 0;
  131. enableCount++;
  132. }
  133. else
  134. {
  135. _vpwCellDevice.FlowSmallOff();
  136. }
  137. bool result = count == enableCount;
  138. if (!result)
  139. {
  140. NotifyError(eEvent.ERR_VPW, "open cell valve failed", 0);
  141. }
  142. foreach (var item in _recipe.ExtendCleanRinseStep)
  143. {
  144. _totalMicrosecond += item.DurationSeconds * 1000;
  145. }
  146. _startStepTime = DateTime.Now;
  147. _stepIndex = 0;
  148. return result;
  149. }
  150. /// <summary>
  151. /// 检验步骤是否完成
  152. /// </summary>
  153. /// <returns></returns>
  154. private bool CheckStepComplete()
  155. {
  156. _mainDevice.CellFlow = _vpwCellDevice.CommonData.DiwFlow;
  157. if (_stepIndex >= _recipe.ExtendCleanRinseStep.Count)
  158. {
  159. LOG.WriteLog(eEvent.INFO_VPW, Module, $"step {_stepIndex} is over step count {_recipe.ExtendCleanRinseStep.Count}");
  160. return true;
  161. }
  162. int length = _recipe.ExtendCleanRinseStep[_stepIndex].DurationSeconds;
  163. if (DateTime.Now.Subtract(_startStepTime).TotalSeconds >= length)
  164. {
  165. _stepIndex++;
  166. _startStepTime = DateTime.Now;
  167. if (_stepIndex >= _recipe.ExtendCleanRinseStep.Count)
  168. {
  169. LOG.WriteLog(eEvent.INFO_VPW, Module, $"step {_stepIndex} is over step count {_recipe.ExtendCleanRinseStep.Count}");
  170. return true;
  171. }
  172. bool result = _vpwCellDevice.ChangeRotationSpeed(_recipe.ExtendCleanRinseStep[_stepIndex].RotationSpeed*6);
  173. if (result)
  174. {
  175. LOG.WriteLog(eEvent.INFO_VPW, Module, $"step {_stepIndex} complete");
  176. }
  177. return result;
  178. }
  179. int firstDelay = SC.GetValue<int>($"{Module}.FlowCheckDelay") * 1000;
  180. if (DateTime.Now.Subtract(_startStepTime).TotalMilliseconds >= firstDelay)
  181. {
  182. bool abnormal = CheckDisable();
  183. if (abnormal)
  184. {
  185. return false;
  186. }
  187. }
  188. return false;
  189. }
  190. /// <summary>
  191. /// 检验数据
  192. /// </summary>
  193. /// <returns></returns>
  194. private bool CheckDisable()
  195. {
  196. double flow = _vpwCellDevice.CommonData.DiwFlow;
  197. double lowError = _recipe.ExtendCleanFlowSetPoint * (1 - (double)_recipe.ExtendCleanFlowErrorPercent / 100);
  198. double upError = _recipe.ExtendCleanFlowSetPoint * (1 + (double)_recipe.ExtendCleanFlowErrorPercent / 100);
  199. double lowWarn = _recipe.ExtendCleanFlowSetPoint * (1 - (double)_recipe.ExtendCleanFlowWarningPercent / 100);
  200. double upWarn = _recipe.ExtendCleanFlowSetPoint * (1 + (double)_recipe.ExtendCleanFlowWarningPercent / 100);
  201. if (flow<lowError)
  202. {
  203. NotifyError(eEvent.ERR_VPW, $"{Module} cell flow {flow} is less than {lowError} ", 0);
  204. Abort();
  205. return true;
  206. }
  207. if (flow > upError)
  208. {
  209. NotifyError(eEvent.ERR_VPW, $"{Module} cell flow {flow} is up than {upError} ", 0);
  210. Abort();
  211. return true;
  212. }
  213. if ((flow <= upError && flow >= upWarn) || (flow >= lowError && flow <= lowWarn))
  214. {
  215. string str = $"{Module} cell flow {flow} is in warning";
  216. if (AlarmListManager.Instance.AddWarn(Module, $"{Module} cell flow", str))
  217. {
  218. LOG.WriteLog(eEvent.WARN_VPW, Module, str);
  219. }
  220. }
  221. bool isSimulatorMode = SC.GetValue<bool>("System.IsSimulatorMode");
  222. if (!isSimulatorMode)
  223. {
  224. if (!_vpwCellDevice.CheckRotationRunning())
  225. {
  226. NotifyError(eEvent.ERR_VPW, $"{Module} rotation is stopped", 0);
  227. Abort();
  228. return true;
  229. }
  230. }
  231. return false;
  232. }
  233. /// <summary>
  234. /// 启动
  235. /// </summary>
  236. /// <param name="objs"></param>
  237. /// <returns></returns>
  238. public RState Start(params object[] objs)
  239. {
  240. _recipe=(VpwRecipe)objs[0];
  241. _vpwCellDevice = DEVICE.GetDevice<VpwCellDevice>(Module);
  242. _mainDevice = DEVICE.GetDevice<VpwMainDevice>(ModuleName.VPWMain1.ToString());
  243. _totalMicrosecond = 0;
  244. _stepIndex = 0;
  245. return Runner.Start(Module, $"{Module} extend clean");
  246. }
  247. /// <summary>
  248. /// 重试
  249. /// </summary>
  250. /// <param name="step"></param>
  251. public RState Retry(int step)
  252. {
  253. if (_recipe == null)
  254. {
  255. NotifyError(eEvent.ERR_VPW, "recipe is null", -1);
  256. return RState.Failed;
  257. }
  258. List<Enum> preStepIds = new List<Enum>();
  259. return Runner.Retry(PrepareStep.OpenDrainValve, preStepIds, Module, "Extend clean Retry");
  260. }
  261. }
  262. }