Process.cs 90 KB

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