CycleManualProcessRecipeRoutine.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. using System;
  2. using System.Collections.Generic;
  3. using Aitex.Core.RT.Device;
  4. using Aitex.Core.RT.Routine;
  5. using MECF.Framework.Common.Routine;
  6. using CyberX8_Core;
  7. using CyberX8_RT.Devices.LinMot;
  8. using CyberX8_RT.Devices.Prewet;
  9. using MECF.Framework.Common.CommonData.Prewet;
  10. using MECF.Framework.Common.CommonData;
  11. using Aitex.Core.RT.SCCore;
  12. using Aitex.Core.Util;
  13. using Aitex.Core.RT.Log;
  14. using MECF.Framework.Common.RecipeCenter;
  15. namespace CyberX8_RT.Modules.Prewet
  16. {
  17. sealed class CycleManualProcessRecipeRoutine:RoutineBase, IRoutine
  18. {
  19. private const int LOTTRACK_TIME = 1000;
  20. private enum CycleManualRunRecipeStep
  21. {
  22. LoopStart,
  23. LoopRunProcess,
  24. LoopWaitRunProcess,
  25. LoopDelay,
  26. LoopEnd,
  27. End
  28. }
  29. #region 内部变量
  30. private PrewetProcessRoutine _processRecipeRoutine;
  31. private LinMotAxis _linmotAxis;
  32. private int _cycle = 0;
  33. private int _achievedCycle;
  34. private object[] param;
  35. /// <summary>
  36. /// Prewet recipe
  37. /// </summary>
  38. private PwtRecipe _recipe;
  39. /// <summary>
  40. /// lock track time
  41. /// </summary>
  42. private DateTime _lotTackTime = DateTime.Now;
  43. /// <summary>
  44. /// LotTrack数据
  45. /// </summary>
  46. private List<PrewetLotTrackData> _datas = new List<PrewetLotTrackData>();
  47. /// <summary>
  48. /// LotTrack文件头数据
  49. /// </summary>
  50. private LotTrackFileHeaderCommonData _header = new LotTrackFileHeaderCommonData();
  51. /// <summary>
  52. /// 设备对象
  53. /// </summary>
  54. private PrewetDevice _prewetDevice;
  55. #endregion
  56. #region 属性
  57. /// <summary>
  58. /// 当前执行到循环哪一步
  59. /// </summary>
  60. public string CurrentStatus
  61. {
  62. get { return Runner.CurrentStep.ToString(); ; }
  63. }
  64. /// <summary>
  65. /// 当前执行到循环哪一步内的哪个动作
  66. /// </summary>
  67. public string CurrentStateMachine
  68. {
  69. get { return _processRecipeRoutine.CurrentStep; }
  70. }
  71. /// <summary>
  72. /// LotTrack数据
  73. /// </summary>
  74. public List<PrewetLotTrackData> PrewetLotTrackDatas { get { return _datas; } }
  75. /// <summary>
  76. /// LotTrack文件头数据
  77. /// </summary>
  78. public LotTrackFileHeaderCommonData PrewetLotTrackHeaderDatas { get { return _header; } }
  79. #endregion
  80. /// <summary>
  81. /// 构造函数
  82. /// </summary>
  83. /// <param name="module"></param>
  84. public CycleManualProcessRecipeRoutine(string module, LinMotAxis linMotAxis) : base(module)
  85. {
  86. _linmotAxis = linMotAxis;
  87. _processRecipeRoutine = new PrewetProcessRoutine(module, _linmotAxis);
  88. }
  89. /// <summary>
  90. /// Abort
  91. /// </summary>
  92. public void Abort()
  93. {
  94. _processRecipeRoutine.Abort();
  95. Runner.Stop("Cycle ManualRunRecipe Abort");
  96. }
  97. public RState Start(params object[] objs)
  98. {
  99. _cycle = (int)objs[1];
  100. _achievedCycle = 0;
  101. param = objs;
  102. _prewetDevice = DEVICE.GetDevice<PrewetDevice>(Module);
  103. _datas.Clear();
  104. _recipe = objs[0] as PwtRecipe;
  105. if (_recipe == null)
  106. {
  107. LOG.WriteLog(eEvent.ERR_PREWET, Module, "recipe is null");
  108. return RState.Failed;
  109. }
  110. if (SC.ContainsItem("System.ToolID")) _header.ToolID = SC.GetStringValue("System.ToolID");
  111. _header.SoftWareVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
  112. _header.Recipe = $"{_recipe.Ppid}.pwt.rcp";
  113. //lotTract记录SequenceRecipe
  114. PrewetEntity prewetEntity = Singleton<RouteManager>.Instance.GetModule<PrewetEntity>(Module);
  115. if (prewetEntity.WaferHolderInfo != null && prewetEntity.WaferHolderInfo.SequenceRecipe != null && !string.IsNullOrEmpty(prewetEntity.WaferHolderInfo.SequenceRecipe.Ppid.ToString()))
  116. {
  117. _header.SequenceRecipe = prewetEntity.WaferHolderInfo.SequenceRecipe.Ppid.ToString();
  118. _header.ProcessTransferList = new List<string>();
  119. _header.ProcessTransferList.AddRange(prewetEntity.WaferHolderInfo.SchedulerModules);
  120. prewetEntity.WaferHolderInfo.SchedulerModules.Clear();
  121. }
  122. _lotTackTime = DateTime.Now;
  123. return Runner.Start(Module, "Start cycle ManualRunRecipe");
  124. }
  125. public RState Monitor()
  126. {
  127. LottrackRecord();
  128. Runner.LoopStart(CycleManualRunRecipeStep.LoopStart, "Loop Start ManualRunRecipe", _cycle, NullFun, _delay_1ms)
  129. .LoopRun(CycleManualRunRecipeStep.LoopRunProcess, () => _processRecipeRoutine.Start(param) == RState.Running, _delay_1ms)
  130. .LoopRunWithStopStatus(CycleManualRunRecipeStep.LoopWaitRunProcess, () => CheckRoutineEndStatus(_processRecipeRoutine), () => CheckRoutineStopStatus(_processRecipeRoutine))
  131. .LoopDelay(CycleManualRunRecipeStep.LoopDelay, _delay_1s)
  132. .LoopEnd(CycleManualRunRecipeStep.LoopEnd, AchievedCycleCount, _delay_1ms)
  133. .End(CycleManualRunRecipeStep.End, NullFun, _delay_1ms);
  134. return Runner.Status;
  135. }
  136. private bool CheckRoutineEndStatus(IRoutine routine)
  137. {
  138. bool result = routine.Monitor() == RState.End;
  139. return result;
  140. }
  141. private bool CheckRoutineStopStatus(IRoutine routine)
  142. {
  143. RState state = routine.Monitor();
  144. if (state == RState.Failed || state == RState.Timeout)
  145. {
  146. AddLotTrackData();
  147. return true;
  148. }
  149. return false;
  150. }
  151. /// <summary>
  152. /// 统计完成的Cycle次数
  153. /// </summary>
  154. /// <returns></returns>
  155. private bool AchievedCycleCount()
  156. {
  157. _achievedCycle += 1;
  158. return true;
  159. }
  160. /// <summary>
  161. /// 获取已经完成的Cycle次数
  162. /// </summary>
  163. /// <returns></returns>
  164. public int GetAchievedCycle()
  165. {
  166. return _achievedCycle;
  167. }
  168. /// <summary>
  169. /// 记录Lottrack
  170. /// </summary>
  171. private void LottrackRecord()
  172. {
  173. //记录Lottrack
  174. if (DateTime.Now.Subtract(_lotTackTime).TotalMilliseconds >= LOTTRACK_TIME)
  175. {
  176. AddLotTrackData();
  177. _lotTackTime = DateTime.Now;
  178. }
  179. }
  180. /// <summary>
  181. /// 获取Lot Track数据
  182. /// </summary>
  183. /// <returns></returns>
  184. private void AddLotTrackData()
  185. {
  186. PrewetLotTrackData data = new PrewetLotTrackData();
  187. data.TimeStamp = DateTime.Now;
  188. data.StateMachine = CurrentStateMachine;
  189. data.Pressure = _prewetDevice.PrewetPumpData.PumpPressureData.Value;
  190. data.Flow = _prewetDevice.PrewetPumpData.PumpFlowData.Value;
  191. data.PumpMode = _prewetDevice.PrewetPumpData.PumpModel;
  192. data.PressureTarget = _prewetDevice.PrewetPumpData.PressureTarget;
  193. data.CurrentScan = _linmotAxis.ScanCount;
  194. data.ScanOn = _linmotAxis.IsMotorOn;
  195. data.ValveState = _prewetDevice.PrewetPumpData.PumpValve;
  196. data.PumpSpeed = _prewetDevice.LastPumpSpeed;
  197. data.PumpControlCurrent = _prewetDevice.PrewetPumpData.PumpCurrent;
  198. _datas.Add(data);
  199. }
  200. }
  201. }