Process.cs 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Xml;
  4. using Aitex.Core.Equipment.SusceptorDefine;
  5. using Aitex.Core.RT.Device;
  6. using Aitex.Core.RT.Event;
  7. using Aitex.Core.RT.Log;
  8. using Aitex.Core.RT.OperationCenter;
  9. using Aitex.Core.RT.RecipeCenter;
  10. using Aitex.Core.RT.Routine;
  11. using Aitex.Core.RT.SCCore;
  12. using Aitex.Core.Util;
  13. using MECF.Framework.Common.DBCore;
  14. using MECF.Framework.Common.Equipment;
  15. using VirgoRT.Devices;
  16. using VirgoRT.Module;
  17. namespace VirgoRT.Modules.PMs
  18. {
  19. class ProcessRoutine : PMRoutineBase
  20. {
  21. private enum RecipeEngineState
  22. {
  23. Error,
  24. RecipeCompleted,
  25. ExecStep,
  26. TimeWait,
  27. EndPointWait,
  28. StepCompleted,
  29. Paused,
  30. }
  31. private object _lockerTotalCycle = new object();
  32. private Dictionary<string, int> _recipeTotalCycle = new Dictionary<string, int>();
  33. private DeviceTimer _beginPauseTimer = new DeviceTimer();
  34. private object _recipeLocker = new object();
  35. private RecipeEngineState _state = RecipeEngineState.ExecStep;
  36. private RecipeEngineState _pausedState = RecipeEngineState.ExecStep;
  37. private DeviceTimer _estimatedTimeCalcTimer = new DeviceTimer();//用于定时计算工艺程序估计的结束时间
  38. public DateTime RecipeStartTime { get; private set; }
  39. public int RecipeChangeNo { get; private set; }
  40. public string CurrentRecipeBaseName { get; private set; }
  41. public string CurrentRecipeRunningName { get; private set; }
  42. public string CurrentRecipeContent { get; private set; }
  43. public string CurrentLotName { get; set; }
  44. public string CurrentRecipeGuid { get; set; }
  45. private List<RecipeStep> _recipeStepList = new List<RecipeStep>();
  46. public List<RecipeStep> CurrentRecipeStepList
  47. {
  48. get
  49. {
  50. return _recipeStepList;
  51. }
  52. set
  53. {
  54. _recipeStepList = value;
  55. }
  56. }
  57. public RecipeHead CurrentRecipeHead { get; set; }
  58. public int CurStepNum { get; private set; }
  59. public int CurStepTotalLoopCount { get; private set; }
  60. public double CurStepTotalTime
  61. {
  62. get
  63. {
  64. if (_recipeStepList == null || _recipeStepList.Count == 0 || _state == RecipeEngineState.RecipeCompleted || _state == RecipeEngineState.Error)
  65. return 0;
  66. return _recipeStepList[CurStepNum].StepTime * 1000;
  67. }
  68. }
  69. public int CurrentLoopCount
  70. {
  71. get;
  72. private set;
  73. }
  74. private DeviceTimer StepTimer = new DeviceTimer();
  75. public bool IsPaused
  76. {
  77. private set;
  78. get;
  79. }
  80. public string CurStepComment
  81. {
  82. get
  83. {
  84. if (_recipeStepList == null || _recipeStepList.Count == 0)
  85. return string.Empty;
  86. return _recipeStepList[CurStepNum].StepName;
  87. }
  88. }
  89. public double CurStepLeftTime
  90. {
  91. get
  92. {
  93. if (IsPaused)
  94. return StepTimer.GetTotalTime() - StepTimer.GetElapseTime() + _beginPauseTimer.GetElapseTime();
  95. //return Math.Max(0,StepTimer.GetTotalTime() - StepTimer.GetElapseTime());
  96. return StepTimer.GetTotalTime() - StepTimer.GetElapseTime();
  97. }
  98. }
  99. public double CurStepElpasedTime
  100. {
  101. get
  102. {
  103. if (_recipeStepList == null || _recipeStepList.Count == 0 || _state == RecipeEngineState.RecipeCompleted || _state == RecipeEngineState.Error)
  104. return 0;
  105. return StepTimer.GetElapseTime();
  106. }
  107. }
  108. public double CurStepTotalRfTime
  109. {
  110. get
  111. {
  112. if (_recipeStepList == null || _recipeStepList.Count == 0 || _state == RecipeEngineState.RecipeCompleted || _state == RecipeEngineState.Error)
  113. return 0;
  114. if (_recipeStepList[CurStepNum].RecipeCommands.ContainsKey("Rf.SetPower") &&
  115. !string.IsNullOrEmpty(_recipeStepList[CurStepNum].RecipeCommands["Rf.SetPower"]) &&
  116. Convert.ToDouble(_recipeStepList[CurStepNum].RecipeCommands["Rf.SetPower"]) > 0.1)
  117. return CurStepTotalTime;
  118. return 0;
  119. }
  120. }
  121. public int TotalCycle
  122. {
  123. get
  124. {
  125. if (string.IsNullOrEmpty(DateTimeRecipeBaseName))
  126. return 0;
  127. lock (_lockerTotalCycle)
  128. {
  129. if (_recipeTotalCycle.ContainsKey(DateTimeRecipeBaseName))
  130. return _recipeTotalCycle[DateTimeRecipeBaseName];
  131. }
  132. return 0;
  133. }
  134. }
  135. public string DateTimeRecipeBaseName
  136. {
  137. get
  138. {
  139. if (string.IsNullOrEmpty(CurrentRecipeBaseName))
  140. return "";
  141. return DateTime.Now.ToString("yyyyMMdd") + CurrentRecipeBaseName;
  142. }
  143. }
  144. public double PausedTime
  145. {
  146. get
  147. {
  148. return IsPaused ? _beginPauseTimer.GetElapseTime() : 0;
  149. }
  150. }
  151. public double EstimatedTotalLeftTime
  152. {
  153. get;
  154. private set;
  155. }
  156. public int RecipeTotalStepNum
  157. {
  158. get
  159. {
  160. return _recipeStepList.Count;
  161. }
  162. }
  163. protected PMEntity _chamberEntity;
  164. private RecipeFACallback _faCallback;
  165. private RecipeDBCallback _dbCallback;
  166. private Fdc _fdc;
  167. public ProcessRoutine(JetPM chamber, PMEntity entity) : base(chamber)
  168. {
  169. Name = "ProcessRoutine";
  170. RecipeStartTime = new DateTime(0);
  171. EstimatedTotalLeftTime = 0;
  172. CalcEstimatedRecipeEndTime();
  173. _chamberEntity = entity;
  174. _faCallback = new RecipeFACallback();
  175. _dbCallback = new RecipeDBCallback();
  176. _fdc = new Fdc(Module);
  177. }
  178. public Result Start(params object[] param)
  179. {
  180. RecipeStartTime = DateTime.Now;
  181. CurrentRecipeBaseName = (string)param[0];
  182. CurrentRecipeRunningName = (string)param[1];
  183. RecipeChangeNo = (int)param[2];
  184. CurrentLotName = (string)param[3];
  185. CurrentRecipeContent = (string)param[4];
  186. CurrentRecipeHead = (RecipeHead)param[5];
  187. CurrentRecipeStepList = (List<RecipeStep>)param[6];
  188. if (!_chamber.IsRFGInterlockOn)
  189. {
  190. EV.PostAlarmLog(Module, "RF Interlock sensor error");
  191. return Result.VERIFYFAIL;
  192. }
  193. lock (_lockerTotalCycle)
  194. {
  195. if (_recipeTotalCycle.ContainsKey(DateTimeRecipeBaseName))
  196. _recipeTotalCycle[DateTimeRecipeBaseName] += 1;
  197. else
  198. {
  199. _recipeTotalCycle[DateTimeRecipeBaseName] = 1;
  200. }
  201. List<string> keys = new List<string>();
  202. foreach (KeyValuePair<string, int> item in _recipeTotalCycle)
  203. {
  204. if (!item.Key.StartsWith(DateTime.Now.ToString("yyyyMMdd")))
  205. keys.Add(item.Key);
  206. }
  207. foreach (string key in keys)
  208. {
  209. _recipeTotalCycle.Remove(key);
  210. }
  211. }
  212. _chamber.SetValveOnOff(ValveType.PROCESS, true);
  213. CurStepNum = CurStepTotalLoopCount = 0;
  214. _estimatedTimeCalcTimer.Start(1000);
  215. EV.PostInfoLog(Module, $"Recipe {CurrentRecipeRunningName} Start running");
  216. _chamberEntity.RecipeRunningInfo.InnerId = Guid.NewGuid();
  217. _chamberEntity.RecipeRunningInfo.BeginTime = DateTime.Now;
  218. _chamberEntity.RecipeRunningInfo.RecipeName = CurrentRecipeBaseName;
  219. _chamberEntity.RecipeRunningInfo.RecipeStepList = CurrentRecipeStepList;
  220. //ProcessDataRecorder.UpdateStatus(RecipeRunGuid.ToString(), SusceptorStatus.InProcessing.ToString(), Module);
  221. _state = RecipeEngineState.ExecStep;
  222. double totalTime = 0;
  223. foreach (var step in CurrentRecipeStepList)
  224. {
  225. totalTime += step.StepTime;
  226. }
  227. _dbCallback.RecipeStart(_chamber.Module.ToString(), 0, _chamberEntity.RecipeRunningInfo.InnerId.ToString(), _chamberEntity.RecipeRunningInfo.RecipeName);
  228. _dbCallback.RecipeUpdateStatus(_chamberEntity.RecipeRunningInfo.InnerId.ToString(), "InProcess", (float)totalTime);
  229. _faCallback.RecipeStart(_chamber.Module.ToString(), CurrentRecipeBaseName);
  230. _fdc.Reset();
  231. _chamberEntity.EndPointRecipeStart(CurrentRecipeBaseName);
  232. return Result.RUN;
  233. }
  234. /// <summary>
  235. /// quiting current state
  236. /// </summary>
  237. /// <param name="nextState"></param>
  238. public void Exit()
  239. {
  240. _chamber.IsPressureToleranceEnabled = false;
  241. var ts = DateTime.Now - RecipeStartTime;
  242. var totalTime = $"{Convert.ToInt32(ts.TotalHours)}:{ts.Minutes}:{ts.Seconds}";
  243. bool isProcessCompleted = _state == RecipeEngineState.RecipeCompleted;
  244. if (isProcessCompleted)
  245. {
  246. EV.PostInfoLog(Module, $"Recipe {CurrentRecipeRunningName} Completed");
  247. _faCallback.RecipeComplete(_chamber.Module.ToString(), CurrentRecipeBaseName);
  248. _dbCallback.RecipeComplete(_chamberEntity.RecipeRunningInfo.InnerId.ToString());
  249. _fdc.Stop();
  250. }
  251. else
  252. {
  253. _faCallback.RecipeFailed(_chamber.Module.ToString(), CurrentRecipeBaseName);
  254. _dbCallback.RecipeFailed(_chamberEntity.RecipeRunningInfo.InnerId.ToString());
  255. _chamberEntity.StopEndPoint();
  256. string info = string.Format("Recipe:{0}\r\nStart time:{1:yyyy/MM/dd HH:mm:ss}\r\nEnd time:{2:yyyy/MM/dd HH:mm:ss}\r\nTotal time:{3}",
  257. CurrentRecipeRunningName, RecipeStartTime, DateTime.Now, totalTime);
  258. EV.PostWarningLog(Module, info);
  259. EV.PostPopDialogMessage(EventLevel.Warning, $"{Module} recipe was aborted", info);
  260. }
  261. _chamberEntity.EndPointRecipeStop();
  262. //重置工艺程序名
  263. CurrentRecipeRunningName = string.Empty;
  264. CurrentLotName = string.Empty;
  265. }
  266. public Result Monitor()
  267. {
  268. string reason = string.Empty;
  269. CalcEstimatedRecipeEndTime();
  270. //工艺程序运行监控,自动打开阀门如果对应的MFC设定设置大于0
  271. _chamber.Monitor();
  272. if (_chamber.IsError)
  273. return Result.FAIL;
  274. //工艺程序运行引擎
  275. lock (_recipeLocker)
  276. {
  277. try
  278. {
  279. switch (_state)
  280. {
  281. case RecipeEngineState.ExecStep:
  282. {
  283. //工艺程序循环设置
  284. if (_recipeStepList[CurStepNum].IsLoopStartStep)
  285. {
  286. CurStepTotalLoopCount = _recipeStepList[CurStepNum].LoopCount;
  287. if (CurStepTotalLoopCount == 0)
  288. {
  289. CurrentLoopCount = 0;
  290. }
  291. else
  292. {
  293. CurrentLoopCount++;
  294. }
  295. }
  296. //当前工艺程序步的定时器设定
  297. StepTimer.Start(_recipeStepList[CurStepNum].StepTime * 1000);
  298. //发送信息到用户界面
  299. EV.PostInfoLog(Module, $"Recipe {CurrentRecipeRunningName} No {CurStepNum + 1} step start:{_recipeStepList[CurStepNum].StepName}");
  300. //执行工艺程序命令
  301. foreach (var cmdkey in _recipeStepList[CurStepNum].RecipeCommands.Keys)
  302. {
  303. string recipeCmd = cmdkey;
  304. string param = _recipeStepList[CurStepNum].RecipeCommands[recipeCmd];
  305. if (string.IsNullOrWhiteSpace(param)) continue;
  306. if (recipeCmd == "EPD.SetConfig" && !SC.GetValue<bool>($"{Module}.EPD.IsEnabled"))
  307. continue;
  308. if (!OP.CanDoOperation($"{Module}." + recipeCmd, out reason, param))
  309. {
  310. EV.PostAlarmLog(Module, $"Can not do {recipeCmd}, {reason}");
  311. return Result.FAIL;
  312. }
  313. else
  314. {
  315. var rampTime_ms = (int)(_recipeStepList[CurStepNum].StepTime * 1000);
  316. if (_recipeStepList[CurStepNum].IsJumpStep)
  317. rampTime_ms = 0;
  318. if (recipeCmd == "EPD.SetConfig")
  319. {
  320. if(SC.GetValue<bool>($"{Module}.EPD.IsEnabled"))
  321. OP.DoOperation($"{Module}." + recipeCmd, out string reason1, rampTime_ms, CurStepNum, _recipeStepList[CurStepNum].RecipeCommands[recipeCmd]);
  322. }
  323. else
  324. {
  325. OP.DoOperation($"{Module}." + recipeCmd, out string reason1, rampTime_ms, param);
  326. }
  327. }
  328. }
  329. string endby = _recipeStepList[CurStepNum].EndBy;
  330. if (!string.IsNullOrEmpty(endby) && endby == "EndByEndPoint")
  331. {
  332. _state = RecipeEngineState.EndPointWait;
  333. }
  334. else
  335. {
  336. _state = RecipeEngineState.TimeWait;
  337. }
  338. _faCallback.RecipeStepStart(_chamber.Module.ToString(), CurrentRecipeBaseName, CurStepNum);
  339. _dbCallback.RecipeStepStart(_chamberEntity.RecipeRunningInfo.InnerId.ToString(), CurStepNum, _chamberEntity.RecipeRunningInfo.RecipeStepList[CurStepNum].StepName, (float)_chamberEntity.RecipeRunningInfo.RecipeStepList[CurStepNum].StepTime);
  340. _fdc.Start(_chamberEntity.RecipeRunningInfo.RecipeStepList[CurStepNum].RecipeCommands);
  341. }
  342. break;
  343. case RecipeEngineState.TimeWait:
  344. _chamber.CheckPressureStability();
  345. if (StepTimer.IsTimeout())
  346. {
  347. _state = RecipeEngineState.StepCompleted;
  348. }
  349. break;
  350. case RecipeEngineState.EndPointWait:
  351. {
  352. if (_chamberEntity.CheckEndPoint())
  353. {
  354. _state = RecipeEngineState.StepCompleted;
  355. }
  356. if (StepTimer.IsTimeout())
  357. {
  358. if (_recipeStepList[CurStepNum].FaultIfNoEPDTrigger)
  359. {
  360. EV.PostAlarmLog(Module, $"{_chamberEntity.Module} EPD step not triggered, timeout");
  361. return Result.FAIL;
  362. }
  363. else
  364. {
  365. EV.PostWarningLog(Module, $"{_chamberEntity.Module} EPD step not triggered, skipped");
  366. }
  367. _state = RecipeEngineState.StepCompleted;
  368. }
  369. }
  370. break;
  371. case RecipeEngineState.Paused:
  372. break;
  373. case RecipeEngineState.StepCompleted:
  374. {
  375. EV.PostInfoLog(Module, $"Recipe {CurrentRecipeRunningName} No {CurStepNum + 1} step completed");
  376. _chamberEntity.StopEndPoint();
  377. _faCallback.RecipeStepEnd(_chamber.Module.ToString(), CurrentRecipeBaseName, CurStepNum, _fdc.DataList);
  378. _dbCallback.RecipeStepEnd(_chamberEntity.RecipeRunningInfo.InnerId.ToString(), CurStepNum, _fdc.DataList);
  379. _fdc.Stop();
  380. //判断是否当前步循环终止
  381. if (_recipeStepList[CurStepNum].IsLoopEndStep)
  382. {
  383. //重新读取循环的设定次数
  384. for (int nn = CurStepNum; nn >= 0; nn--)
  385. {
  386. if (_recipeStepList[nn].IsLoopStartStep)
  387. {
  388. CurStepTotalLoopCount = _recipeStepList[nn].LoopCount;
  389. break;
  390. }
  391. }
  392. if (CurrentLoopCount >= CurStepTotalLoopCount)
  393. {
  394. CurrentLoopCount = CurStepTotalLoopCount = 0;
  395. //CurStepNum++;
  396. if (CurStepNum < _recipeStepList.Count - 1)
  397. {
  398. CurStepNum++;
  399. _state = RecipeEngineState.ExecStep;
  400. }
  401. else
  402. {
  403. EV.PostInfoLog(Module, $"工艺 {CurrentRecipeRunningName} 完毕");
  404. CurStepNum = _recipeStepList.Count - 1;
  405. _state = RecipeEngineState.RecipeCompleted;
  406. return Result.DONE;
  407. }
  408. }
  409. else
  410. {
  411. int n = CurStepNum - 1;
  412. int next = -1;
  413. while (n >= 0)
  414. {
  415. if (_recipeStepList[n].IsLoopStartStep)
  416. {
  417. next = n;
  418. break;
  419. }
  420. n--;
  421. }
  422. if (next == -1)
  423. throw new Exception("Loop End control error");
  424. CurStepNum = next;
  425. _state = RecipeEngineState.ExecStep;
  426. }
  427. }
  428. else
  429. {
  430. if (CurStepNum < _recipeStepList.Count - 1)
  431. {
  432. CurStepNum++;
  433. _state = RecipeEngineState.ExecStep;
  434. }
  435. else
  436. {
  437. EV.PostInfoLog(Module, $"Recipe {CurrentRecipeRunningName} finish");
  438. CurStepNum = _recipeStepList.Count - 1;
  439. _state = RecipeEngineState.RecipeCompleted;
  440. return Result.DONE;
  441. }
  442. }
  443. }
  444. break;
  445. case RecipeEngineState.RecipeCompleted:
  446. return Result.DONE;
  447. case RecipeEngineState.Error:
  448. return Result.FAIL;
  449. default:
  450. break;
  451. }
  452. }
  453. catch (Exception ex)
  454. {
  455. EV.PostAlarmLog(Module, $"{CurStepNum + 1}, grammar error, {ex.Message}");
  456. return Result.FAIL;
  457. }
  458. }
  459. return Result.RUN;
  460. }
  461. /// <summary>
  462. /// 暂停工艺程序运行
  463. /// </summary>
  464. public void PauseRecipe()
  465. {
  466. if (_state != RecipeEngineState.TimeWait && _state != RecipeEngineState.EndPointWait)
  467. return;
  468. if (!IsPaused)
  469. {
  470. string reason = string.Empty;
  471. IsPaused = true;
  472. _pausedState = _state;
  473. _state = RecipeEngineState.Paused;
  474. _beginPauseTimer.Start(0);
  475. EV.PostInfoLog(Module, $"Recipe'{CurrentRecipeRunningName}' No {CurStepNum + 1} step pause");
  476. }
  477. }
  478. /// <summary>
  479. /// 恢复工艺程序运行
  480. /// </summary>
  481. public void ResumeRecipe()
  482. {
  483. if (IsPaused)
  484. {
  485. //update current recipe step time
  486. string recipeXml = CurrentRecipeContent;
  487. int currentStepNo = CurStepNum;
  488. XmlDocument xmlDoc = new XmlDocument();
  489. xmlDoc.LoadXml(recipeXml);
  490. var stepNodes = xmlDoc.SelectNodes("/TableRecipeData/Step");
  491. if (currentStepNo >= 0 && currentStepNo < stepNodes.Count)
  492. {
  493. var curStepNode = stepNodes[currentStepNo] as XmlElement;
  494. var curStepNewTime = CurStepTotalTime + PausedTime;
  495. if (curStepNewTime < 0)
  496. curStepNewTime = 0;
  497. TimeSpan tspan = new TimeSpan(0, 0, 0, 0, (int)curStepNewTime);
  498. var timeString =
  499. $"{((int)tspan.TotalHours).ToString("00")}:{tspan.Minutes.ToString("00")}:{tspan.Seconds.ToString("00")}";
  500. curStepNode.SetAttribute("Time", timeString);
  501. LOG.Write($"Execute Resume command,Change the current{currentStepNo}time to{timeString}");
  502. UpdateRecipe(xmlDoc.OuterXml);
  503. }
  504. //Resume recipe
  505. IsPaused = false;
  506. _state = _pausedState;
  507. EV.PostInfoLog(Module, $"Recipe'{CurrentRecipeRunningName}' No {CurStepNum + 1} step continue");
  508. //resume recipe
  509. double stepElapsedTime = StepTimer.GetElapseTime() - _beginPauseTimer.GetElapseTime();
  510. double stepLeftTime = StepTimer.GetTotalTime() - stepElapsedTime;
  511. if (stepLeftTime < 0)
  512. stepLeftTime = 0;
  513. //更新当前步的定时器时间
  514. StepTimer.Restart(StepTimer.GetTotalTime() + _beginPauseTimer.GetElapseTime());
  515. //重新执行当前工艺程序步
  516. foreach (var recipeCmd in _recipeStepList[CurStepNum].RecipeCommands.Keys)
  517. {
  518. if (!DEVICE.CanDo(recipeCmd))
  519. {
  520. EV.PostInfoLog(Module, $"Unknown recipe command {recipeCmd}");
  521. }
  522. else
  523. {
  524. var rampTime_ms = (int)(_recipeStepList[CurStepNum].StepTime * 1000);
  525. if (_recipeStepList[CurStepNum].IsJumpStep)
  526. rampTime_ms = 0;
  527. DEVICE.Do(recipeCmd, rampTime_ms, false, _recipeStepList[CurStepNum].RecipeCommands[recipeCmd]);
  528. }
  529. }
  530. }
  531. }
  532. /// <summary>
  533. /// 终止工艺程序运行
  534. /// </summary>
  535. public void AbortRecipe()
  536. {
  537. ResumeRecipe();
  538. _chamberEntity.StopEndPoint();
  539. _state = RecipeEngineState.Error;
  540. CalcEstimatedRecipeEndTime();
  541. _faCallback.RecipeFailed(_chamber.Module.ToString(), CurrentRecipeBaseName);
  542. _dbCallback.RecipeFailed(_chamberEntity.RecipeRunningInfo.InnerId.ToString());
  543. _fdc.Stop();
  544. EV.PostInfoLog(Module, "Receipe abort");
  545. }
  546. /// <summary>
  547. /// 跳至工艺程序下一步
  548. /// </summary>
  549. public void SkipCurrentRecipeStep()
  550. {
  551. if (_state == RecipeEngineState.Paused)
  552. {
  553. EV.PostInfoLog(Module, "Can not do Skip to next step command at the recipe Pause status");
  554. return;
  555. }
  556. try
  557. {
  558. //update current recipe step time
  559. string recipeXml = CurrentRecipeContent;
  560. int currentStepNo = CurStepNum;
  561. XmlDocument xmlDoc = new XmlDocument();
  562. xmlDoc.LoadXml(recipeXml);
  563. var stepNodes = xmlDoc.SelectNodes("/TableRecipeData/Step");
  564. if (currentStepNo >= 0 && currentStepNo < stepNodes.Count)
  565. {
  566. var curStepNode = stepNodes[currentStepNo] as XmlElement;
  567. var curStepElapsedTime = CurStepTotalTime - CurStepLeftTime;//ms
  568. if (curStepElapsedTime < 0)
  569. curStepElapsedTime = 0;
  570. //TimeSpan tspan = new TimeSpan(0, 0, 0, 0, (int)curStepElapsedTime);
  571. //var timeString =
  572. // $"{((int)tspan.TotalHours).ToString("00")}:{tspan.Minutes.ToString("00")}:{tspan.Seconds.ToString("00")}";
  573. string timeString = ((int)(curStepElapsedTime / 1000)).ToString();
  574. curStepNode.SetAttribute("Time", timeString);
  575. LOG.Write($"step skipped,step {currentStepNo} time changed to {timeString}");
  576. //recipe update command
  577. UpdateRecipe(xmlDoc.OuterXml);
  578. }
  579. }
  580. catch (Exception ex)
  581. {
  582. LOG.Write(ex);
  583. }
  584. if (_state == RecipeEngineState.EndPointWait || _state == RecipeEngineState.TimeWait)
  585. {
  586. _state = RecipeEngineState.StepCompleted;
  587. //send informational event
  588. EV.PostMessage(Module, EventEnum.GeneralInfo, Module, CurrentRecipeRunningName, CurStepNum + 1);
  589. }
  590. }
  591. public bool UpdateRecipe(string newRecipeContent)
  592. {
  593. lock (_recipeLocker)
  594. {
  595. RecipeHead head = null;
  596. List<RecipeStep> newRecipeData = null;
  597. if (!Recipe.Parse(Module, newRecipeContent, out head, out newRecipeData))
  598. {
  599. EV.PostMessage(Module, EventEnum.DefaultAlarm, Module, CurrentRecipeRunningName);
  600. return false;
  601. }
  602. else
  603. {
  604. string oldRecipeName = CurrentRecipeRunningName;
  605. CurrentRecipeRunningName =
  606. $"{DateTime.Now:yyyyMMddHHmmss}-{CurrentRecipeBaseName}-({RecipeChangeNo++})";
  607. //update local recipe data
  608. _recipeStepList = newRecipeData;
  609. CurrentRecipeContent = newRecipeContent;
  610. //send informational event
  611. EV.PostInfoLog(Module, $"Recipe'{oldRecipeName}' No {CurStepNum + 1} step,update recipe content '{CurrentRecipeRunningName}");
  612. RecipeFileManager.Instance.SaveRecipeHistory(ModuleName.System.ToString(), CurrentRecipeRunningName, CurrentRecipeContent);
  613. }
  614. }
  615. return true;
  616. }
  617. public override void Abort()
  618. {
  619. _dbCallback.RecipeFailed(_chamberEntity.RecipeRunningInfo.InnerId.ToString() );
  620. base.Abort();
  621. }
  622. public override string ToString()
  623. {
  624. return "recipe running";
  625. }
  626. /// <summary>
  627. /// 工艺程序估计结束时间计算
  628. /// </summary>
  629. protected void CalcEstimatedRecipeEndTime()
  630. {
  631. try
  632. {
  633. //(*计算当前工艺程序预计所需的总时间,从当前步开始计算剩余步的估算时间+已经既成事实的时间 => 总的估计时间,采用该种方式进行总工艺时间理论上最为精确*)
  634. if (!_estimatedTimeCalcTimer.IsTimeout())
  635. return;
  636. _estimatedTimeCalcTimer.Start(1000);
  637. EstimatedTotalLeftTime = 0;
  638. if (_state == RecipeEngineState.RecipeCompleted)
  639. return;
  640. if (!(CurStepNum >= 0 && CurStepNum <= _recipeStepList.Count - 1))
  641. return;
  642. if (CurStepLeftTime > 0)
  643. {
  644. EstimatedTotalLeftTime = CurStepLeftTime;
  645. }
  646. int nextBegin = CurStepNum;
  647. //(*判断当前是否处于循环之中*)
  648. bool IsInLoop = false;
  649. int iNum1 = 0;
  650. int iNum2 = 0;
  651. //int j=i;
  652. for (int j = CurStepNum; j < _recipeStepList.Count; j++)
  653. {
  654. if (_recipeStepList[j].IsLoopEndStep)
  655. {
  656. iNum2 = j;
  657. IsInLoop = true;
  658. break;
  659. }
  660. else if (j > CurStepNum && _recipeStepList[j].IsLoopStartStep)
  661. {
  662. IsInLoop = false;
  663. break;
  664. }
  665. }
  666. if (IsInLoop)
  667. {
  668. //(*当前步处于循环中*)
  669. iNum1 = CurStepNum;
  670. for (int j = CurStepNum; j >= 0; j--)
  671. {
  672. if (_recipeStepList[j].IsLoopStartStep)
  673. {
  674. iNum1 = j;
  675. break;
  676. }
  677. }
  678. for (int j = CurStepNum + 1; j <= iNum2; j++)
  679. {
  680. EstimatedTotalLeftTime += _recipeStepList[j].StepTime * 1000 * (_recipeStepList[iNum1].LoopCount - CurrentLoopCount + 1);
  681. }
  682. for (int j = iNum1; j <= CurStepNum; j++)
  683. {
  684. EstimatedTotalLeftTime += _recipeStepList[j].StepTime * 1000 * (_recipeStepList[iNum1].LoopCount - CurrentLoopCount);
  685. }
  686. nextBegin = iNum2 + 1;
  687. }
  688. else
  689. {
  690. nextBegin++;
  691. }
  692. //(*当前步处于循环外*)
  693. for (int j = nextBegin; j < _recipeStepList.Count; j++)
  694. {
  695. if (_recipeStepList[j].IsLoopStartStep)
  696. {
  697. //j=i;
  698. iNum1 = j;
  699. iNum2 = j + 1;
  700. double lr1 = 0;
  701. for (int m = j; m < _recipeStepList.Count; m++)
  702. {
  703. lr1 += _recipeStepList[m].StepTime * 1000;
  704. if (_recipeStepList[m].IsLoopEndStep)
  705. {
  706. iNum2 = m;
  707. break;
  708. }
  709. }
  710. EstimatedTotalLeftTime = EstimatedTotalLeftTime + lr1 * _recipeStepList[iNum1].LoopCount;
  711. j = iNum2;
  712. }
  713. else
  714. {
  715. EstimatedTotalLeftTime += _recipeStepList[j].StepTime * 1000;
  716. }
  717. //END_WHILE
  718. }
  719. }
  720. catch (Exception ex)
  721. {
  722. LOG.Write(ex);
  723. }
  724. }
  725. public class RecipeRunningInfo
  726. {
  727. public Guid InnerId { get; set; }
  728. public RecipeHead Head { get; set; }
  729. public List<RecipeStep> RecipeStepList { get; set; }
  730. public string RecipeName { get; set; }
  731. public DateTime BeginTime { get; set; }
  732. public DateTime EndTime { get; set; }
  733. public int StepNumber { get; set; }
  734. public string StepName { get; set; }
  735. public double StepTime { get; set; }
  736. public double StepElapseTime { get; set; }
  737. public double TotalTime { get; set; }
  738. public double TotalElapseTime { get; set; }
  739. }
  740. }
  741. }