Process.cs 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892
  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. }
  397. else
  398. {
  399. int n = CurStepNum - 1;
  400. int next = -1;
  401. while (n >= 0)
  402. {
  403. if (_recipeStepList[n].IsLoopStartStep)
  404. {
  405. next = n;
  406. break;
  407. }
  408. n--;
  409. }
  410. if (next == -1)
  411. throw new Exception("Loop End control error");
  412. CurStepNum = next;
  413. }
  414. }
  415. else
  416. {
  417. if (CurStepNum < _recipeStepList.Count - 1)
  418. {
  419. CurStepNum++;
  420. _state = RecipeEngineState.ExecStep;
  421. }
  422. else
  423. {
  424. EV.PostInfoLog(Module, $"Recipe {CurrentRecipeRunningName} finish");
  425. CurStepNum = _recipeStepList.Count - 1;
  426. _state = RecipeEngineState.RecipeCompleted;
  427. return Result.DONE;
  428. }
  429. }
  430. }
  431. break;
  432. case RecipeEngineState.RecipeCompleted:
  433. return Result.DONE;
  434. case RecipeEngineState.Error:
  435. return Result.FAIL;
  436. default:
  437. break;
  438. }
  439. }
  440. catch (Exception ex)
  441. {
  442. EV.PostAlarmLog(Module, $"{CurStepNum + 1}, grammar error, {ex.Message}");
  443. return Result.FAIL;
  444. }
  445. }
  446. return Result.RUN;
  447. }
  448. /// <summary>
  449. /// 暂停工艺程序运行
  450. /// </summary>
  451. public void PauseRecipe()
  452. {
  453. if (_state != RecipeEngineState.TimeWait && _state != RecipeEngineState.EndPointWait)
  454. return;
  455. if (!IsPaused)
  456. {
  457. string reason = string.Empty;
  458. IsPaused = true;
  459. _pausedState = _state;
  460. _state = RecipeEngineState.Paused;
  461. _beginPauseTimer.Start(0);
  462. EV.PostInfoLog(Module, $"Recipe'{CurrentRecipeRunningName}' No {CurStepNum + 1} step pause");
  463. }
  464. }
  465. /// <summary>
  466. /// 恢复工艺程序运行
  467. /// </summary>
  468. public void ResumeRecipe()
  469. {
  470. if (IsPaused)
  471. {
  472. //update current recipe step time
  473. string recipeXml = CurrentRecipeContent;
  474. int currentStepNo = CurStepNum;
  475. XmlDocument xmlDoc = new XmlDocument();
  476. xmlDoc.LoadXml(recipeXml);
  477. var stepNodes = xmlDoc.SelectNodes("/TableRecipeData/Step");
  478. if (currentStepNo >= 0 && currentStepNo < stepNodes.Count)
  479. {
  480. var curStepNode = stepNodes[currentStepNo] as XmlElement;
  481. var curStepNewTime = CurStepTotalTime + PausedTime;
  482. if (curStepNewTime < 0)
  483. curStepNewTime = 0;
  484. TimeSpan tspan = new TimeSpan(0, 0, 0, 0, (int)curStepNewTime);
  485. var timeString =
  486. $"{((int)tspan.TotalHours).ToString("00")}:{tspan.Minutes.ToString("00")}:{tspan.Seconds.ToString("00")}";
  487. curStepNode.SetAttribute("Time", timeString);
  488. LOG.Write($"执行Resume命令,将当前第{currentStepNo}步时间修改为{timeString}");
  489. UpdateRecipe(xmlDoc.OuterXml);
  490. }
  491. //Resume recipe
  492. IsPaused = false;
  493. _state = _pausedState;
  494. EV.PostInfoLog(Module, $"Recipe'{CurrentRecipeRunningName}' No {CurStepNum + 1} step continue");
  495. //resume recipe
  496. double stepElapsedTime = StepTimer.GetElapseTime() - _beginPauseTimer.GetElapseTime();
  497. double stepLeftTime = StepTimer.GetTotalTime() - stepElapsedTime;
  498. if (stepLeftTime < 0)
  499. stepLeftTime = 0;
  500. //更新当前步的定时器时间
  501. StepTimer.Restart(StepTimer.GetTotalTime() + _beginPauseTimer.GetElapseTime());
  502. //重新执行当前工艺程序步
  503. foreach (var recipeCmd in _recipeStepList[CurStepNum].RecipeCommands.Keys)
  504. {
  505. if (!DEVICE.CanDo(recipeCmd))
  506. {
  507. EV.PostInfoLog(Module, $"Unknown recipe command {recipeCmd}");
  508. }
  509. else
  510. {
  511. var rampTime_ms = (int)(_recipeStepList[CurStepNum].StepTime * 1000);
  512. if (_recipeStepList[CurStepNum].IsJumpStep)
  513. rampTime_ms = 0;
  514. DEVICE.Do(recipeCmd, rampTime_ms, false, _recipeStepList[CurStepNum].RecipeCommands[recipeCmd]);
  515. }
  516. }
  517. }
  518. }
  519. /// <summary>
  520. /// 终止工艺程序运行
  521. /// </summary>
  522. public void AbortRecipe()
  523. {
  524. ResumeRecipe();
  525. _chamberEntity.StopEndPoint();
  526. _state = RecipeEngineState.Error;
  527. CalcEstimatedRecipeEndTime();
  528. _faCallback.RecipeFailed(_chamber.Module.ToString(), CurrentRecipeBaseName);
  529. _dbCallback.RecipeFailed(_chamberEntity.RecipeRunningInfo.InnerId.ToString());
  530. _fdc.Stop();
  531. EV.PostInfoLog(Module, "Receipe abort");
  532. }
  533. /// <summary>
  534. /// 跳至工艺程序下一步
  535. /// </summary>
  536. public void SkipCurrentRecipeStep()
  537. {
  538. if (_state == RecipeEngineState.Paused)
  539. {
  540. EV.PostInfoLog(Module, "Can not do Skip to next step command at the recipe Pause status");
  541. return;
  542. }
  543. try
  544. {
  545. //update current recipe step time
  546. string recipeXml = CurrentRecipeContent;
  547. int currentStepNo = CurStepNum;
  548. XmlDocument xmlDoc = new XmlDocument();
  549. xmlDoc.LoadXml(recipeXml);
  550. var stepNodes = xmlDoc.SelectNodes("/TableRecipeData/Step");
  551. if (currentStepNo >= 0 && currentStepNo < stepNodes.Count)
  552. {
  553. var curStepNode = stepNodes[currentStepNo] as XmlElement;
  554. var curStepElapsedTime = CurStepTotalTime - CurStepLeftTime;//ms
  555. if (curStepElapsedTime < 0)
  556. curStepElapsedTime = 0;
  557. //TimeSpan tspan = new TimeSpan(0, 0, 0, 0, (int)curStepElapsedTime);
  558. //var timeString =
  559. // $"{((int)tspan.TotalHours).ToString("00")}:{tspan.Minutes.ToString("00")}:{tspan.Seconds.ToString("00")}";
  560. string timeString = ((int)(curStepElapsedTime / 1000)).ToString();
  561. curStepNode.SetAttribute("Time", timeString);
  562. LOG.Write($"step skipped,step {currentStepNo} time changed to {timeString}");
  563. //recipe update command
  564. UpdateRecipe(xmlDoc.OuterXml);
  565. }
  566. }
  567. catch (Exception ex)
  568. {
  569. LOG.Write(ex);
  570. }
  571. if (_state == RecipeEngineState.EndPointWait || _state == RecipeEngineState.TimeWait)
  572. {
  573. _state = RecipeEngineState.StepCompleted;
  574. //send informational event
  575. EV.PostMessage(Module, EventEnum.GeneralInfo, Module, CurrentRecipeRunningName, CurStepNum + 1);
  576. }
  577. }
  578. public bool UpdateRecipe(string newRecipeContent)
  579. {
  580. lock (_recipeLocker)
  581. {
  582. RecipeHead head = null;
  583. List<RecipeStep> newRecipeData = null;
  584. if (!Recipe.Parse(Module, newRecipeContent, out head, out newRecipeData))
  585. {
  586. EV.PostMessage(Module, EventEnum.DefaultAlarm, Module, CurrentRecipeRunningName);
  587. return false;
  588. }
  589. else
  590. {
  591. string oldRecipeName = CurrentRecipeRunningName;
  592. CurrentRecipeRunningName =
  593. $"{DateTime.Now:yyyyMMddHHmmss}-{CurrentRecipeBaseName}-({RecipeChangeNo++})";
  594. //update local recipe data
  595. _recipeStepList = newRecipeData;
  596. CurrentRecipeContent = newRecipeContent;
  597. //send informational event
  598. EV.PostInfoLog(Module, $"Recipe'{oldRecipeName}' No {CurStepNum + 1} step,update recipe content '{CurrentRecipeRunningName}");
  599. RecipeFileManager.Instance.SaveRecipeHistory(ModuleName.System.ToString(), CurrentRecipeRunningName, CurrentRecipeContent);
  600. }
  601. }
  602. return true;
  603. }
  604. public override void Abort()
  605. {
  606. _dbCallback.RecipeFailed(_chamberEntity.RecipeRunningInfo.InnerId.ToString() );
  607. base.Abort();
  608. }
  609. public override string ToString()
  610. {
  611. return "recipe running";
  612. }
  613. /// <summary>
  614. /// 工艺程序估计结束时间计算
  615. /// </summary>
  616. protected void CalcEstimatedRecipeEndTime()
  617. {
  618. try
  619. {
  620. //(*计算当前工艺程序预计所需的总时间,从当前步开始计算剩余步的估算时间+已经既成事实的时间 => 总的估计时间,采用该种方式进行总工艺时间理论上最为精确*)
  621. if (!_estimatedTimeCalcTimer.IsTimeout())
  622. return;
  623. _estimatedTimeCalcTimer.Start(1000);
  624. EstimatedTotalLeftTime = 0;
  625. if (_state == RecipeEngineState.RecipeCompleted)
  626. return;
  627. if (!(CurStepNum >= 0 && CurStepNum <= _recipeStepList.Count - 1))
  628. return;
  629. if (CurStepLeftTime > 0)
  630. {
  631. EstimatedTotalLeftTime = CurStepLeftTime;
  632. }
  633. int nextBegin = CurStepNum;
  634. //(*判断当前是否处于循环之中*)
  635. bool IsInLoop = false;
  636. int iNum1 = 0;
  637. int iNum2 = 0;
  638. //int j=i;
  639. for (int j = CurStepNum; j < _recipeStepList.Count; j++)
  640. {
  641. if (_recipeStepList[j].IsLoopEndStep)
  642. {
  643. iNum2 = j;
  644. IsInLoop = true;
  645. break;
  646. }
  647. else if (j > CurStepNum && _recipeStepList[j].IsLoopStartStep)
  648. {
  649. IsInLoop = false;
  650. break;
  651. }
  652. }
  653. if (IsInLoop)
  654. {
  655. //(*当前步处于循环中*)
  656. iNum1 = CurStepNum;
  657. for (int j = CurStepNum; j >= 0; j--)
  658. {
  659. if (_recipeStepList[j].IsLoopStartStep)
  660. {
  661. iNum1 = j;
  662. break;
  663. }
  664. }
  665. for (int j = CurStepNum + 1; j <= iNum2; j++)
  666. {
  667. EstimatedTotalLeftTime += _recipeStepList[j].StepTime * 1000 * (_recipeStepList[iNum1].LoopCount - CurrentLoopCount + 1);
  668. }
  669. for (int j = iNum1; j <= CurStepNum; j++)
  670. {
  671. EstimatedTotalLeftTime += _recipeStepList[j].StepTime * 1000 * (_recipeStepList[iNum1].LoopCount - CurrentLoopCount);
  672. }
  673. nextBegin = iNum2 + 1;
  674. }
  675. else
  676. {
  677. nextBegin++;
  678. }
  679. //(*当前步处于循环外*)
  680. for (int j = nextBegin; j < _recipeStepList.Count; j++)
  681. {
  682. if (_recipeStepList[j].IsLoopStartStep)
  683. {
  684. //j=i;
  685. iNum1 = j;
  686. iNum2 = j + 1;
  687. double lr1 = 0;
  688. for (int m = j; m < _recipeStepList.Count; m++)
  689. {
  690. lr1 += _recipeStepList[m].StepTime * 1000;
  691. if (_recipeStepList[m].IsLoopEndStep)
  692. {
  693. iNum2 = m;
  694. break;
  695. }
  696. }
  697. EstimatedTotalLeftTime = EstimatedTotalLeftTime + lr1 * _recipeStepList[iNum1].LoopCount;
  698. j = iNum2;
  699. }
  700. else
  701. {
  702. EstimatedTotalLeftTime += _recipeStepList[j].StepTime * 1000;
  703. }
  704. //END_WHILE
  705. }
  706. }
  707. catch (Exception ex)
  708. {
  709. LOG.Write(ex);
  710. }
  711. }
  712. public class RecipeRunningInfo
  713. {
  714. public Guid InnerId { get; set; }
  715. public RecipeHead Head { get; set; }
  716. public List<RecipeStep> RecipeStepList { get; set; }
  717. public string RecipeName { get; set; }
  718. public DateTime BeginTime { get; set; }
  719. public DateTime EndTime { get; set; }
  720. public int StepNumber { get; set; }
  721. public string StepName { get; set; }
  722. public double StepTime { get; set; }
  723. public double StepElapseTime { get; set; }
  724. public double TotalTime { get; set; }
  725. public double TotalElapseTime { get; set; }
  726. }
  727. }
  728. }