Process.cs 87 KB

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