VpwSpinOffRoutine.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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 VpwSpinOffRoutine : RoutineBase, IRoutine
  25. {
  26. private enum PrepareStep
  27. {
  28. CloseCellValve,
  29. LoopStart,
  30. LoopRun,
  31. LoopEnd,
  32. End
  33. }
  34. #region 内部变量
  35. /// <summary>
  36. /// recipe
  37. /// </summary>
  38. private VpwRecipe _recipe;
  39. /// <summary>
  40. /// 设备
  41. /// </summary>
  42. private VpwCellDevice _vpwCellDevice;
  43. /// <summary>
  44. /// Main设备
  45. /// </summary>
  46. private VpwMainDevice _mainDevice;
  47. /// <summary>
  48. /// Lid Release Pressure
  49. /// </summary>
  50. private int _lidReleasePressure = 730;
  51. /// <summary>
  52. /// Lid Release Pressure
  53. /// </summary>
  54. private int _lidReleasePressureTimeout = 10000;
  55. /// <summary>
  56. /// 总时长
  57. /// </summary>
  58. private int _totalMicrosecond = 0;
  59. /// <summary>
  60. /// 步骤
  61. /// </summary>
  62. private int _stepIndex = 0;
  63. /// <summary>
  64. /// 启动步骤时间
  65. /// </summary>
  66. private DateTime _startStepTime = DateTime.Now;
  67. #endregion
  68. /// <summary>
  69. /// 构造函数
  70. /// </summary>
  71. /// <param name="module"></param>
  72. public VpwSpinOffRoutine(string module) : base(module)
  73. {
  74. }
  75. /// <summary>
  76. /// 中止
  77. /// </summary>
  78. public void Abort()
  79. {
  80. Runner.Stop("Manual abort");
  81. }
  82. /// <summary>
  83. /// 监控
  84. /// </summary>
  85. /// <returns></returns>
  86. public RState Monitor()
  87. {
  88. Runner.Run(PrepareStep.CloseCellValve,CloseCellValve,_delay_1ms)
  89. .LoopStart(PrepareStep.LoopStart,"Loop Step",1,NullFun,_delay_1ms)
  90. .LoopRunWithStopStatus(PrepareStep.LoopRun, CheckStepComplete, () => { return false; }, _totalMicrosecond + 60 * 1000)//总时长再延迟1分种
  91. .LoopEnd(PrepareStep.LoopEnd,NullFun,_delay_1ms)
  92. .End(PrepareStep.End,NullFun,_delay_1ms);
  93. return Runner.Status;
  94. }
  95. /// <summary>
  96. /// 打开相应的cell valve
  97. /// </summary>
  98. /// <returns></returns>
  99. private bool CloseCellValve()
  100. {
  101. int count = 0;
  102. count += _vpwCellDevice.FlowDripOff()?1:0;
  103. count += _vpwCellDevice.FlowLargeOff() ? 1 : 0;
  104. count += _vpwCellDevice.FlowSmallOff() ? 1 : 0;
  105. bool result= count == 3;
  106. if (!result)
  107. {
  108. NotifyError(eEvent.ERR_VPW, "close cell valve failed", 0);
  109. }
  110. _totalMicrosecond += _recipe.SpinTime * 1000;
  111. _startStepTime = DateTime.Now;
  112. _stepIndex = 0;
  113. return result;
  114. }
  115. /// <summary>
  116. /// 检验步骤是否完成
  117. /// </summary>
  118. /// <returns></returns>
  119. private bool CheckStepComplete()
  120. {
  121. _mainDevice.CellFlow = _vpwCellDevice.CommonData.DiwFlow;
  122. if (_stepIndex >= 1)
  123. {
  124. LOG.WriteLog(eEvent.INFO_VPW, Module, $"step {_stepIndex} is over step count 1");
  125. return true;
  126. }
  127. int length = _recipe.SpinTime;
  128. if (DateTime.Now.Subtract(_startStepTime).TotalSeconds >= length)
  129. {
  130. _stepIndex++;
  131. _startStepTime = DateTime.Now;
  132. if (_stepIndex >= 1)
  133. {
  134. LOG.WriteLog(eEvent.INFO_VPW, Module, $"step {_stepIndex} is over step count 1");
  135. return true;
  136. }
  137. bool result = _vpwCellDevice.ChangeRotationSpeed(_recipe.SpinSpeed*6);
  138. if (result)
  139. {
  140. LOG.WriteLog(eEvent.INFO_VPW, Module, $"step {_stepIndex} complete");
  141. }
  142. return result;
  143. }
  144. int firstDelay = SC.GetValue<int>($"{Module}.FlowCheckDelay") * 1000;
  145. if (DateTime.Now.Subtract(_startStepTime).TotalMilliseconds >= firstDelay)
  146. {
  147. bool abnormal = CheckDisable();
  148. if (abnormal)
  149. {
  150. return false;
  151. }
  152. }
  153. return false;
  154. }
  155. /// <summary>
  156. /// 检验数据
  157. /// </summary>
  158. /// <returns></returns>
  159. private bool CheckDisable()
  160. {
  161. bool isSimulatorMode = SC.GetValue<bool>("System.IsSimulatorMode");
  162. if (!isSimulatorMode)
  163. {
  164. if (!_vpwCellDevice.CheckRotationRunning())
  165. {
  166. NotifyError(eEvent.ERR_VPW, $"{Module} rotation is stopped", 0);
  167. Abort();
  168. return true;
  169. }
  170. }
  171. return false;
  172. }
  173. /// <summary>
  174. /// 启动
  175. /// </summary>
  176. /// <param name="objs"></param>
  177. /// <returns></returns>
  178. public RState Start(params object[] objs)
  179. {
  180. _recipe=(VpwRecipe)objs[0];
  181. _vpwCellDevice = DEVICE.GetDevice<VpwCellDevice>(Module);
  182. _mainDevice = DEVICE.GetDevice<VpwMainDevice>(ModuleName.VPWMain1.ToString());
  183. _lidReleasePressure = SC.GetValue<int>($"{Module}.LidReleasePressure");
  184. _lidReleasePressureTimeout = SC.GetValue<int>($"{Module}.LidReleasePressureTimeout");
  185. _totalMicrosecond = 0;
  186. _stepIndex = 0;
  187. return Runner.Start(Module, $"{Module} spin off");
  188. }
  189. /// <summary>
  190. /// 重试
  191. /// </summary>
  192. /// <param name="step"></param>
  193. public RState Retry(int step)
  194. {
  195. if (_recipe == null)
  196. {
  197. NotifyError(eEvent.ERR_VPW, "recipe is null", -1);
  198. return RState.Failed;
  199. }
  200. List<Enum> preStepIds = new List<Enum>();
  201. return Runner.Retry(PrepareStep.CloseCellValve, preStepIds, Module, "Spin off Retry");
  202. }
  203. }
  204. }