Process.cs 87 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793
  1. using Aitex.Core.Common;
  2. using Aitex.Core.RT.Event;
  3. using Aitex.Core.RT.Log;
  4. using Aitex.Core.RT.OperationCenter;
  5. using Aitex.Core.RT.Routine;
  6. using Aitex.Core.RT.SCCore;
  7. using Aitex.Core.Util;
  8. using MECF.Framework.Common.DBCore;
  9. using MECF.Framework.Common.Equipment;
  10. using MECF.Framework.Common.Alarms;
  11. using MECF.Framework.Common.Event;
  12. using MECF.Framework.Common.SubstrateTrackings;
  13. using System;
  14. using System.Collections.Generic;
  15. using FurnaceRT.Equipments.PMs.Routines;
  16. using System.Diagnostics;
  17. namespace FurnaceRT.Equipments.PMs.RecipeExecutions
  18. {
  19. public enum RecipeContinueMode
  20. {
  21. None,
  22. WaferReturnAndJobStop,
  23. RecipeCompleted,
  24. StepContinue,
  25. StepRestart,
  26. RecipeRestart,
  27. NextStep,
  28. }
  29. public class Process : PMBaseRoutine
  30. {
  31. enum RecipeRunningState
  32. {
  33. Error,
  34. RecipeCompleted,
  35. ExecStep,
  36. TimeWait,
  37. ConditionWait,
  38. StepCompleted,
  39. Paused,
  40. }
  41. enum RecipeAlaramAction
  42. {
  43. None,
  44. JumpAbortRecipe,
  45. JumpStep,
  46. JumpStepCancelCallLoop,
  47. Abort,
  48. Hold,
  49. IgnoreAlaram,
  50. }
  51. private object _recipeLocker = new object();
  52. private RecipeRunningState _state = RecipeRunningState.ExecStep;
  53. private RecipeRunningState _pausedState = RecipeRunningState.ExecStep;
  54. private double _curStepElpasedTimeBeforePaused;
  55. private double _holdTimeElpasedTime;
  56. private double _waferTimeElpasedTimeBeforPaused;
  57. private double _totalElpasedTime;
  58. public RecipeContinueMode ContinueAction { get; set; }
  59. public DateTime _recipeStartTime
  60. {
  61. get;
  62. private set;
  63. }
  64. public string CurrentRecipeContent { get; private set; }
  65. private int _currentStepNumber;
  66. private int _currentSubRecipeStepNumber;
  67. private bool _loopEnd;
  68. public int CurStepTotalLoopCount
  69. {
  70. get;
  71. private set;
  72. }
  73. public int CurSubRecipeStepTotalLoopCount
  74. {
  75. get;
  76. private set;
  77. }
  78. public double CurStepTotalTime
  79. {
  80. get
  81. {
  82. if (PMModule.RecipeRunningInfo.RecipeStepList == null || PMModule.RecipeRunningInfo.RecipeStepList.Count == 0 || _state == RecipeRunningState.RecipeCompleted || _state == RecipeRunningState.Error)
  83. return 0;
  84. return PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].StepTime * 1000;
  85. }
  86. }
  87. public int CurrentLoopCount
  88. {
  89. get;
  90. private set;
  91. }
  92. public int CurrentAbortRecipeLoopCount
  93. {
  94. get;
  95. private set;
  96. }
  97. public int CurrentSubRecipeLoopCount
  98. {
  99. get;
  100. private set;
  101. }
  102. public bool IsExecuteAbort
  103. {
  104. get;
  105. private set;
  106. }
  107. public bool IsSubReciep
  108. {
  109. get;
  110. private set;
  111. }
  112. public int AlarmConditionJumpStep { get; set; } = -1;
  113. private DeviceTimer _stepTimer = new DeviceTimer();
  114. private DeviceTimer _holdTimer = new DeviceTimer();
  115. private RecipeFACallback _faCallback;
  116. private RecipeDBCallback _dbCallback;
  117. private Fdc _fdc;
  118. private ModuleName _doModule = ModuleName.PM1;
  119. private bool IsJumpStepCancelCallLoop;
  120. private int _jumpStepNumber;
  121. private int _showStepNo;
  122. private int _subRecipeStartStepNumber;
  123. private RecipeAlaramAction _alarmAction = RecipeAlaramAction.None;
  124. public List<string> _alarmNames
  125. {
  126. private set;
  127. get;
  128. }
  129. private R_TRIG _trigHeaterBottomToleranceAlarm = new R_TRIG();
  130. private R_TRIG _trigHeaterBottomToleranceWarning = new R_TRIG();
  131. private R_TRIG _trigHeaterCenterBottomToleranceAlarm = new R_TRIG();
  132. private R_TRIG _trigHeaterCenterBottomToleranceWarning = new R_TRIG();
  133. private R_TRIG _trigHeaterCenterToleranceAlarm = new R_TRIG();
  134. private R_TRIG _trigHeaterCenterToleranceWarning = new R_TRIG();
  135. private R_TRIG _trigHeaterCenterTopToleranceAlarm = new R_TRIG();
  136. private R_TRIG _trigHeaterCenterTopToleranceWarning = new R_TRIG();
  137. private R_TRIG _trigHeaterTopToleranceAlarm = new R_TRIG();
  138. private R_TRIG _trigHeaterTopToleranceWarning = new R_TRIG();
  139. private R_TRIG _trigPressureToleranceAlarm = new R_TRIG();
  140. private R_TRIG _trigPressureToleranceWarning = new R_TRIG();
  141. private R_TRIG _trigInputSignalTimeOutAlarm = new R_TRIG();
  142. private R_TRIG _trigTemperatureConvergenceTimeOutAlarm = new R_TRIG();
  143. private R_TRIG _trigReachTempTimeOutAlarm = new R_TRIG();
  144. private R_TRIG _trigPressureConvergenceTimeOutAlarm = new R_TRIG();
  145. private R_TRIG _trigReachPressureTimeOutAlarm = new R_TRIG();
  146. private R_TRIG _trigAutoProfileTimeOutAlarm = new R_TRIG();
  147. private Dictionary<string, R_TRIG> _trigMfcToleranceAlarms;
  148. private Dictionary<string, R_TRIG> _trigMfcToleranceWarnings;
  149. private R_TRIG _trigBoatMoveToLoadPositionTimeout = new R_TRIG();
  150. private R_TRIG _trigHeaterProfileFinish = new R_TRIG();
  151. private R_TRIG _trigLeakCheckFinish = new R_TRIG();
  152. private R_TRIG _trigBoatWaitCondition = new R_TRIG();
  153. private R_TRIG _trigAPCWaitCondition = new R_TRIG();
  154. private R_TRIG _trigAUXWaitCondition = new R_TRIG();
  155. private R_TRIG _trigHeaterWaitCondition = new R_TRIG();
  156. private R_TRIG _trigMFCWaitCondition = new R_TRIG();
  157. private string _infoHeaterProfileFinish = "";
  158. private string _infoAUXWaitCondition = "";
  159. private string _infoHeaterWaitCondition = "";
  160. private string _infoMFCWaitCondition = "";
  161. private Dictionary<int, Tuple<bool,int>> _callSubSteps = new Dictionary<int, Tuple<bool, int>>();
  162. private bool _isJumpStep = false;
  163. public Process(ModuleName module, PMModule pm) : base(module, pm)
  164. {
  165. Module = module.ToString();
  166. Name = "Process";
  167. _trigMfcToleranceAlarms = new Dictionary<string, R_TRIG>()
  168. {
  169. {"MFC61", new R_TRIG() },
  170. {"MFC13", new R_TRIG() },
  171. {"MFC14", new R_TRIG() },
  172. {"MFC15", new R_TRIG() },
  173. {"MFC16", new R_TRIG() },
  174. {"MFC24", new R_TRIG() },
  175. {"MFC25", new R_TRIG() },
  176. {"MFC26", new R_TRIG() },
  177. {"MFC34", new R_TRIG() },
  178. {"MFC35", new R_TRIG() },
  179. {"MFC36", new R_TRIG() },
  180. {"MFC90", new R_TRIG() },
  181. {"MFC91", new R_TRIG() },
  182. {"MFC84", new R_TRIG() },
  183. };
  184. _trigMfcToleranceWarnings = new Dictionary<string, R_TRIG>()
  185. {
  186. {"MFC61", new R_TRIG() },
  187. {"MFC13", new R_TRIG() },
  188. {"MFC14", new R_TRIG() },
  189. {"MFC15", new R_TRIG() },
  190. {"MFC16", new R_TRIG() },
  191. {"MFC24", new R_TRIG() },
  192. {"MFC25", new R_TRIG() },
  193. {"MFC26", new R_TRIG() },
  194. {"MFC34", new R_TRIG() },
  195. {"MFC35", new R_TRIG() },
  196. {"MFC36", new R_TRIG() },
  197. {"MFC90", new R_TRIG() },
  198. {"MFC91", new R_TRIG() },
  199. {"MFC84", new R_TRIG() },
  200. };
  201. _faCallback = new RecipeFACallback();
  202. _dbCallback = new RecipeDBCallback();
  203. _fdc = new Fdc(Module);
  204. }
  205. public override Result Start(params object[] param)
  206. {
  207. CurStepTotalLoopCount = 0;
  208. _currentSubRecipeStepNumber = CurSubRecipeStepTotalLoopCount = 0;
  209. if (AlarmConditionJumpStep > 0)
  210. _currentStepNumber = AlarmConditionJumpStep;
  211. else
  212. _currentStepNumber = PMModule.IsJobProcess ? 1 : 0; // 如果是从Job Process开始,从1开始,跳过standby step
  213. AlarmConditionJumpStep = -1;
  214. PMModule.RecipeRunningInfo.InnerId = Guid.NewGuid();
  215. PMModule.RecipeRunningInfo.BeginTime = DateTime.Now;
  216. PMModule.RecipeRunningInfo.TotalTime = CalcRecipeTime();
  217. if (PMModule.RecipeRunningInfo.TotalTime < 0)
  218. return Result.FAIL;
  219. IsSubReciep = false;
  220. IsExecuteAbort = false;
  221. IsJumpStepCancelCallLoop = false;
  222. PMModule.IsPaused = false;
  223. PMModule.IsHeaterProfile = false;
  224. PMModule.IsHeaterProfileSuccess = false;
  225. PMModule.IsMainRecipeComplete = false;
  226. _loopEnd = false;
  227. _isJumpStep = false;
  228. _curStepElpasedTimeBeforePaused = 0;
  229. _waferTimeElpasedTimeBeforPaused = 0;
  230. _totalElpasedTime = 0;
  231. _holdTimeElpasedTime = 0;
  232. _jumpStepNumber = 0;
  233. _showStepNo = 0;
  234. _state = RecipeRunningState.ExecStep;
  235. _alarmAction = RecipeAlaramAction.None;
  236. _alarmNames = new List<string>();
  237. _subRecipeStartStepNumber = 1;
  238. _callSubSteps.Clear();
  239. PMModule.InitAlarmCondition(PMModule.RecipeRunningInfo.Head.AlarmCondition);
  240. PMModule.InitLeakCheck(PMModule.RecipeRunningInfo.Head.LeakCheck);
  241. ResetTrig();
  242. Notify($"Start");
  243. _faCallback.RecipeStart(PMModule.Module, PMModule.RecipeRunningInfo.RecipeName);
  244. _dbCallback.RecipeStart(PMModule.Module, 0, PMModule.RecipeRunningInfo.InnerId.ToString(), PMModule.RecipeRunningInfo.RecipeName);
  245. _dbCallback.RecipeUpdateStatus(PMModule.RecipeRunningInfo.InnerId.ToString(), "InProcess");
  246. _fdc.Reset();
  247. WaferManager.Instance.UpdateWaferProcessStatus(ModuleHelper.Converter(Module), 0, EnumWaferProcessStatus.InProcess);
  248. PMModule.HeaterEnable(true);
  249. return Result.RUN;
  250. }
  251. public override Result Monitor()
  252. {
  253. if (!PMModule.CheckEnableRunProcess(out string reason))
  254. {
  255. PMModule.CheckEnableRunProcessAlarm.Set(reason);
  256. return Result.FAIL;
  257. }
  258. //MonitorRecipeAlaramAction();
  259. //if (IsExecuteAbort)
  260. // return Result.DONE;
  261. MonitorRecipePause();
  262. CheckTolerance();
  263. List<RecipeStep> curSteps;
  264. if ((IsSubReciep || PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].IsCallSubStep) && !_isJumpStep)
  265. {
  266. curSteps = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps;
  267. if (!_callSubSteps.ContainsKey(_currentStepNumber))
  268. _callSubSteps.Add(_currentStepNumber, Tuple.Create(false,0));
  269. if (PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].IsCallSubStep)
  270. {
  271. _callSubSteps[_currentStepNumber] = Tuple.Create(true, PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeLoopCount);
  272. PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].IsCallSubStepTemp = true;
  273. PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeLoopCountTemp = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeLoopCount;
  274. }
  275. if (!IsSubReciep)
  276. {
  277. PMModule.RecipeRunningInfo.SubRecipeCurrentLoopCount = 1;
  278. PMModule.RecipeRunningInfo.SubRecipeLoopCount = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeLoopCount;
  279. }
  280. PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].IsCallSubStep = false;
  281. IsSubReciep = true;
  282. }
  283. else
  284. {
  285. curSteps = PMModule.RecipeRunningInfo.RecipeStepList;
  286. PMModule.RecipeRunningInfo.SubRecipeLoopCount = 0;
  287. }
  288. lock (_recipeLocker)
  289. {
  290. try
  291. {
  292. switch (_state)
  293. {
  294. case RecipeRunningState.ExecStep:
  295. {
  296. PMModule.IsWait = false;
  297. _loopEnd = false;
  298. if (!_holdTimer.IsIdle())
  299. {
  300. _holdTimeElpasedTime += _holdTimer.GetElapseTime();
  301. _holdTimer.Stop();
  302. }
  303. PMModule.ResetToleranceChecker();
  304. _curStepElpasedTimeBeforePaused = 0;
  305. ContinueAction = RecipeContinueMode.None;
  306. if (IsSubReciep)
  307. {
  308. if (curSteps[_currentSubRecipeStepNumber].IsLoopStartStep)
  309. {
  310. CurrentSubRecipeLoopCount++;
  311. PMModule.RecipeRunningInfo.IsLooping = true;
  312. PMModule.RecipeRunningInfo.LoopCountCurrent = CurrentSubRecipeLoopCount - 1;//即使不循环,本身也有一次。本身的一次不算,所以减1
  313. PMModule.RecipeRunningInfo.LoopCountSet = curSteps[_currentSubRecipeStepNumber].LoopCount - 1;//即使不循环,本身也有一次。本身的一次不算,所以减1
  314. }
  315. if (curSteps[_currentSubRecipeStepNumber].IsJumpStep)
  316. {
  317. _currentSubRecipeStepNumber = curSteps[_currentSubRecipeStepNumber].JumpStepNo;
  318. }
  319. RecipeExec("Sub recipe", curSteps, _currentSubRecipeStepNumber, _curStepElpasedTimeBeforePaused, _currentSubRecipeStepNumber+1);
  320. }
  321. else
  322. {
  323. if (curSteps[_currentStepNumber].IsLoopStartStep)
  324. {
  325. CurrentLoopCount++;
  326. PMModule.RecipeRunningInfo.IsLooping = true;
  327. PMModule.RecipeRunningInfo.LoopCountCurrent = CurrentLoopCount - 1;//即使不循环,本身也有一次。本身的一次不算,所以减1
  328. PMModule.RecipeRunningInfo.LoopCountSet = curSteps[_currentStepNumber].LoopCount - 1;//即使不循环,本身也有一次。本身的一次不算,所以减1
  329. }
  330. if (curSteps[_currentStepNumber].IsJumpStep)
  331. {
  332. curSteps[_currentStepNumber].IsJumpStep = false;//只执行一次
  333. _currentStepNumber = curSteps[_currentStepNumber].JumpStepNo;
  334. }
  335. RecipeExec("Main recipe", curSteps, _currentStepNumber, _curStepElpasedTimeBeforePaused);
  336. }
  337. }
  338. break;
  339. case RecipeRunningState.TimeWait:
  340. //if (PMModule.IsPaused)
  341. //{
  342. // _state = RecipeRunningState.Paused;
  343. // break;
  344. //}
  345. var leakCheck = PMModule.CheckLeakCheckFinish();
  346. _trigLeakCheckFinish.CLK = !leakCheck;
  347. if (_trigLeakCheckFinish.Q)
  348. LOG.Write($"Wait condition:leak check");
  349. if (_stepTimer.IsTimeout())
  350. {
  351. var heaterProfile = PMModule.CheckHeaterProfileFinish(out reason);
  352. _trigHeaterProfileFinish.CLK = !heaterProfile || _infoHeaterProfileFinish != reason;
  353. if (_trigHeaterProfileFinish.Q)
  354. LOG.Write($"Wait condition:heater profile--{reason}");
  355. _infoHeaterProfileFinish = reason;
  356. var boatWaitCondition = PMModule.CheckBoatWaitCondition(out reason);
  357. _trigBoatWaitCondition.CLK = !boatWaitCondition;
  358. if (_trigBoatWaitCondition.Q)
  359. LOG.Write($"Wait condition:boat--{reason}");
  360. var apcWaitCondition = PMModule.CheckAPCWaitCondition(out reason);
  361. _trigAPCWaitCondition.CLK = !apcWaitCondition;
  362. if (_trigAPCWaitCondition.Q)
  363. LOG.Write($"Wait condition:APC--{reason}");
  364. var auxWaitCondition = PMModule.CheckAUXWaitCondition(out reason);
  365. _trigAUXWaitCondition.CLK = !auxWaitCondition || _infoAUXWaitCondition != reason;
  366. if (_trigAUXWaitCondition.Q)
  367. LOG.Write($"Wait condition:heater profile--{reason}");
  368. _infoAUXWaitCondition = reason;
  369. var heaterWaitCondition = PMModule.CheckHeaterWaitCondition(out reason);
  370. _trigHeaterWaitCondition.CLK = !heaterWaitCondition || _infoHeaterWaitCondition != reason;
  371. if (_trigHeaterWaitCondition.Q)
  372. LOG.Write($"Wait condition:heater--{reason}");
  373. _infoHeaterWaitCondition = reason;
  374. var mfcWaitCondition = PMModule.CheckMFCWaitCondition(out reason);
  375. _trigMFCWaitCondition.CLK = !mfcWaitCondition || _infoMFCWaitCondition != reason;
  376. if (_trigMFCWaitCondition.Q)
  377. LOG.Write($"Wait condition:MFC--{reason}");
  378. _infoMFCWaitCondition = reason;
  379. if (heaterProfile &&
  380. leakCheck &&
  381. boatWaitCondition &&
  382. apcWaitCondition &&
  383. auxWaitCondition &&
  384. heaterWaitCondition &&
  385. mfcWaitCondition)
  386. {
  387. _state = RecipeRunningState.StepCompleted;
  388. }
  389. else
  390. {
  391. PMModule.IsWait = true;
  392. }
  393. }
  394. else
  395. {
  396. PMModule.CheckHeaterProfileFinish(out reason);
  397. PMModule.CheckBoatWaitCondition(out reason);
  398. PMModule.CheckAPCWaitCondition(out reason);
  399. PMModule.CheckAUXWaitCondition(out reason);
  400. PMModule.CheckHeaterWaitCondition(out reason);
  401. PMModule.CheckMFCWaitCondition(out reason);
  402. }
  403. break;
  404. case RecipeRunningState.ConditionWait:
  405. {
  406. if (!PMModule.CheckBoatState() && !PMModule.IsBoatMoveToLoadPosition)
  407. break;
  408. var heaterProfile = PMModule.CheckHeaterProfileFinish(out reason);
  409. _trigHeaterProfileFinish.CLK = !heaterProfile || _infoHeaterProfileFinish != reason;
  410. if (_trigHeaterProfileFinish.Q)
  411. LOG.Write($"Wait condition:heater profile--{reason}");
  412. _infoHeaterProfileFinish = reason;
  413. leakCheck = PMModule.CheckLeakCheckFinish();
  414. _trigLeakCheckFinish.CLK = !leakCheck;
  415. if (_trigLeakCheckFinish.Q)
  416. LOG.Write($"Wait condition:leak check");
  417. var boatWaitCondition = PMModule.CheckBoatWaitCondition(out reason);
  418. _trigBoatWaitCondition.CLK = !boatWaitCondition;
  419. if (_trigBoatWaitCondition.Q)
  420. LOG.Write($"Wait condition:boat--{reason}");
  421. var apcWaitCondition = PMModule.CheckAPCWaitCondition(out reason);
  422. _trigAPCWaitCondition.CLK = !apcWaitCondition;
  423. if (_trigAPCWaitCondition.Q)
  424. LOG.Write($"Wait condition:APC--{reason}");
  425. var auxWaitCondition = PMModule.CheckAUXWaitCondition(out reason);
  426. _trigAUXWaitCondition.CLK = !auxWaitCondition || _infoAUXWaitCondition != reason;
  427. if (_trigAUXWaitCondition.Q)
  428. LOG.Write($"Wait condition:heater profile--{reason}");
  429. _infoAUXWaitCondition = reason;
  430. var heaterWaitCondition = PMModule.CheckHeaterWaitCondition(out reason);
  431. _trigHeaterWaitCondition.CLK = !heaterWaitCondition || _infoHeaterWaitCondition != reason;
  432. if (_trigHeaterWaitCondition.Q)
  433. LOG.Write($"Wait condition:heater--{reason}");
  434. _infoHeaterWaitCondition = reason;
  435. var mfcWaitCondition = PMModule.CheckMFCWaitCondition(out reason);
  436. _trigMFCWaitCondition.CLK = !mfcWaitCondition || _infoMFCWaitCondition != reason;
  437. if (_trigMFCWaitCondition.Q)
  438. LOG.Write($"Wait condition:MFC--{reason}");
  439. _infoMFCWaitCondition = reason;
  440. if (heaterProfile &&
  441. leakCheck &&
  442. boatWaitCondition &&
  443. apcWaitCondition &&
  444. auxWaitCondition &&
  445. heaterWaitCondition &&
  446. mfcWaitCondition)
  447. {
  448. _state = RecipeRunningState.StepCompleted;
  449. }
  450. if (_stepTimer.IsTimeout())
  451. {
  452. if(PMModule.IsBoatMoveToLoadPosition)
  453. {
  454. _trigBoatMoveToLoadPositionTimeout.CLK = !boatWaitCondition;
  455. if(_trigBoatMoveToLoadPositionTimeout.Q)
  456. PMModule.BoatMoveToLoadPositionTimeoutWarning.Set();
  457. }
  458. //_trigInputSignalTimeOutAlarm.CLK = !PMModule.CheckExternalSensorCondition();
  459. //if (_trigInputSignalTimeOutAlarm.Q)
  460. // PMModule.InputSignalTimeOutAlarm.Set();
  461. //_trigTemperatureConvergenceTimeOutAlarm.CLK = !PMModule.CheckTempStabilizeCondition();
  462. //if (_trigTemperatureConvergenceTimeOutAlarm.Q)
  463. // PMModule.TemperatureConvergenceTimeOutAlarm.Set();
  464. //_trigReachTempTimeOutAlarm.CLK = !PMModule.CheckReachTempCondition();
  465. //if (_trigReachTempTimeOutAlarm.Q)
  466. // PMModule.TemperatureConvergenceTimeOutAlarm.Set("Reach temp condition timeout");
  467. //_trigPressureConvergenceTimeOutAlarm.CLK = !PMModule.CheckPressureStablilizeCondition();
  468. //if (_trigPressureConvergenceTimeOutAlarm.Q)
  469. // PMModule.PressureConvergenceTimeOutAlarm.Set();
  470. //_trigReachPressureTimeOutAlarm.CLK = !PMModule.CheckReachPressureCondition();
  471. //if (_trigReachPressureTimeOutAlarm.Q)
  472. // PMModule.PressureConvergenceTimeOutAlarm.Set("Reach pressure condition timeout");
  473. //_trigAutoProfileTimeOutAlarm.CLK = !PMModule.CheckFinishAutoProfileCondition();
  474. //if (_trigAutoProfileTimeOutAlarm.Q)
  475. // PMModule.AutoProfileTimeOutAlarm.Set();
  476. //_state = RecipeRunningState.StepCompleted;
  477. }
  478. else
  479. {
  480. _trigBoatMoveToLoadPositionTimeout.RST = true;
  481. }
  482. }
  483. break;
  484. case RecipeRunningState.Paused:
  485. if (!_stepTimer.IsIdle())
  486. {
  487. _curStepElpasedTimeBeforePaused += _stepTimer.GetElapseTime();
  488. _stepTimer.Stop();
  489. }
  490. if (_holdTimer.IsIdle())
  491. _holdTimer.Start(0);
  492. switch (ContinueAction)
  493. {
  494. case RecipeContinueMode.None:
  495. break;
  496. case RecipeContinueMode.StepContinue:
  497. if (!_holdTimer.IsIdle())
  498. {
  499. _holdTimeElpasedTime += _holdTimer.GetElapseTime();
  500. _holdTimer.Stop();
  501. }
  502. _state = RecipeRunningState.ExecStep;
  503. _stepTimer.Stop();
  504. break;
  505. }
  506. break;
  507. case RecipeRunningState.StepCompleted:
  508. {
  509. ResetTrig();
  510. //CloseAllValve();
  511. _curStepElpasedTimeBeforePaused = 0;
  512. var stepName = "";
  513. var stepTime = (float)_stepTimer.GetElapseTime() / 1000;//sec
  514. var thickness = 0.0f;
  515. if (IsSubReciep)
  516. {
  517. stepName = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps[_currentSubRecipeStepNumber].StepName;
  518. float.TryParse(PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps[_currentSubRecipeStepNumber].FilmThickFormula, out thickness);
  519. //放在前面,stepnumber后面会被更新
  520. if (!_isJumpStep)
  521. {
  522. _faCallback.RecipeStepEnd(PMModule.Module, PMModule.RecipeRunningInfo.RecipeName, _currentSubRecipeStepNumber + 1);
  523. _dbCallback.RecipeStepEnd(PMModule.RecipeRunningInfo.InnerId.ToString(), _currentSubRecipeStepNumber + 1, _fdc.DataList, SC.GetStringValue("PM1.TempCorrection"), SC.GetStringValue("PM1.Heater.PID"));
  524. }
  525. _fdc.Stop();
  526. //if (PMModule.RecipeRunningInfo.RecipeStepList.Count > _currentStepNumber)
  527. //{
  528. // _totalElpasedTime += PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].StepTime;
  529. //}
  530. if (PMModule.RecipeRunningInfo.RecipeStepList.Count > _currentStepNumber && PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps.Count> _currentSubRecipeStepNumber)
  531. {
  532. _totalElpasedTime += PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps[_currentSubRecipeStepNumber].StepTime;
  533. }
  534. _subRecipeStartStepNumber++;
  535. if (_loopEnd)
  536. {
  537. _currentSubRecipeStepNumber++;
  538. CurrentSubRecipeLoopCount = 0;
  539. PMModule.RecipeRunningInfo.IsLooping = false;
  540. PMModule.RecipeRunningInfo.LoopCountCurrent = 0;
  541. PMModule.RecipeRunningInfo.LoopCountSet = 0;
  542. }
  543. else
  544. {
  545. SubRecipeLoopEndCheck(curSteps);
  546. }
  547. if (_currentSubRecipeStepNumber >= curSteps.Count)
  548. {
  549. PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeLoopCount--;
  550. if (PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeLoopCount > 0)
  551. {
  552. IsSubReciep = true;
  553. }
  554. else
  555. {
  556. IsSubReciep = false;
  557. //PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeLoopCount = PMModule.RecipeRunningInfo.SubRecipeLoopCount;
  558. }
  559. _currentSubRecipeStepNumber = 0;
  560. CurrentSubRecipeLoopCount = 0;
  561. //// sub recipe执行完后,检查下是否在main recipe的loop内
  562. //RecipeLoopEndCheck();
  563. //if (_currentStepNumber >= PMModule.RecipeRunningInfo.RecipeStepList.Count)
  564. //{
  565. // _currentStepNumber = PMModule.RecipeRunningInfo.RecipeStepList.Count - 1;
  566. // _state = RecipeRunningState.RecipeCompleted;
  567. //}
  568. }
  569. _state = RecipeRunningState.ExecStep;
  570. _stepTimer.Stop();
  571. }
  572. else
  573. {
  574. stepName = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].StepName;
  575. float.TryParse(PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].FilmThickFormula, out thickness);
  576. //放在前面,stepnumber后面会被更新
  577. if (!_isJumpStep)
  578. {
  579. _faCallback.RecipeStepEnd(PMModule.Module, PMModule.RecipeRunningInfo.RecipeName, _currentStepNumber);
  580. _dbCallback.RecipeStepEnd(PMModule.RecipeRunningInfo.InnerId.ToString(), _currentStepNumber, _fdc.DataList, SC.GetStringValue("PM1.TempCorrection"), SC.GetStringValue("PM1.Heater.PID"));
  581. }
  582. _fdc.Stop();
  583. if (_currentStepNumber >= 0 && !IsSubReciep)
  584. {
  585. _totalElpasedTime += PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].StepTime;
  586. }
  587. if (IsSubReciep)
  588. IsSubReciep = false;
  589. if (_currentStepNumber > 0 && PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber - 1].IsCallSubStepTemp)
  590. {
  591. PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber - 1].IsCallSubStep = true;
  592. PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber - 1].SubRecipeLoopCount = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber - 1].SubRecipeLoopCountTemp;
  593. }
  594. if (_loopEnd)
  595. {
  596. _currentStepNumber++;
  597. CurrentLoopCount = 0;
  598. CurrentAbortRecipeLoopCount = 0;
  599. CurrentSubRecipeLoopCount = 0;
  600. PMModule.RecipeRunningInfo.IsLooping = false;
  601. PMModule.RecipeRunningInfo.LoopCountCurrent = 0;
  602. PMModule.RecipeRunningInfo.LoopCountSet = 0;
  603. }
  604. else
  605. {
  606. RecipeLoopEndCheck(PMModule.RecipeRunningInfo.RecipeStepList);
  607. }
  608. if(_currentStepNumber >= PMModule.RecipeRunningInfo.RecipeStepList.Count - 1)
  609. {
  610. for (int i = 0; i < SC.GetValue<int>($"Boat.SlotCount"); i++)
  611. {
  612. if (!WaferManager.Instance.CheckHasWafer(ModuleHelper.Converter(Module), i))
  613. continue;
  614. var wafer = WaferManager.Instance.GetWafer(ModuleHelper.Converter(Module), i);
  615. if (wafer.ProcessState == EnumWaferProcessStatus.Completed ||
  616. wafer.ProcessState == EnumWaferProcessStatus.Idle)
  617. continue;
  618. WaferManager.Instance.UpdateWaferProcessStatus(ModuleHelper.Converter(Module), i, EnumWaferProcessStatus.Completed);
  619. }
  620. PMModule.IsMainRecipeComplete = true;
  621. }
  622. if (_currentStepNumber >= PMModule.RecipeRunningInfo.RecipeStepList.Count)
  623. {
  624. _currentStepNumber = PMModule.RecipeRunningInfo.RecipeStepList.Count - 1;
  625. _state = RecipeRunningState.RecipeCompleted;
  626. }
  627. else
  628. {
  629. _state = RecipeRunningState.ExecStep;
  630. _stepTimer.Stop();
  631. }
  632. }
  633. if(!_isJumpStep)
  634. {
  635. PMModule.UpdateRecipeStepThicknessAndTime(stepName, thickness, stepTime);
  636. var wafers = WaferManager.Instance.GetWafers(ModuleHelper.Converter(Module));
  637. for (int i = 0; i < wafers.Length; i++)
  638. {
  639. if (WaferManager.Instance.CheckNoWafer(ModuleHelper.Converter(Module), i))
  640. continue;
  641. var useCount = wafers[i].UseCount;
  642. var useTime = wafers[i].UseTime + (float)stepTime;
  643. var useThick = wafers[i].UseThick + thickness;
  644. WaferManager.Instance.UpdateWaferStatistics(ModuleHelper.Converter(Module), i, useCount, useTime, useThick);
  645. }
  646. }
  647. }
  648. _isJumpStep = false;
  649. if (PMModule.IsPaused)
  650. {
  651. _state = RecipeRunningState.Paused;
  652. break;
  653. }
  654. break;
  655. case RecipeRunningState.RecipeCompleted:
  656. {
  657. var wafers = WaferManager.Instance.GetWafers(ModuleHelper.Converter(Module));
  658. for (int i = 0; i < wafers.Length; i++)
  659. {
  660. if (WaferManager.Instance.CheckNoWafer(ModuleHelper.Converter(Module), i))
  661. continue;
  662. var useCount = wafers[i].UseCount + 1;
  663. var useTime = wafers[i].UseTime;
  664. var useThick = wafers[i].UseThick;
  665. WaferManager.Instance.UpdateWaferStatistics(ModuleHelper.Converter(Module), i, useCount, useTime, useThick);
  666. }
  667. if (PMModule.IsHeaterProfile && !PMModule.IsHeaterProfileSuccess)
  668. EV.PostWarningLog(PMModule.Module, "Auto profile failed");
  669. Notify("End");
  670. return Result.DONE;
  671. }
  672. case RecipeRunningState.Error:
  673. {
  674. return Result.DONE;
  675. }
  676. default:
  677. break;
  678. }
  679. }
  680. catch (Exception ex)
  681. {
  682. LOG.Write(ex);
  683. return Result.FAIL;
  684. }
  685. }
  686. MonitorRecipeRunInfo();
  687. return Result.RUN;
  688. }
  689. private void MonitorRecipeRunInfo()
  690. {
  691. PMModule.IsHolded = _state == RecipeRunningState.Paused;
  692. double elapseTime;
  693. double totalElapseTime;
  694. double holdTotalElapseTime;
  695. var step = 0;
  696. if (IsSubReciep)
  697. {
  698. if(PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps != null)
  699. {
  700. if (_stepTimer.IsIdle())
  701. {
  702. elapseTime = (_curStepElpasedTimeBeforePaused / 1000) < 1 ? 0 : _curStepElpasedTimeBeforePaused / 1000;
  703. }
  704. else
  705. {
  706. elapseTime = ((_curStepElpasedTimeBeforePaused + _stepTimer.GetElapseTime()) / 1000) < 1 ? 0 : (_curStepElpasedTimeBeforePaused + _stepTimer.GetElapseTime()) / 1000;
  707. }
  708. if (elapseTime > PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps[_currentSubRecipeStepNumber].StepTime)
  709. elapseTime = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps[_currentSubRecipeStepNumber].StepTime;
  710. totalElapseTime = _totalElpasedTime + elapseTime > PMModule.RecipeRunningInfo.TotalTime ? PMModule.RecipeRunningInfo.TotalTime : _totalElpasedTime + elapseTime;
  711. if (_holdTimer.IsIdle())
  712. {
  713. holdTotalElapseTime = _holdTimeElpasedTime / 1000;
  714. }
  715. else
  716. {
  717. holdTotalElapseTime = (_holdTimeElpasedTime + _holdTimer.GetElapseTime()) / 1000;
  718. }
  719. PMModule.RecipeRunningInfo.StepElapseTime = elapseTime;
  720. PMModule.RecipeRunningInfo.TotalElapseTime = totalElapseTime;
  721. PMModule.RecipeRunningInfo.HoldTime = holdTotalElapseTime;
  722. PMModule.RecipeRunningInfo.StepTime = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps[_currentSubRecipeStepNumber].StepTime;
  723. PMModule.RecipeRunningInfo.RecipeName = $"Sub/{PMModule.RecipeRunningInfo.Head.SubRecipe}-{PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeTableInfo}-{PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps[_currentSubRecipeStepNumber].StepName}";
  724. PMModule.RecipeRunningInfo.ExecRecipeType = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].RecipeType;
  725. PMModule.RecipeRunningInfo.ExecSubRecipeType = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps[_currentSubRecipeStepNumber].RecipeType;
  726. PMModule.RecipeRunningInfo.SubRecipeCurrentLoopCount = PMModule.RecipeRunningInfo.SubRecipeLoopCount - PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeLoopCount + 1;
  727. PMModule.RecipeRunningInfo.SubRecipeName = PMModule.RecipeRunningInfo.Head.SubRecipe;
  728. step = _currentSubRecipeStepNumber;
  729. if (_state == RecipeRunningState.Paused)
  730. {
  731. //pause之后,当前step执行完,显示的step要保持hold住的这一步的
  732. step--;
  733. if (step < 0)
  734. step = 0;
  735. }
  736. PMModule.RecipeRunningInfo.StepNumber = step + 1; //CurStepNum start from 0
  737. PMModule.RecipeRunningInfo.StepName = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps[step].StepName;
  738. if (PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps[step].IsLoopEndStep)
  739. PMModule.RecipeRunningInfo.NextStepName = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps.Count > PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps[_currentSubRecipeStepNumber].LoopStartStep ?
  740. PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps[PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps[step].LoopStartStep].StepName : "";
  741. else
  742. {
  743. if(PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps.Count > step + 1)
  744. {
  745. PMModule.RecipeRunningInfo.NextStepName = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps[step + 1].StepName;
  746. }
  747. else
  748. {
  749. if(PMModule.RecipeRunningInfo.SubRecipeCurrentLoopCount < PMModule.RecipeRunningInfo.SubRecipeLoopCount)
  750. {
  751. //sub 下一个循环
  752. PMModule.RecipeRunningInfo.NextStepName = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps[0].StepName;
  753. }
  754. else
  755. {
  756. //sub执行结束
  757. if (PMModule.RecipeRunningInfo.RecipeStepList.Count > _currentStepNumber)
  758. {
  759. PMModule.RecipeRunningInfo.NextStepName = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].StepName;
  760. }
  761. }
  762. }
  763. }
  764. if (PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps[_currentSubRecipeStepNumber].StepName.ToLower() == "standby")
  765. {
  766. PMModule.StringProcessFlowState = PMModule.ProcessFlowState.Standby.ToString();
  767. }
  768. else
  769. {
  770. PMModule.StringProcessFlowState = PMModule.ProcessFlowState.Run.ToString();
  771. }
  772. }
  773. return;
  774. }
  775. if (_stepTimer.IsIdle())
  776. {
  777. elapseTime = (_curStepElpasedTimeBeforePaused / 1000) < 1 ? 0 : _curStepElpasedTimeBeforePaused / 1000;
  778. }
  779. else
  780. {
  781. elapseTime = ((_curStepElpasedTimeBeforePaused + _stepTimer.GetElapseTime()) / 1000) < 1 ? 0 : (_curStepElpasedTimeBeforePaused + _stepTimer.GetElapseTime()) / 1000;
  782. }
  783. if (elapseTime > PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].StepTime)
  784. elapseTime = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].StepTime;
  785. totalElapseTime = _totalElpasedTime + elapseTime > PMModule.RecipeRunningInfo.TotalTime ? PMModule.RecipeRunningInfo.TotalTime : _totalElpasedTime + elapseTime;
  786. if (_holdTimer.IsIdle())
  787. {
  788. holdTotalElapseTime = _holdTimeElpasedTime / 1000;
  789. }
  790. else
  791. {
  792. holdTotalElapseTime = (_holdTimeElpasedTime + _holdTimer.GetElapseTime()) / 1000;
  793. }
  794. PMModule.RecipeRunningInfo.StepElapseTime = elapseTime;
  795. PMModule.RecipeRunningInfo.TotalElapseTime = totalElapseTime;
  796. PMModule.RecipeRunningInfo.HoldTime = holdTotalElapseTime;
  797. PMModule.RecipeRunningInfo.StepTime = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].StepTime;
  798. PMModule.RecipeRunningInfo.RecipeName = PMModule.RecipeRunningInfo.MainRecipeName;
  799. PMModule.RecipeRunningInfo.ExecRecipeType = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].RecipeType;
  800. if (_state == RecipeRunningState.RecipeCompleted) {
  801. PMModule.RecipeRunningInfo.HoldTime = 0;
  802. }
  803. step = _currentStepNumber;
  804. if (_state == RecipeRunningState.Paused)
  805. {
  806. //pause之后,当前step执行完,显示的step要保持hold住的这一步的
  807. step--;
  808. if (step < 0)
  809. step = 0;
  810. }
  811. if (PMModule.RecipeRunningInfo.RecipeStepList[0].StepName.ToLower() == "standby")
  812. {
  813. PMModule.RecipeRunningInfo.StepNumber = step; //CurStepNum start from 0
  814. }
  815. else
  816. {
  817. PMModule.RecipeRunningInfo.StepNumber = step + 1; //CurStepNum start from 0
  818. }
  819. PMModule.RecipeRunningInfo.StepName = PMModule.RecipeRunningInfo.RecipeStepList[_showStepNo].StepName;
  820. if(PMModule.RecipeRunningInfo.RecipeStepList[step].IsLoopEndStep && PMModule.RecipeRunningInfo.LoopCountCurrent < PMModule.RecipeRunningInfo.LoopCountSet)
  821. PMModule.RecipeRunningInfo.NextStepName = PMModule.RecipeRunningInfo.RecipeStepList.Count > PMModule.RecipeRunningInfo.RecipeStepList[step].LoopStartStep ? PMModule.RecipeRunningInfo.RecipeStepList[PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].LoopStartStep].StepName : "";
  822. else
  823. PMModule.RecipeRunningInfo.NextStepName = PMModule.RecipeRunningInfo.RecipeStepList.Count > step + 1 ? PMModule.RecipeRunningInfo.RecipeStepList[step + 1].StepName : "";
  824. if (PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].StepName.ToLower() == "standby")
  825. {
  826. PMModule.StringProcessFlowState = PMModule.ProcessFlowState.Standby.ToString();
  827. }
  828. else if (PMModule.RecipeRunningInfo.RecipeStepList.Count - 1 == _currentStepNumber)
  829. {
  830. PMModule.StringProcessFlowState = PMModule.ProcessFlowState.End.ToString();
  831. }
  832. else
  833. {
  834. PMModule.StringProcessFlowState = PMModule.ProcessFlowState.Run.ToString();
  835. }
  836. }
  837. private void MonitorRecipeAlaramAction()
  838. {
  839. if (_state != RecipeRunningState.TimeWait && _state != RecipeRunningState.ConditionWait)
  840. return;
  841. if (_alarmNames.Count == 0)
  842. return;
  843. int group = -1,temp = 0;
  844. string iAlarmConditionTable="1:";
  845. if (IsSubReciep)
  846. {
  847. for (int i = 0; i < _alarmNames.Count; i++)
  848. {
  849. iAlarmConditionTable = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps[_currentSubRecipeStepNumber].AlarmConditionTable;
  850. temp = (int)Singleton<EventManager>.Instance.AlarmDic[iAlarmConditionTable.ToString()][_alarmNames[i]].Group;
  851. if (!PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps[_currentSubRecipeStepNumber].AlarmActionSets.ContainsKey(temp))
  852. continue;
  853. var type = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps[_currentSubRecipeStepNumber].AlarmActionSets[temp].ProcessingType;
  854. if (temp >= group && (group == -1 || type != "Ignore Alarm"))
  855. group = temp;
  856. }
  857. }
  858. else
  859. {
  860. for (int i = 0; i < _alarmNames.Count; i++)
  861. {
  862. iAlarmConditionTable = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].AlarmConditionTable;
  863. temp = (int)Singleton<EventManager>.Instance.AlarmDic[iAlarmConditionTable.ToString()][_alarmNames[i]].Group;
  864. if (!PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].AlarmActionSets.ContainsKey(temp))
  865. continue;
  866. var type = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].AlarmActionSets[temp].ProcessingType;
  867. if (temp >= group && (group == -1 || type != "Ignore Alarm"))
  868. group = temp;
  869. }
  870. }
  871. _alarmNames.Clear();
  872. if (group == -1)
  873. return;
  874. string alarmAction = "", alarmDetails = "";
  875. List<RecipeStep> abortRecipes = new List<RecipeStep>();
  876. if (IsSubReciep)
  877. {
  878. alarmAction = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps[_currentSubRecipeStepNumber].AlarmActionSets[group].ProcessingType;
  879. alarmDetails = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps[_currentSubRecipeStepNumber].AlarmActionSets[group].ProcessingDetails;
  880. abortRecipes = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps[_currentSubRecipeStepNumber].AlarmActionSets[group].AbortRecipeStepList;
  881. }
  882. else
  883. {
  884. alarmAction = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].AlarmActionSets[group].ProcessingType;
  885. alarmDetails = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].AlarmActionSets[group].ProcessingDetails;
  886. abortRecipes = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].AlarmActionSets[group].AbortRecipeStepList;
  887. }
  888. switch (alarmAction)
  889. {
  890. case "Jump Abort Recipe":
  891. alarmDetails = alarmDetails.Replace("Abort Recipe/", string.Empty);
  892. Abort();
  893. _alarmAction = RecipeAlaramAction.JumpAbortRecipe;
  894. break;
  895. case "Jump Step":
  896. alarmDetails = alarmDetails.Replace("Jump Step/", string.Empty);
  897. _jumpStepNumber = PMModule.RecipeRunningInfo.RecipeStepList.FindIndex(x => x.StepName == alarmDetails);
  898. _alarmAction = RecipeAlaramAction.JumpStep;
  899. _state = RecipeRunningState.StepCompleted;
  900. break;
  901. case "Jump Step(Cancel Call Loop)":
  902. alarmDetails = alarmDetails.Replace("Jump Step(Cancel Call Loop)/", string.Empty);
  903. _jumpStepNumber = PMModule.RecipeRunningInfo.RecipeStepList.FindIndex(x => x.StepName == alarmDetails);
  904. _alarmAction = RecipeAlaramAction.JumpStepCancelCallLoop;
  905. IsJumpStepCancelCallLoop = true;
  906. _state = RecipeRunningState.StepCompleted;
  907. break;
  908. case "Abort":
  909. IsExecuteAbort = true;
  910. break;
  911. case "Hold":
  912. PMModule.IsPaused = true;
  913. ContinueAction = RecipeContinueMode.None;
  914. _alarmAction = RecipeAlaramAction.Hold;
  915. break;
  916. case "Ignore Alarm":
  917. _alarmAction = RecipeAlaramAction.IgnoreAlaram;
  918. break;
  919. default:
  920. _alarmAction = RecipeAlaramAction.IgnoreAlaram;
  921. break;
  922. }
  923. }
  924. private void MonitorRecipePause()
  925. {
  926. if (_state != RecipeRunningState.TimeWait && _state != RecipeRunningState.ConditionWait)
  927. return;
  928. //if (PMModule.IsPaused)
  929. //{
  930. // _state = RecipeRunningState.Paused;
  931. //}
  932. }
  933. public override void Abort()
  934. {
  935. //PMModule.AbortRecipe();//暂时这么做
  936. PMModule.RecipeRunningInfo.IsLooping = false;
  937. PMModule.RecipeRunningInfo.LoopCountCurrent = 0;
  938. PMModule.RecipeRunningInfo.LoopCountSet = 0;
  939. IsExecuteAbort = true;
  940. IsSubReciep = false;
  941. PMModule.IsPaused = false;
  942. PMModule.IsHeaterProfile = false;
  943. PMModule.IsHeaterProfileSuccess = false;
  944. if (!_holdTimer.IsIdle())
  945. {
  946. _holdTimeElpasedTime += _holdTimer.GetElapseTime();
  947. _holdTimer.Stop();
  948. }
  949. CurrentLoopCount = 0;
  950. CurrentAbortRecipeLoopCount = 0;
  951. CurrentSubRecipeLoopCount = 0;
  952. _state = RecipeRunningState.RecipeCompleted;//暂时这么做
  953. return;//暂时这么做
  954. //_totalElpasedTime = 0;
  955. PMModule.RecipeRunningInfo.BeginTime = DateTime.Now;
  956. double total = 0;
  957. for (int i = 0; i < PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].AbortRecipeSteps.Count; i++)
  958. {
  959. total += PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].AbortRecipeSteps[i].StepTime;
  960. }
  961. PMModule.RecipeRunningInfo.TotalTime = _totalElpasedTime + total;
  962. ResetTrig();
  963. //PMModule.ResetToleranceAlarm();
  964. //PMModule.ResetToleranceAlarmChecker();
  965. PMModule.ExecuteAbortRecipeWarning.Set($"from recipe name:{PMModule.RecipeRunningInfo.RecipeName} step:{_currentStepNumber} start execute abort recipe.");
  966. _state = RecipeRunningState.ExecStep;
  967. }
  968. public void UpdateProcessDataPJid(string pjId)
  969. {
  970. _dbCallback.RecipeUpdatePjId(PMModule.RecipeRunningInfo.InnerId.ToString(), pjId);
  971. }
  972. public void ExitProcess()
  973. {
  974. if (_state == RecipeRunningState.RecipeCompleted)
  975. {
  976. PMModule.StringProcessFlowState = PMModule.ProcessFlowState.Standby.ToString();
  977. _faCallback.RecipeComplete(PMModule.Module, PMModule.RecipeRunningInfo.RecipeName);
  978. _dbCallback.RecipeComplete(PMModule.RecipeRunningInfo.InnerId.ToString());
  979. _fdc.Stop();
  980. }
  981. else
  982. {
  983. if (PMModule.IsExcuteIdleRecipe)
  984. {
  985. _faCallback.RecipeComplete(PMModule.Module, PMModule.RecipeRunningInfo.RecipeName);
  986. _dbCallback.RecipeComplete(PMModule.RecipeRunningInfo.InnerId.ToString());
  987. _fdc.Stop();
  988. }
  989. else
  990. {
  991. _faCallback.RecipeFailed(PMModule.Module, PMModule.RecipeRunningInfo.RecipeName);
  992. _dbCallback.RecipeFailed(PMModule.RecipeRunningInfo.InnerId.ToString());
  993. _fdc.Stop();
  994. };
  995. }
  996. }
  997. public void PauseRecipe()
  998. {
  999. PMModule.IsPaused = true;
  1000. ContinueAction = RecipeContinueMode.None;
  1001. }
  1002. public void ContinueRecipe()
  1003. {
  1004. PMModule.IsPaused = false;
  1005. ContinueAction = RecipeContinueMode.StepContinue;
  1006. }
  1007. public void SkipCurrentRecipeStep()
  1008. {
  1009. if (_state == RecipeRunningState.ConditionWait || _state == RecipeRunningState.TimeWait || _state == RecipeRunningState.Paused)
  1010. {
  1011. _state = RecipeRunningState.StepCompleted;
  1012. _loopEnd = true;
  1013. PMModule.RecipeRunningInfo.IsLooping = false;
  1014. PMModule.RecipeRunningInfo.LoopCountCurrent = 0;
  1015. PMModule.RecipeRunningInfo.LoopCountSet = 0;
  1016. PMModule.IsPaused = false;
  1017. if (!_holdTimer.IsIdle())
  1018. {
  1019. _holdTimeElpasedTime += _holdTimer.GetElapseTime();
  1020. _holdTimer.Stop();
  1021. }
  1022. }
  1023. if(IsSubReciep)
  1024. {
  1025. ResetLoop(PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps, _currentSubRecipeStepNumber);
  1026. }
  1027. else
  1028. {
  1029. ResetLoop(PMModule.RecipeRunningInfo.RecipeStepList, _currentStepNumber);
  1030. }
  1031. }
  1032. private void ResetLoop(List<RecipeStep> checkRecipeSeps, int currentStepNumber)
  1033. {
  1034. if (checkRecipeSeps == null)
  1035. return;
  1036. var hasLoopStart = false;
  1037. for (int i = currentStepNumber; i >= 0; i--)
  1038. {
  1039. if (checkRecipeSeps[i].IsLoopStartStep)
  1040. {
  1041. hasLoopStart = true;
  1042. break;
  1043. }
  1044. if (checkRecipeSeps[i].IsLoopEndStep)
  1045. {
  1046. hasLoopStart = false;//前面有end,说明没有循环
  1047. break;
  1048. }
  1049. }
  1050. if (hasLoopStart)
  1051. {
  1052. for (int i = currentStepNumber; i < checkRecipeSeps.Count; i++)
  1053. {
  1054. if (checkRecipeSeps[i].IsLoopStartStep)
  1055. {
  1056. break;//没有循环
  1057. }
  1058. if (checkRecipeSeps[i].IsLoopEndStep)
  1059. {
  1060. checkRecipeSeps[i].IsLoopEndStep = false;//跳出skip step之间的循环
  1061. break;
  1062. }
  1063. }
  1064. }
  1065. }
  1066. public void LeakCheckRetry()
  1067. {
  1068. JumpCurrentRecipeStep(_currentStepNumber - 1, PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber - 1].StepName);
  1069. }
  1070. public void JumpCurrentRecipeStep(int stepNumber, string stepName, bool isAlarmConditionCall = false)
  1071. {
  1072. PMModule.AbortLeakCheck();
  1073. LOG.Write($"Jump to step stepNumber={stepNumber} stepName={stepName}, currentStepNumber={_currentStepNumber}");
  1074. if (_state == RecipeRunningState.ConditionWait || _state == RecipeRunningState.TimeWait ||
  1075. _state == RecipeRunningState.Paused || _state == RecipeRunningState.ExecStep)
  1076. {
  1077. _loopEnd = true;
  1078. PMModule.RecipeRunningInfo.IsLooping = false;
  1079. PMModule.RecipeRunningInfo.LoopCountCurrent = 0;
  1080. PMModule.RecipeRunningInfo.LoopCountSet = 0;
  1081. CurrentLoopCount = 0;
  1082. CurrentAbortRecipeLoopCount = 0;
  1083. CurrentSubRecipeLoopCount = 0;
  1084. IsSubReciep = false;
  1085. if (IsSubReciep)
  1086. {
  1087. _faCallback.RecipeStepEnd(PMModule.Module, PMModule.RecipeRunningInfo.RecipeName, _currentSubRecipeStepNumber + 1);
  1088. _dbCallback.RecipeStepEnd(PMModule.RecipeRunningInfo.InnerId.ToString(), _currentSubRecipeStepNumber + 1, _fdc.DataList, SC.GetStringValue("PM1.TempCorrection"), SC.GetStringValue("PM1.Heater.PID"));
  1089. ResetLoop(PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps, _currentSubRecipeStepNumber);
  1090. }
  1091. else
  1092. {
  1093. _faCallback.RecipeStepEnd(PMModule.Module, PMModule.RecipeRunningInfo.RecipeName, _currentStepNumber);
  1094. _dbCallback.RecipeStepEnd(PMModule.RecipeRunningInfo.InnerId.ToString(), _currentStepNumber, _fdc.DataList, SC.GetStringValue("PM1.TempCorrection"), SC.GetStringValue("PM1.Heater.PID"));
  1095. ResetLoop(PMModule.RecipeRunningInfo.RecipeStepList, _currentStepNumber);
  1096. }
  1097. if(_callSubSteps != null)
  1098. {
  1099. foreach(var key in _callSubSteps.Keys)
  1100. {
  1101. if(PMModule.RecipeRunningInfo.RecipeStepList.Count > key)
  1102. {
  1103. PMModule.RecipeRunningInfo.RecipeStepList[key].IsCallSubStep = _callSubSteps[key].Item1;
  1104. PMModule.RecipeRunningInfo.RecipeStepList[key].SubRecipeLoopCount = _callSubSteps[key].Item2;
  1105. }
  1106. }
  1107. _currentSubRecipeStepNumber = CurSubRecipeStepTotalLoopCount = 0;
  1108. }
  1109. _isJumpStep = true;
  1110. _currentStepNumber = stepNumber - 1;
  1111. if (_currentStepNumber < 0)
  1112. _currentStepNumber = 0;
  1113. _totalElpasedTime = RefreshElpasedTime();
  1114. _state = RecipeRunningState.StepCompleted;
  1115. PMModule.IsPaused = false;
  1116. if (!_holdTimer.IsIdle())
  1117. {
  1118. _holdTimeElpasedTime += _holdTimer.GetElapseTime();
  1119. _holdTimer.Stop();
  1120. }
  1121. }
  1122. }
  1123. private double RefreshElpasedTime()
  1124. {
  1125. double total = 0;
  1126. try
  1127. {
  1128. for (int i = 0; i < _currentStepNumber; i++)
  1129. {
  1130. if (!PMModule.RecipeRunningInfo.RecipeStepList[i].IsJumpStep)
  1131. {
  1132. if (PMModule.RecipeRunningInfo.RecipeStepList[i].IsLoopEndStep)
  1133. {
  1134. int iLoopStartStep = PMModule.RecipeRunningInfo.RecipeStepList[i].LoopStartStep;
  1135. for (int j = 0; j < PMModule.RecipeRunningInfo.RecipeStepList[i].LoopCount; j++)
  1136. {
  1137. for (int m = iLoopStartStep; m <= i; m++)
  1138. {
  1139. if (PMModule.RecipeRunningInfo.RecipeStepList[m].SubRecipeSteps != null && PMModule.RecipeRunningInfo.RecipeStepList[m].SubRecipeSteps.Count > _currentSubRecipeStepNumber)
  1140. {
  1141. int subLoopCount =Math.Max(1, PMModule.RecipeRunningInfo.RecipeStepList[m].SubRecipeLoopCount);
  1142. total += SubRecipeCalTotalTime(m) * subLoopCount;
  1143. }
  1144. total += PMModule.RecipeRunningInfo.RecipeStepList[m].StepTime;
  1145. }
  1146. }
  1147. }
  1148. else
  1149. {
  1150. if (PMModule.RecipeRunningInfo.RecipeStepList[i].SubRecipeSteps != null &&
  1151. PMModule.RecipeRunningInfo.RecipeStepList[i].SubRecipeSteps.Count > _currentSubRecipeStepNumber)
  1152. {
  1153. int subLoopCount = Math.Max(1, PMModule.RecipeRunningInfo.RecipeStepList[i].SubRecipeLoopCount);
  1154. total += SubRecipeCalTotalTime(i) * subLoopCount ;
  1155. }
  1156. total += PMModule.RecipeRunningInfo.RecipeStepList[i].StepTime;
  1157. }
  1158. }
  1159. }
  1160. }
  1161. catch (Exception ex)
  1162. {
  1163. LOG.Write(ex);
  1164. return -1;
  1165. }
  1166. return (int)total;
  1167. }
  1168. public void RespondAlarm(string name)
  1169. {
  1170. if (!_alarmNames.Contains(name))
  1171. _alarmNames.Add(name);
  1172. }
  1173. protected int CalcRecipeTime()
  1174. {
  1175. double total = 0;
  1176. int iStart = PMModule.IsJobProcess ? 1 : 0;
  1177. try
  1178. {
  1179. for (int i = iStart; i < PMModule.RecipeRunningInfo.RecipeStepList.Count; i++)
  1180. {
  1181. if (!PMModule.RecipeRunningInfo.RecipeStepList[i].IsJumpStep)
  1182. {
  1183. if (PMModule.RecipeRunningInfo.RecipeStepList[i].IsLoopEndStep)
  1184. {
  1185. int iLoopStartStep = PMModule.RecipeRunningInfo.RecipeStepList[i].LoopStartStep;
  1186. total += PMModule.RecipeRunningInfo.RecipeStepList[i].StepTime;
  1187. for (int j = 0; j < PMModule.RecipeRunningInfo.RecipeStepList[i].LoopCount - 1; j++)
  1188. {
  1189. for (int m = iLoopStartStep; m <= i; m++)
  1190. {
  1191. if (PMModule.RecipeRunningInfo.RecipeStepList[m].SubRecipeSteps != null && PMModule.RecipeRunningInfo.RecipeStepList[m].SubRecipeSteps.Count > _currentSubRecipeStepNumber)
  1192. {
  1193. int subLoopCount = Math.Max(1, PMModule.RecipeRunningInfo.RecipeStepList[m].SubRecipeLoopCount);
  1194. total += SubRecipeCalTotalTime(m) * subLoopCount ;
  1195. }
  1196. total += PMModule.RecipeRunningInfo.RecipeStepList[m].StepTime;
  1197. }
  1198. }
  1199. }
  1200. else
  1201. {
  1202. if (PMModule.RecipeRunningInfo.RecipeStepList[i].SubRecipeSteps != null && PMModule.RecipeRunningInfo.RecipeStepList[i].SubRecipeSteps.Count > _currentSubRecipeStepNumber)
  1203. {
  1204. int subLoopCount = Math.Max(1, PMModule.RecipeRunningInfo.RecipeStepList[i].SubRecipeLoopCount);
  1205. total += SubRecipeCalTotalTime(i) * subLoopCount;
  1206. }
  1207. total += PMModule.RecipeRunningInfo.RecipeStepList[i].StepTime;
  1208. }
  1209. }
  1210. else
  1211. {
  1212. i = PMModule.RecipeRunningInfo.RecipeStepList[i].JumpStepNo - 1;// -1是因为i++
  1213. }
  1214. }
  1215. }
  1216. catch (Exception ex)
  1217. {
  1218. LOG.Write(ex);
  1219. return -1;
  1220. }
  1221. return (int)total;
  1222. }
  1223. private int AbortRecipeCalTotalTime()
  1224. {
  1225. double total = 0;
  1226. List<RecipeStep> abortRecipeSteps;
  1227. abortRecipeSteps = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].AbortRecipeSteps;
  1228. try
  1229. {
  1230. for (int i = 0; i < abortRecipeSteps.Count; i++)
  1231. {
  1232. if (!abortRecipeSteps[i].IsJumpStep)
  1233. {
  1234. if (abortRecipeSteps[i].IsLoopStartStep)
  1235. {
  1236. int iLoopEndStep = 0;
  1237. for (int j = 0; j < abortRecipeSteps[i].LoopCount; j++)
  1238. {
  1239. for (int m = i; m < abortRecipeSteps.Count; m++)
  1240. {
  1241. total += abortRecipeSteps[m].StepTime;
  1242. if (abortRecipeSteps[m].IsLoopEndStep)
  1243. {
  1244. iLoopEndStep = m;
  1245. break;
  1246. }
  1247. }
  1248. }
  1249. i = iLoopEndStep;
  1250. }
  1251. else
  1252. {
  1253. total += abortRecipeSteps[i].StepTime;
  1254. }
  1255. }
  1256. else
  1257. {
  1258. i = abortRecipeSteps[i].JumpStepNo - 1;// -1是因为i++
  1259. }
  1260. }
  1261. }
  1262. catch (Exception ex)
  1263. {
  1264. LOG.Write(ex);
  1265. return -1;
  1266. }
  1267. return (int)total;
  1268. }
  1269. public void SetContinue(string continueMode)
  1270. {
  1271. switch (continueMode)
  1272. {
  1273. case "Step continue":
  1274. ContinueAction = RecipeContinueMode.StepContinue;
  1275. break;
  1276. case "Step restart":
  1277. ContinueAction = RecipeContinueMode.StepRestart;
  1278. break;
  1279. case "Next step":
  1280. ContinueAction = RecipeContinueMode.NextStep;
  1281. break;
  1282. case "Recipe restart":
  1283. ContinueAction = RecipeContinueMode.RecipeRestart;
  1284. break;
  1285. case "Recipe complete":
  1286. ContinueAction = RecipeContinueMode.RecipeCompleted;
  1287. break;
  1288. case "Wafer return and job stop":
  1289. ContinueAction = RecipeContinueMode.WaferReturnAndJobStop;
  1290. break;
  1291. }
  1292. PMModule.ResetToleranceChecker();
  1293. }
  1294. private double SubRecipeCalTotalTime(int currentStepNumber)
  1295. {
  1296. double total = 0;
  1297. for (int k = _currentSubRecipeStepNumber; k < PMModule.RecipeRunningInfo.RecipeStepList[currentStepNumber].SubRecipeSteps.Count; k++)
  1298. {
  1299. if (!PMModule.RecipeRunningInfo.RecipeStepList[currentStepNumber].SubRecipeSteps[k].IsJumpStep)
  1300. {
  1301. if (PMModule.RecipeRunningInfo.RecipeStepList[currentStepNumber].SubRecipeSteps[k].IsLoopEndStep)
  1302. {
  1303. int iSystemLoopStartStep = PMModule.RecipeRunningInfo.RecipeStepList[currentStepNumber].SubRecipeSteps[k].LoopStartStep;
  1304. total += PMModule.RecipeRunningInfo.RecipeStepList[currentStepNumber].SubRecipeSteps[k].StepTime;
  1305. for (int n = 0; n < PMModule.RecipeRunningInfo.RecipeStepList[currentStepNumber].SubRecipeSteps[k].LoopCount - 1; n++)
  1306. {
  1307. for (int l = iSystemLoopStartStep; l <= k; l++)
  1308. {
  1309. total += PMModule.RecipeRunningInfo.RecipeStepList[currentStepNumber].SubRecipeSteps[l].StepTime;
  1310. }
  1311. }
  1312. }
  1313. else
  1314. {
  1315. total += PMModule.RecipeRunningInfo.RecipeStepList[currentStepNumber].SubRecipeSteps[k].StepTime;
  1316. }
  1317. }
  1318. else
  1319. {
  1320. k = PMModule.RecipeRunningInfo.RecipeStepList[currentStepNumber].SubRecipeSteps[k].JumpStepNo - 1;// -1是因为k++
  1321. }
  1322. }
  1323. return total;
  1324. }
  1325. private void SubRecipeLoopEndCheck(List<RecipeStep> recipeSteps)
  1326. {
  1327. if (_alarmAction == RecipeAlaramAction.JumpStep || _alarmAction == RecipeAlaramAction.JumpStepCancelCallLoop)
  1328. {
  1329. _currentSubRecipeStepNumber = _jumpStepNumber;
  1330. _alarmAction = RecipeAlaramAction.None;
  1331. _alarmNames.Clear();
  1332. return;
  1333. }
  1334. if (recipeSteps[_currentSubRecipeStepNumber].IsLoopEndStep)
  1335. {
  1336. if (IsJumpStepCancelCallLoop)
  1337. {
  1338. _currentSubRecipeStepNumber++;
  1339. IsJumpStepCancelCallLoop = false;
  1340. return;
  1341. }
  1342. //重新读取循环的设定次数
  1343. CurSubRecipeStepTotalLoopCount = recipeSteps[_currentSubRecipeStepNumber].LoopCount;
  1344. if (CurrentSubRecipeLoopCount >= CurSubRecipeStepTotalLoopCount)
  1345. {
  1346. CurrentSubRecipeLoopCount = CurSubRecipeStepTotalLoopCount = 0;
  1347. _currentSubRecipeStepNumber++;
  1348. PMModule.RecipeRunningInfo.IsLooping = false;
  1349. PMModule.RecipeRunningInfo.LoopCountCurrent = 0;
  1350. PMModule.RecipeRunningInfo.LoopCountSet = 0;
  1351. }
  1352. else
  1353. {
  1354. _currentSubRecipeStepNumber = recipeSteps[_currentSubRecipeStepNumber].LoopStartStep;
  1355. }
  1356. }
  1357. else
  1358. {
  1359. _currentSubRecipeStepNumber++;
  1360. }
  1361. }
  1362. private void RecipeLoopEndCheck(List<RecipeStep> recipeSteps)
  1363. {
  1364. if (_alarmAction == RecipeAlaramAction.JumpStep || _alarmAction == RecipeAlaramAction.JumpStepCancelCallLoop)
  1365. {
  1366. _currentStepNumber = _jumpStepNumber;
  1367. _alarmAction = RecipeAlaramAction.None;
  1368. _alarmNames.Clear();
  1369. return;
  1370. }
  1371. if (recipeSteps[_currentStepNumber].IsLoopEndStep)
  1372. {
  1373. if (IsJumpStepCancelCallLoop)
  1374. {
  1375. _currentStepNumber++;
  1376. IsJumpStepCancelCallLoop = false;
  1377. return;
  1378. }
  1379. //重新读取循环的设定次数
  1380. CurStepTotalLoopCount = recipeSteps[_currentStepNumber].LoopCount;
  1381. if (CurrentLoopCount >= CurStepTotalLoopCount)
  1382. {
  1383. CurrentLoopCount = CurStepTotalLoopCount = 0;
  1384. _currentStepNumber++;
  1385. PMModule.RecipeRunningInfo.IsLooping = false;
  1386. PMModule.RecipeRunningInfo.LoopCountCurrent = 0;
  1387. PMModule.RecipeRunningInfo.LoopCountSet = 0;
  1388. }
  1389. else
  1390. {
  1391. _currentStepNumber = recipeSteps[_currentStepNumber].LoopStartStep;
  1392. }
  1393. }
  1394. else
  1395. {
  1396. _currentStepNumber++;
  1397. }
  1398. }
  1399. private void CheckTolerance()
  1400. {
  1401. //foreach (var key in _trigMfcToleranceAlarms.Keys)
  1402. //{
  1403. // if (PMModule.GasMFCs.ContainsKey(key) && _trigMfcToleranceWarnings.ContainsKey(key))
  1404. // {
  1405. // _trigMfcToleranceAlarms[key].CLK = PMModule.GasMFCs[key].CheckToleranceAlarm();
  1406. // if (_trigMfcToleranceAlarms[key].Q)
  1407. // PMModule.GasMFCs[key].SetToleranceAlarm();
  1408. // _trigMfcToleranceWarnings[key].CLK = PMModule.GasMFCs[key].CheckToleranceWarning();
  1409. // if (_trigMfcToleranceWarnings[key].Q && !_trigMfcToleranceAlarms[key].Q)
  1410. // PMModule.GasMFCs[key].SetToleranceWarning();
  1411. // }
  1412. //}
  1413. //_trigHeaterBottomToleranceAlarm.CLK = PMModule.CheckHeaterBottomToleranceAlaram();
  1414. //if (_trigHeaterBottomToleranceAlarm.Q)
  1415. // PMModule.SetHeaterBottomToleranceAlaram();
  1416. //_trigHeaterBottomToleranceWarning.CLK = PMModule.CheckHeaterBottomToleranceWarning();
  1417. //if (_trigHeaterBottomToleranceWarning.Q && !_trigHeaterBottomToleranceAlarm.Q)
  1418. // PMModule.SetHeaterBottomToleranceWarning();
  1419. //_trigHeaterCenterBottomToleranceAlarm.CLK = PMModule.CheckHeaterCenterBottomToleranceAlaram();
  1420. //if (_trigHeaterCenterBottomToleranceAlarm.Q)
  1421. // PMModule.SetHeaterCenterBottomToleranceAlaram();
  1422. //_trigHeaterCenterBottomToleranceWarning.CLK = PMModule.CheckHeaterCenterBottomToleranceWarning();
  1423. //if (_trigHeaterCenterBottomToleranceWarning.Q && !_trigHeaterCenterBottomToleranceAlarm.Q)
  1424. // PMModule.SetHeaterCenterBottomToleranceWarning();
  1425. //_trigHeaterCenterToleranceAlarm.CLK = PMModule.CheckHeaterCenterToleranceAlaram();
  1426. //if (_trigHeaterCenterToleranceAlarm.Q)
  1427. // PMModule.SetHeaterCenterToleranceAlaram();
  1428. //_trigHeaterCenterToleranceWarning.CLK = PMModule.CheckHeaterCenterToleranceWarning();
  1429. //if (_trigHeaterCenterToleranceWarning.Q && !_trigHeaterCenterToleranceAlarm.Q)
  1430. // PMModule.SetHeaterCenterToleranceWarning();
  1431. //_trigHeaterCenterTopToleranceAlarm.CLK = PMModule.CheckHeaterCenterTopToleranceAlaram();
  1432. //if (_trigHeaterCenterTopToleranceAlarm.Q)
  1433. // PMModule.SetHeaterCenterTopToleranceAlaram();
  1434. //_trigHeaterCenterTopToleranceWarning.CLK = PMModule.CheckHeaterCenterTopToleranceWarning();
  1435. //if (_trigHeaterCenterTopToleranceWarning.Q && !_trigHeaterCenterTopToleranceAlarm.Q)
  1436. // PMModule.SetHeaterCenterTopToleranceWarning();
  1437. //_trigHeaterTopToleranceAlarm.CLK = PMModule.CheckHeaterTopToleranceAlaram();
  1438. //if (_trigHeaterTopToleranceAlarm.Q)
  1439. // PMModule.SetHeaterTopToleranceAlaram();
  1440. //_trigHeaterTopToleranceWarning.CLK = PMModule.CheckHeaterTopToleranceWarning();
  1441. //if (_trigHeaterTopToleranceWarning.Q && !_trigHeaterTopToleranceAlarm.Q)
  1442. // PMModule.SetHeaterTopToleranceWarning();
  1443. //_trigPressureToleranceAlarm.CLK = PMModule.CheckPressureToleranceAlaram();
  1444. //if (_trigPressureToleranceAlarm.Q)
  1445. // PMModule.SetPressureToleranceAlaram();
  1446. //_trigPressureToleranceWarning.CLK = PMModule.CheckPressureToleranceWarning();
  1447. //if (_trigPressureToleranceWarning.Q && !_trigPressureToleranceAlarm.Q)
  1448. // PMModule.SetPressureToleranceWarning();
  1449. }
  1450. private void ResetTrig()
  1451. {
  1452. PMModule.ResetAlarmCondition();
  1453. foreach (var key in _trigMfcToleranceAlarms.Keys)
  1454. {
  1455. if (_trigMfcToleranceWarnings.ContainsKey(key))
  1456. {
  1457. _trigMfcToleranceAlarms[key].RST = true;
  1458. _trigMfcToleranceWarnings[key].RST = true;
  1459. }
  1460. }
  1461. _trigHeaterBottomToleranceAlarm.RST = true;
  1462. _trigHeaterBottomToleranceWarning.RST = true;
  1463. _trigHeaterCenterBottomToleranceAlarm.RST = true;
  1464. _trigHeaterCenterBottomToleranceWarning.RST = true;
  1465. _trigHeaterCenterToleranceAlarm.RST = true;
  1466. _trigHeaterCenterToleranceWarning.RST = true;
  1467. _trigHeaterCenterTopToleranceAlarm.RST = true;
  1468. _trigHeaterCenterTopToleranceWarning.RST = true;
  1469. _trigHeaterTopToleranceAlarm.RST = true;
  1470. _trigHeaterTopToleranceWarning.RST = true;
  1471. _trigPressureToleranceAlarm.RST = true;
  1472. _trigPressureToleranceWarning.RST = true;
  1473. _trigInputSignalTimeOutAlarm.RST = true;
  1474. _trigTemperatureConvergenceTimeOutAlarm.RST = true;
  1475. _trigReachTempTimeOutAlarm.RST = true;
  1476. _trigPressureConvergenceTimeOutAlarm.RST = true;
  1477. _trigReachPressureTimeOutAlarm.RST = true;
  1478. _trigAutoProfileTimeOutAlarm.RST = true;
  1479. _trigHeaterProfileFinish.RST = true;
  1480. _trigLeakCheckFinish.RST = true;
  1481. _trigBoatWaitCondition.RST = true;
  1482. _trigAPCWaitCondition.RST = true;
  1483. _trigAUXWaitCondition.RST = true;
  1484. _trigHeaterWaitCondition.RST = true;
  1485. _trigMFCWaitCondition.RST = true;
  1486. _infoHeaterProfileFinish = "";
  1487. _infoAUXWaitCondition = "";
  1488. _infoHeaterWaitCondition = "";
  1489. _infoMFCWaitCondition = "";
  1490. }
  1491. private void RecipeExec(string type, List<RecipeStep> curSteps, int currentStepNumber, double curStepElpasedTimeBeforePaused, int otherRecipeStartStepNumber=0)
  1492. {
  1493. var reason = "";
  1494. _stepTimer.Start(curSteps[currentStepNumber].StepTime * 1000 - curStepElpasedTimeBeforePaused);
  1495. _showStepNo = currentStepNumber;
  1496. Notify($"{type} running step {currentStepNumber + 1}:{curSteps[currentStepNumber].StepName}");
  1497. var stopwatch = new Stopwatch();
  1498. stopwatch.Start();
  1499. //执行工艺程序命令
  1500. foreach (var recipeCmd in curSteps[currentStepNumber].RecipeCommands.Keys)
  1501. {
  1502. if (!OP.CanDoOperation($"{_doModule}.{recipeCmd}", out reason, curSteps[currentStepNumber].RecipeCommands[recipeCmd]))
  1503. {
  1504. if (!OP.CanDoOperation($"{Module}.{recipeCmd}", out reason, curSteps[currentStepNumber].RecipeCommands[recipeCmd]))
  1505. {
  1506. if (!OP.CanDoOperation($"{ModuleName.System}.{recipeCmd}", out reason, curSteps[currentStepNumber].RecipeCommands[recipeCmd]))
  1507. {
  1508. PMModule.CheckCanDoOperationAlarm.Set($"Can not execute {recipeCmd}, {reason}");
  1509. return;
  1510. }
  1511. else
  1512. {
  1513. OP.DoOperation($"{ModuleName.System}.{recipeCmd}", out string reason1, 0, curSteps[currentStepNumber].RecipeCommands[recipeCmd]);
  1514. }
  1515. }
  1516. else
  1517. {
  1518. OP.DoOperation($"{Module}.{recipeCmd}", out string reason1, 0, curSteps[currentStepNumber].RecipeCommands[recipeCmd]);
  1519. }
  1520. }
  1521. else
  1522. {
  1523. OP.DoOperation($"{_doModule}.{recipeCmd}", out string reason1, 0, curSteps[currentStepNumber].RecipeCommands[recipeCmd]);
  1524. }
  1525. }
  1526. LOG.Write($"step exec time {stopwatch.ElapsedMilliseconds}");
  1527. if (curSteps[currentStepNumber].EndBy == EnumEndByCondition.ByTime && !PMModule.IsBoatMoveToLoadPosition)
  1528. _state = RecipeRunningState.TimeWait;
  1529. else
  1530. _state = RecipeRunningState.ConditionWait;
  1531. _faCallback.RecipeStepStart(PMModule.Module, PMModule.RecipeRunningInfo.RecipeName, otherRecipeStartStepNumber != 0 ? otherRecipeStartStepNumber : currentStepNumber);
  1532. if (type == "Sub recipe")
  1533. _dbCallback.RecipeStepStart(PMModule.RecipeRunningInfo.InnerId.ToString(), _currentStepNumber, PMModule.RecipeRunningInfo.RecipeStepList.Count > _currentStepNumber ? PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].StepName : "",
  1534. PMModule.RecipeRunningInfo.RecipeStepList.Count > _currentStepNumber ? (float)PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].StepTime : 0,
  1535. $"{(otherRecipeStartStepNumber != 0 ? otherRecipeStartStepNumber : currentStepNumber)}", curSteps[currentStepNumber].StepName, (float)curSteps[currentStepNumber].StepTime,
  1536. $"{PMModule.RecipeRunningInfo.SubRecipeCurrentLoopCount}/{PMModule.RecipeRunningInfo.SubRecipeLoopCount}");
  1537. else
  1538. _dbCallback.RecipeStepStart(PMModule.RecipeRunningInfo.InnerId.ToString(), otherRecipeStartStepNumber != 0 ? otherRecipeStartStepNumber : currentStepNumber,
  1539. curSteps[currentStepNumber].StepName, (float)curSteps[currentStepNumber].StepTime, "", "", 0, "");
  1540. _fdc.Start(curSteps[currentStepNumber].RecipeCommands);
  1541. }
  1542. }
  1543. }