Process.cs 87 KB

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