Process.cs 86 KB

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