PMProcessRoutine.cs 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774
  1. using System;
  2. using System.Collections.Generic;
  3. using Aitex.Core.RT.Routine;
  4. using Aitex.Core.RT.SCCore;
  5. using Aitex.Core.Common;
  6. using Aitex.Core.RT.RecipeCenter;
  7. using Venus_RT.Devices;
  8. using MECF.Framework.Common.Equipment;
  9. using MECF.Framework.Common.SubstrateTrackings;
  10. using Venus_Core;
  11. using System.Diagnostics;
  12. using MECF.Framework.Common.DBCore;
  13. using System.Threading.Tasks;
  14. using Aitex.Core.RT.Event;
  15. using Aitex.Core.RT.Log;
  16. using Aitex.Core.RT.DataCenter;
  17. using Aitex.Core.Common.DeviceData;
  18. namespace Venus_RT.Modules.PMs
  19. {
  20. class PMProcessRoutine : PMRoutineBase, IRoutine
  21. {
  22. private enum ProcessStep
  23. {
  24. PreparePVHe2,
  25. ClosePVHe2,
  26. WaitPressure,
  27. PreparePressure,
  28. PrepareTemperature,
  29. RunChuckRecipe,
  30. RunProcessRecipe,
  31. RunDechuckRecipe,
  32. RunCleanRecipe,
  33. End,
  34. }
  35. public string CurrentRunningRecipe { get; set; }
  36. public string ProcessRecipeName { get; set; }
  37. public string ChuckRecipeName { get; set; }
  38. public string DechuckRecipeName { get; set; }
  39. public string CleanRecipeName { get; set; }
  40. public RecipeHead ProcessRecipeHead { get; set; }
  41. public DateTime RecipeStartTime { get; private set; }
  42. public DateTime RecipeEndTime { get; private set; }
  43. public string WaferId { get; set; }
  44. public string SlotID { get; set; }
  45. public string LotID { get; set; }
  46. public string RecipeId { get; set; }
  47. //public bool CurrentRecipeType { get; set; }
  48. //int Timeall;
  49. private Stopwatch Recipetime = new Stopwatch();
  50. private readonly PumpDownRoutine _pumpDownRoutine;
  51. private readonly ProcessHelper _processHelper;
  52. private bool _withWafer = true;
  53. private bool _needPumpDown = false;
  54. public Recipe _currentRecipe = null;
  55. private int _currentStep = 0;
  56. private List<Recipe> Recipelist = new List<Recipe>();
  57. //private double _tolerance;
  58. //private double _OffsetTemp = 0.0f;
  59. private bool _bLoopMode = false;
  60. private int _loopStartStep = 0;
  61. private int _loopCounter = 0;
  62. private int _recipeRunningMode = 0;
  63. private Stopwatch _stepTime = new Stopwatch();
  64. public RecipeResult currentRecipeResult;
  65. public bool isMaualEndStep;
  66. private RecipeFACallback _faCallback;
  67. private JetChamber _jetChamber;
  68. private RecipeType _recipeType;
  69. private Recipe ProcessRecipe;
  70. private Recipe ChuckRecipe;
  71. private Recipe DechuckRecipe;
  72. private Recipe CleanRecipe;
  73. private bool needprocess;
  74. private bool needdechuck;
  75. private bool needchuck;
  76. private bool needclean;
  77. private bool IsVenus;
  78. private double ProcessPressureOffset = 10;
  79. //private Fdc _fdc;
  80. private string Eap_StartRecipeTime;
  81. private string Eap_EndRecipeTime;
  82. private int Eap_RecipeRFOnTime;
  83. private Stopwatch Eap_RFStopWatch = new Stopwatch();
  84. private double BaseTemperature
  85. {
  86. get
  87. {
  88. if (ProcessRecipeHead != null)
  89. {
  90. if (!string.IsNullOrEmpty(ProcessRecipeHead.Temperature))
  91. {
  92. double setpoint = Convert.ToDouble(ProcessRecipeHead.Temperature);
  93. if (setpoint > 0 && setpoint < 600)
  94. return setpoint;
  95. }
  96. }
  97. return 0;
  98. }
  99. }
  100. private double BasePressure
  101. {
  102. get
  103. {
  104. if (ProcessRecipeHead != null)
  105. {
  106. if (!string.IsNullOrEmpty(ProcessRecipeHead.BasePressure))
  107. {
  108. double setpoint = Convert.ToDouble(ProcessRecipeHead.BasePressure);
  109. if (setpoint > 0 && setpoint < 750000)
  110. return setpoint;
  111. }
  112. }
  113. return SC.GetValue<int>($"{Module}.Pump.PumpBasePressure");
  114. }
  115. }
  116. public double EstimatedTotalLeftTime
  117. {
  118. get;
  119. private set;
  120. }
  121. public PMProcessRoutine(JetPMBase chamber, PumpDownRoutine pdRoutine) : base(chamber)
  122. {
  123. Name = "Process";
  124. _pumpDownRoutine = pdRoutine;
  125. _processHelper = new ProcessHelper(chamber);
  126. _faCallback = new RecipeFACallback();
  127. _jetChamber = (JetChamber)SC.GetValue<int>($"{chamber.Module}.ChamberType");
  128. if (_jetChamber == JetChamber.VenusSE || _jetChamber == JetChamber.VenusDE)
  129. IsVenus = true;
  130. else
  131. IsVenus = false;
  132. DATA.Subscribe($"{chamber.Module}.RecipeStartTime", Eap_StartRecipeTime);
  133. DATA.Subscribe($"{chamber.Module}.RecipeEndTime", Eap_EndRecipeTime);
  134. DATA.Subscribe($"{chamber.Module}.StepTime", ()=> _processHelper.EAP_StepTime);
  135. DATA.Subscribe($"{chamber.Module}.RecipeRfOntime", () => Eap_RecipeRFOnTime);
  136. DATA.Subscribe($"{chamber.Module}.StepNo", () => _currentRecipe?.Steps[_currentStep].StepNo);
  137. }
  138. private bool AssignFuns(Recipe recipe)
  139. {
  140. foreach (var step in recipe.Steps)
  141. {
  142. if (_processHelper.LoadStepFuns(step) == false)
  143. return false;
  144. foreach (ProcessUnitBase unit in step.LstUnit)
  145. {
  146. if (_processHelper.LoadMethods(unit) == false)
  147. {
  148. Stop($"Cannot find the process routine for unit:{unit.GetType()}");
  149. return false;
  150. }
  151. }
  152. }
  153. return true;
  154. }
  155. public RState Start(params object[] objs)
  156. {
  157. needprocess = false;
  158. needchuck = false;
  159. needclean = false;
  160. needdechuck = false;
  161. Recipelist.Clear();
  162. string recipeName = (string)objs[0];
  163. if (objs.Length >= 2)
  164. {
  165. _recipeType = (RecipeType)Enum.Parse(typeof(RecipeType), objs[2].ToString());
  166. if (_recipeType == RecipeType.Clean)
  167. {
  168. _withWafer = false;
  169. }
  170. else
  171. {
  172. _withWafer = true;
  173. }
  174. }
  175. if (objs.Length >= 4)
  176. {
  177. LotID = objs[3].ToString();
  178. }
  179. else
  180. {
  181. LotID = "";
  182. }
  183. if (_withWafer && WaferManager.Instance.CheckNoWafer(Module, 0))
  184. {
  185. Stop($"can not run process, no wafer at {Module}");
  186. EV.PostAlarmLog(Module.ToString(), eEvent.ERR_PM_PROCESSNOWAFER, $"can not run process, no wafer at {Module}");
  187. return RState.Failed;
  188. }
  189. else if (!_withWafer && WaferManager.Instance.CheckHasWafer(Module, 0))
  190. {
  191. Stop($"can not run clean recipe{recipeName}, a wafer at {Module}");
  192. EV.PostAlarmLog(Module.ToString(), eEvent.ERR_PM_CLEANWITHWAFER, $"can not run clean recipe, a wafer at {Module}");
  193. return RState.Failed;
  194. }
  195. if (!_chamber.IsRFGInterlockOn)
  196. {
  197. Stop("射频电源 Interlock条件不满足");
  198. EV.PostAlarmLog(Module.ToString(), eEvent.ERR_RF_RFGInterlock, "射频电源 Interlock条件不满足");
  199. return RState.Failed;
  200. }
  201. if (!CheckSlitDoor() || !CheckDryPump() || !CheckTurboPump())
  202. {
  203. return RState.Failed;
  204. }
  205. currentRecipeResult = new RecipeResult();
  206. currentRecipeResult.RecipeName = recipeName;
  207. string recipeContent = RecipeFileManager.Instance.LoadRecipe(_chamber.Name, recipeName, false, objs[2].ToString());
  208. Recipe recipe = Recipe.Load(recipeContent);
  209. if (recipeName != recipe.Header.Name)
  210. {
  211. Stop($"Recipe内部名{recipe.Header.Name}与外部名{recipeName}不一致,请确认Recipe来源");
  212. return RState.Failed;
  213. }
  214. if (_jetChamber != recipe.Header.ChamberType)
  215. {
  216. Stop($"不可以在{_jetChamber}腔体跑{recipe.Header.ChamberType}类型的Recipe,请确认Recipe来源");
  217. return RState.Failed;
  218. }
  219. currentRecipeResult.RecipeStepCount = recipe.Steps.Count;
  220. if (recipe == null)
  221. {
  222. Stop($"Load Recipe:{recipeName} failed");
  223. EV.PostAlarmLog(Module.ToString(), $"Load Recipe:{recipeName} failed");
  224. return RState.Failed;
  225. }
  226. _recipeRunningMode = SC.GetValue<int>($"{Module}.RecipeRunningMode");
  227. _processHelper.m_RecipeHead = recipe.Header;
  228. switch (recipe.Header.Type)
  229. {
  230. case RecipeType.Process:
  231. if (_recipeRunningMode == 1 && recipe.Header.ChuckRecipe != null && !string.IsNullOrEmpty(recipe.Header.ChuckRecipe))
  232. {
  233. string chuckcontent = RecipeFileManager.Instance.LoadRecipe(_chamber.Name, recipe.Header.ChuckRecipe, false, RecipeType.Chuck.ToString());
  234. ChuckRecipe = Recipe.Load(chuckcontent);
  235. if (ChuckRecipe != null)
  236. {
  237. ChuckRecipeName = recipe.Header.ChuckRecipe;
  238. needchuck = true;
  239. Recipelist.Add(ChuckRecipe);
  240. }
  241. }
  242. needprocess = true;
  243. ProcessRecipeHead = recipe.Header;
  244. ProcessRecipe = recipe;
  245. ProcessRecipeName = recipeName;
  246. Recipelist.Add(recipe);
  247. if (_recipeRunningMode == 1 && recipe.Header.DechuckRecipe != null && !string.IsNullOrEmpty(recipe.Header.DechuckRecipe))
  248. {
  249. string dechuckcontent = RecipeFileManager.Instance.LoadRecipe(_chamber.Name, recipe.Header.DechuckRecipe, false, RecipeType.DeChuck.ToString());
  250. DechuckRecipe = Recipe.Load(dechuckcontent);
  251. if (DechuckRecipe != null)
  252. {
  253. DechuckRecipeName = recipe.Header.DechuckRecipe;
  254. needdechuck = true;
  255. Recipelist.Add(DechuckRecipe);
  256. }
  257. }
  258. break;
  259. case RecipeType.Chuck:
  260. ChuckRecipeName = recipeName;
  261. ChuckRecipe = recipe;
  262. Recipelist.Add(ChuckRecipe);
  263. needchuck = true;
  264. break;
  265. case RecipeType.DeChuck:
  266. DechuckRecipeName = recipeName;
  267. Recipelist.Add(DechuckRecipe);
  268. DechuckRecipe = recipe;
  269. needdechuck = true;
  270. break;
  271. case RecipeType.Clean:
  272. CleanRecipe = recipe;
  273. CleanRecipeName = recipeName;
  274. Recipelist.Add(CleanRecipe);
  275. needclean = true;
  276. break;
  277. }
  278. foreach (Recipe rcp in Recipelist)
  279. {
  280. if (AssignFuns(rcp) == false)
  281. {
  282. Stop($"Associate process alogrithm with recipe:{rcp.Header.Name} failed");
  283. EV.PostAlarmLog(Module.ToString(), $"Associate process alogrithm with recipe:{rcp.Header.Name} failed");
  284. return RState.Failed;
  285. }
  286. }
  287. _bLoopMode = false;
  288. _loopStartStep = 0;
  289. _loopCounter = 0;
  290. _processHelper.isLoop = false;
  291. _processHelper.loopsteps = 0;
  292. _processHelper.currentStepIndex = 0;
  293. if (needprocess)
  294. {
  295. switch (_jetChamber)
  296. {
  297. case JetChamber.VenusSE:
  298. if (Convert.ToDouble(ProcessRecipe.Header.Temperature) != SC.GetValue<double>($"{_chamber.Module}.Chiller.LastTemp"))
  299. {
  300. LOG.Write(eEvent.ERR_PROCESS, _chamber.Module, $"Chiller Temp setpoint not {ProcessRecipe.Header.Temperature}");
  301. return RState.Failed;
  302. }
  303. else
  304. {
  305. SC.SetItemValue($"{_chamber.Module}.Chiller.EnableToleranceAlarm", true);
  306. }
  307. if (Convert.ToDouble(ProcessRecipe.Header.WallTemperature) != ((AITHeaterData)DATA.Poll($"{_chamber.Module}.WallHeater.DeviceData")).SetPoint)
  308. {
  309. LOG.Write(eEvent.ERR_PROCESS, _chamber.Module, $"WallChiller Temp setpoint not {ProcessRecipe.Header.WallTemperature}");
  310. return RState.Failed;
  311. }
  312. else
  313. {
  314. SC.SetItemValue($"{_chamber.Module}.WallChiller.EnableToleranceAlarm", true);
  315. }
  316. break;
  317. case JetChamber.VenusDE:
  318. if (Convert.ToDouble(ProcessRecipe.Header.Temperature) != SC.GetValue<double>($"{_chamber.Module}.Chiller.LastTemp"))
  319. {
  320. LOG.Write(eEvent.ERR_PROCESS, _chamber.Module, $"Chiller Temp setpoint not {ProcessRecipe.Header.Temperature}");
  321. return RState.Failed;
  322. }
  323. else
  324. {
  325. SC.SetItemValue($"{_chamber.Module}.Chiller.EnableToleranceAlarm", true);
  326. }
  327. if (Convert.ToDouble(ProcessRecipe.Header.WallTemperature) != SC.GetValue<double>($"{_chamber.Module}.WallChiller.LastTemp"))
  328. {
  329. LOG.Write(eEvent.ERR_PROCESS, _chamber.Module, $"WallChiller Temp setpoint not {ProcessRecipe.Header.WallTemperature}");
  330. return RState.Failed;
  331. }
  332. else
  333. {
  334. SC.SetItemValue($"{_chamber.Module}.WallChiller.EnableToleranceAlarm", true);
  335. }
  336. break;
  337. }
  338. }
  339. ProcessPressureOffset = SC.GetValue<double>($"{_chamber.Module}.ProcessPressureOffset");
  340. _faCallback.RecipeStart(_chamber.Module.ToString(), recipeName);
  341. WaferManager.Instance.UpdateWaferProcessStatus(Module, 0, EnumWaferProcessStatus.InProcess);
  342. Eap_StartRecipeTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff");
  343. Eap_EndRecipeTime = "";
  344. return Runner.Start(Module, Name);
  345. }
  346. public RState Monitor()
  347. {
  348. if (IsVenus)
  349. {
  350. Runner.Run(ProcessStep.PreparePVHe2, PrepareHe2, _delay_5s)
  351. .Run(ProcessStep.ClosePVHe2, CloseHe2, _delay_1s)
  352. .Wait(ProcessStep.WaitPressure, CheckBasePressure, _delay_30s)
  353. .RunIf(ProcessStep.RunChuckRecipe, needchuck, StartChuckRecipe, CheckRecipeDone, 5 * 60 * 60 * 1000)
  354. .RunIf(ProcessStep.RunProcessRecipe, needprocess, StartProcessRecipe, CheckRecipeDone, 5 * 60 * 60 * 1000)
  355. .RunIf(ProcessStep.RunDechuckRecipe, needdechuck, StartDechuckRecipe, CheckRecipeDone, 5 * 60 * 60 * 1000)
  356. .RunIf(ProcessStep.RunCleanRecipe, needclean, StartCleanRecipe, CheckRecipeDone, 5 * 60 * 60 * 1000)
  357. .End(ProcessStep.End, ProcessDone, _delay_1s);
  358. }
  359. else
  360. {
  361. if ((DATA.Poll($"{_chamber.Module}.Rf.DeviceData") as AITRfData).IsRfOn)
  362. {
  363. Eap_RFStopWatch.Start();
  364. }
  365. else
  366. {
  367. Eap_RFStopWatch.Stop();
  368. }
  369. Runner.Run(ProcessStep.PreparePressure, PreparePressure, IsPressureReady)
  370. .Run(ProcessStep.PrepareTemperature, PrepareTemp, IsTempReady)
  371. .RunIf(ProcessStep.RunChuckRecipe, needchuck, StartChuckRecipe, CheckRecipeDone, 5 * 60 * 60 * 1000)
  372. .RunIf(ProcessStep.RunProcessRecipe, needprocess, StartProcessRecipe, CheckRecipeDone, 5 * 60 * 60 * 1000)
  373. .RunIf(ProcessStep.RunDechuckRecipe, needdechuck, StartDechuckRecipe, CheckRecipeDone, 5 * 60 * 60 * 1000)
  374. .RunIf(ProcessStep.RunCleanRecipe, needclean, StartCleanRecipe, CheckRecipeDone, 5 * 60 * 60 * 1000)
  375. .End(ProcessStep.End, ProcessDone, _delay_1s);
  376. }
  377. return Runner.Status;
  378. }
  379. private bool CheckBasePressure()
  380. {
  381. if (needprocess)
  382. return _chamber.ProcessPressure <= Convert.ToDouble(ProcessRecipe.Header.BasePressure);
  383. else
  384. return true;
  385. }
  386. private bool CloseHe2()
  387. {
  388. _chamber.OpenValve(ValveType.PVHe2, false);
  389. return true;
  390. }
  391. private bool PrepareHe2()
  392. {
  393. _chamber.OpenValve(ValveType.PVHe2, true);
  394. return true;
  395. }
  396. private bool PreparePressure()
  397. {
  398. //if (_chamber.ProcessPressure < BasePressure && RtInstance.ConfigType==ConfigType.Kepler2200)
  399. //{
  400. // _needPumpDown = false;
  401. // return true;
  402. //}
  403. //_needPumpDown = true;
  404. return _pumpDownRoutine.Start(BasePressure) == RState.Running;
  405. }
  406. private bool IsPressureReady()
  407. {
  408. //if (_needPumpDown == false && RtInstance.ConfigType == ConfigType.Kepler2200)
  409. //{
  410. // return true;
  411. //}
  412. var status = _pumpDownRoutine.Monitor();
  413. if (status == RState.End)
  414. {
  415. return true;
  416. }
  417. else if (status == RState.Failed || status == RState.Timeout)
  418. {
  419. Runner.Stop($"Pump down to {BasePressure} failed.");
  420. EV.PostAlarmLog(Module.ToString(), $"Pump down to {BasePressure} failed.");
  421. return true;
  422. }
  423. return false;
  424. }
  425. private bool PrepareTemp()
  426. {
  427. //if (_jetChamber == JetChamber.Venus)
  428. //{
  429. // return SetCoolantTemp(BaseTemperature, _OffsetTemp);
  430. //}
  431. //else
  432. //{
  433. // return true;
  434. //}
  435. return true;
  436. }
  437. private bool IsTempReady()
  438. {
  439. //if (_jetChamber == JetChamber.Venus)
  440. //{
  441. // return CheckCoolantTemp(BaseTemperature, _tolerance);
  442. //}
  443. //else
  444. //{
  445. // return true;
  446. //}
  447. return true;
  448. }
  449. public RState StartNewStep()
  450. {
  451. ProcessDataRecorder.StepStart(RecipeId, _currentRecipe.Steps[_currentStep].StepNo, $"{Module}:{_currentRecipe.Header.Name}:{_currentRecipe.Steps[_currentStep].Description}", _currentRecipe.Steps[_currentStep].Time);
  452. _stepTime.Restart();
  453. var state = _currentRecipe.Steps[_currentStep].Start();
  454. LOG.Write(eEvent.INFO_PROCESS, Module, $"Recipe:{CurrentRunningRecipe} Step{_currentStep + 1} Start");
  455. _faCallback.RecipeStepStart(Module.ToString(), CurrentRunningRecipe, _currentStep);
  456. if (state != RState.Running)
  457. {
  458. Runner.Stop($"Start Step {_currentStep + 1} failed.");
  459. return state;
  460. }
  461. //if (_bLoopMode == true)
  462. //{
  463. //}
  464. if (_currentRecipe.Steps[_currentStep].CycleStart)
  465. {
  466. if (!_bLoopMode)
  467. {
  468. _bLoopMode = true;
  469. _loopStartStep = _currentStep;
  470. _loopCounter = _currentRecipe.Steps[_currentStep].CycleNumber - 1;
  471. currentRecipeResult.RecipeAllCounters = _currentRecipe.Steps[_currentStep].CycleNumber;
  472. currentRecipeResult.RecipeCurrentCounter = _loopCounter == 0 ? 0 : 1;
  473. _processHelper.isLoop = true;
  474. _processHelper.loopsteps = _currentRecipe.Steps[_currentStep].CycleNumber;
  475. }
  476. else
  477. {
  478. _processHelper.currentStepIndex += 1;
  479. }
  480. }
  481. return RState.Running;
  482. }
  483. private bool startRecipe(Recipe _recipe)
  484. {
  485. _currentRecipe = _recipe;
  486. if (_currentRecipe != null)
  487. {
  488. _currentStep = 0;
  489. CurrentRunningRecipe = _currentRecipe.Header.Name;
  490. RecipeId = Guid.NewGuid().ToString();
  491. RecipeStartTime = DateTime.Now;
  492. Recipetime.Restart();
  493. Notify($"Recipe:{CurrentRunningRecipe} start");
  494. _chamber.EPDRecipeStart(CurrentRunningRecipe);
  495. return StartNewStep() == RState.Running;
  496. }
  497. else { return false; }
  498. }
  499. private bool StartProcessRecipe()
  500. {
  501. return startRecipe(ProcessRecipe);
  502. }
  503. private bool StartChuckRecipe()
  504. {
  505. return startRecipe(ChuckRecipe);
  506. }
  507. private bool StartDechuckRecipe()
  508. {
  509. return startRecipe(DechuckRecipe);
  510. }
  511. private bool StartCleanRecipe()
  512. {
  513. return startRecipe(CleanRecipe);
  514. }
  515. private bool CheckRecipeDone()
  516. {
  517. var step = _currentRecipe.Steps[_currentStep];
  518. currentRecipeResult.RecipeStepCount = _currentRecipe.Steps.Count;
  519. currentRecipeResult.RecipeName = _currentRecipe.Header.Name;
  520. currentRecipeResult.RecipeType = _currentRecipe.Header.Type.ToString();
  521. currentRecipeResult.RecipeStepNumber = (_currentStep + 1);
  522. currentRecipeResult.RecipeStepType = step.Type.ToString();
  523. currentRecipeResult.RecipeStepDescription = string.IsNullOrEmpty(step.Description) ? "" : step.Description;
  524. switch (step.Type)
  525. {
  526. case StepType.Time:
  527. currentRecipeResult.RecipeStepSetTime = step.Time;
  528. break;
  529. case StepType.OverEtch:
  530. currentRecipeResult.RecipeStepSetTime = (int)_processHelper.lastEPDStepTime / 1000;
  531. break;
  532. default:
  533. currentRecipeResult.RecipeStepSetTime = null;
  534. break;
  535. }
  536. //currentRecipeResult.RecipeStepSetTime = step.Type==StepType.OverEtch? (int)_processHelper.lastEPDStepTime/1000: step.Time;
  537. currentRecipeResult.RecipeType = _currentRecipe.Header.Type.ToString();
  538. currentRecipeResult.RecipeStepDuringTime = (int)_stepTime.ElapsedMilliseconds / 1000;
  539. var result = step.Run();
  540. if (result == RState.Failed)
  541. {
  542. RecipeDone("Fail");
  543. UpdateWaferStatus(false);
  544. Runner.Stop($"Recipe:{CurrentRunningRecipe}, Step:{_currentStep + 1} Failed in {_stepTime.ElapsedMilliseconds / 1000}s");
  545. EV.PostAlarmLog(Module.ToString(), $"Recipe:{CurrentRunningRecipe}, Step:{_currentStep + 1} Failed");
  546. _faCallback.RecipeFailed(Module.ToString(), CurrentRunningRecipe);
  547. return true;
  548. }
  549. else if (result == RState.End || isMaualEndStep == true)
  550. {
  551. if (_currentRecipe.Steps.Count > _currentStep + 1)
  552. {
  553. _currentRecipe.Steps[_currentStep].End();
  554. }
  555. if (_currentRecipe.Steps[_currentStep].CycleEnd)
  556. {
  557. if (_loopCounter > 0)
  558. {
  559. _loopCounter--;
  560. currentRecipeResult.RecipeCurrentCounter += 1;
  561. _currentStep = _loopStartStep;
  562. return StartNewStep() != RState.Running;
  563. }
  564. else
  565. {
  566. _bLoopMode = false;
  567. _loopStartStep = 0;
  568. //_processHelper.loopStep(false, 0, 0);
  569. _processHelper.isLoop = false;
  570. _processHelper.loopsteps = 0;
  571. _processHelper.currentStepIndex = 0;
  572. }
  573. }
  574. if (_currentStep < _currentRecipe.Steps.Count - 1 || isMaualEndStep == true)
  575. {
  576. result = RState.End;
  577. isMaualEndStep = false;
  578. _currentStep++;
  579. LOG.Write(eEvent.INFO_PROCESS, Module, $"Recipe:{CurrentRunningRecipe} Step{_currentStep} End");
  580. ProcessDataRecorder.StepStart(RecipeId, _currentRecipe.Steps[_currentStep].StepNo, $"{Module}:{_currentRecipe.Header.Name}:{_currentRecipe.Steps[_currentStep].Description}", _currentRecipe.Steps[_currentStep].Time);
  581. _faCallback.RecipeStepEnd(Module.ToString(), CurrentRunningRecipe, _currentStep);
  582. return StartNewStep() != RState.Running;
  583. }
  584. else
  585. {
  586. LOG.Write(eEvent.INFO_PROCESS, Module, $"Recipe:{CurrentRunningRecipe} Step{_currentStep + 1} End");
  587. Notify($"Recipe:{CurrentRunningRecipe} finished");
  588. //FaEvent.FaPostInfo(Module.ToString(), $"Recipe:{CurrentRunningRecipe} finished");
  589. UpdateWaferStatus();
  590. //if (_currentRecipe.Header.Type == RecipeType.Process)
  591. //{
  592. // processRecipe = (Recipe)SerializeHelper.Instance.Clone(_currentRecipe);
  593. //}
  594. _chamber.EPDRecipeStop();
  595. RecipeDone("Success");
  596. return true;
  597. }
  598. }
  599. return false;
  600. }
  601. public void RecipeDone(string result)
  602. {
  603. Eap_EndRecipeTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff");
  604. Eap_RecipeRFOnTime = Convert.ToInt32(Eap_RFStopWatch.ElapsedMilliseconds / 1000);
  605. Eap_RFStopWatch.Reset();
  606. Recipetime.Stop();
  607. WaferInfo waferInfo = WaferManager.Instance.GetWafer(ModuleHelper.Converter(Module.ToString()), 0);
  608. if (!waferInfo.IsEmpty)
  609. {
  610. WaferId = waferInfo.InnerId.ToString();
  611. SlotID = waferInfo.OriginSlot.ToString();
  612. LotID = waferInfo.ProcessJob == null || string.IsNullOrEmpty(waferInfo.ProcessJob.ControlJobName) ? "" : waferInfo.ProcessJob.ControlJobName;
  613. }
  614. RecipeEndTime = RecipeStartTime + Recipetime.Elapsed;
  615. switch (_currentRecipe.Header.Type)
  616. {
  617. case RecipeType.Clean:
  618. ProcessDataRecorder.RecordPrecess(RecipeId, RecipeStartTime, RecipeEndTime, _currentRecipe.Header.Name, result, "", _chamber.Name, "", "", _currentRecipe.Header.Type.ToString());
  619. break;
  620. case RecipeType.Chuck:
  621. case RecipeType.DeChuck:
  622. case RecipeType.Process:
  623. ProcessDataRecorder.RecordPrecess(RecipeId, RecipeStartTime, RecipeEndTime, _currentRecipe.Header.Name, result, WaferId, _chamber.Name, LotID, SlotID, _currentRecipe.Header.Type.ToString());
  624. break;
  625. }
  626. }
  627. private bool ProcessDone()
  628. {
  629. _currentRecipe.Steps[_currentStep].End();
  630. _faCallback.RecipeComplete(Module.ToString(), CurrentRunningRecipe);
  631. RecipeFileManager.Instance.SaveRecipe(Module.ToString(), _currentRecipe.Header.Type.ToString(), _currentRecipe.Header.Name, RecipeUnity.RecipeToString(_currentRecipe), false, false);
  632. _stepTime.Stop();
  633. WaferManager.Instance.UpdateWaferProcessStatus(Module, 0, EnumWaferProcessStatus.Idle);
  634. WaferManager.Instance.UpdateWaferProcessStatus(Module, 0, EnumWaferProcessStatus.Completed);
  635. CloseAllValves();
  636. _chamber.GeneratorSetpower(0);
  637. _chamber.GeneratorBiasSetpower(0);
  638. _chamber.GeneratorBiasPowerOn(false);
  639. _chamber.GeneratorPowerOn(false);
  640. _chamber.OpenValve(ValveType.TurboPumpPumping, true);
  641. _chamber.OpenValve(ValveType.TurboPumpPurge, true);
  642. _chamber.OpenValve(ValveType.Guage, true);
  643. _chamber.SetPVPostion(1000);
  644. switch (_chamber.ChamberType)
  645. {
  646. case JetChamber.VenusSE:
  647. SC.SetItemValue($"{_chamber.Module}.Chiller.EnableToleranceAlarm", false);
  648. if (_chamber.IsHVOn)
  649. {
  650. _chamber.OnOffSetESCHV(false);
  651. }
  652. break;
  653. case JetChamber.VenusDE:
  654. SC.SetItemValue($"{_chamber.Module}.Chiller.EnableToleranceAlarm", false);
  655. SC.SetItemValue($"{_chamber.Module}.WallChiller.EnableToleranceAlarm", false);
  656. if (_chamber.IsHVOn)
  657. {
  658. _chamber.OnOffSetESCHV(false);
  659. }
  660. break;
  661. }
  662. return true;
  663. }
  664. private void UpdateWaferStatus(bool bDone = true)
  665. {
  666. if (bDone == false)
  667. {
  668. WaferManager.Instance.UpdateWaferProcessStatus(Module, 0, EnumWaferProcessStatus.Failed);
  669. if (_currentRecipe.Header.Type == RecipeType.Chuck)
  670. {
  671. // set wafer chucked flag even if the chuck recipe failed.
  672. WaferManager.Instance.UpdateWaferChuckStatus(Module, 0, EnumWaferChuckStatus.Chucked);
  673. }
  674. }
  675. switch (_currentRecipe.Header.Type)
  676. {
  677. case RecipeType.Process:
  678. break;
  679. case RecipeType.Chuck:
  680. WaferManager.Instance.UpdateWaferChuckStatus(Module, 0, EnumWaferChuckStatus.Chucked);
  681. break;
  682. case RecipeType.DeChuck:
  683. WaferManager.Instance.UpdateWaferProcessStatus(Module, 0, EnumWaferProcessStatus.Completed);
  684. WaferManager.Instance.UpdateWaferChuckStatus(Module, 0, EnumWaferChuckStatus.Dechucked);
  685. break;
  686. }
  687. }
  688. public async void Abort()
  689. {
  690. if (_currentRecipe != null)
  691. {
  692. RecipeDone("Abort");
  693. }
  694. WaferManager.Instance.UpdateWaferProcessStatus(Module, 0, EnumWaferProcessStatus.Failed);
  695. _chamber.GeneratorBiasPowerOn(false);
  696. _chamber.GeneratorPowerOn(false);
  697. CloseAllValves();
  698. _chamber.OpenValve(ValveType.TurboPumpPumping, true);
  699. _chamber.OpenValve(ValveType.TurboPumpPurge, true);
  700. if (_chamber.ChamberType == JetChamber.VenusSE || _chamber.ChamberType == JetChamber.VenusDE)
  701. {
  702. _chamber.SetBacksideHeThreshold(0, 0);
  703. _chamber.SetBacksideOutHeThreshold(0, 0);
  704. _chamber.MagnetSetpower(0);
  705. await Task.Delay(2000);
  706. _chamber.OnOffSetESCHV(false);
  707. }
  708. }
  709. }
  710. }