PMModule.cs 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Linq;
  5. using Aitex.Core.Common;
  6. using Aitex.Core.RT.DataCenter;
  7. using Aitex.Core.RT.Device;
  8. using Aitex.Core.RT.Device.Unit;
  9. using Aitex.Core.RT.Event;
  10. using Aitex.Core.RT.Fsm;
  11. using Aitex.Core.RT.OperationCenter;
  12. using Aitex.Core.RT.Routine;
  13. using Aitex.Core.RT.SCCore;
  14. using Aitex.Core.Util;
  15. using Aitex.Core.Utilities;
  16. using Aitex.Sorter.Common;
  17. using MECF.Framework.Common.Alarms;
  18. using MECF.Framework.Common.DataCenter;
  19. using MECF.Framework.Common.Equipment;
  20. using MECF.Framework.Common.Schedulers;
  21. using MECF.Framework.Common.SubstrateTrackings;
  22. using FurnaceRT.Equipments.PMs.RecipeExecutions;
  23. using FurnaceRT.Equipments.PMs.Routines;
  24. using FurnaceRT.Equipments.Systems;
  25. using Process = FurnaceRT.Equipments.PMs.RecipeExecutions.Process;
  26. using Aitex.Core.Common.DeviceData;
  27. using FurnaceRT.Devices;
  28. using FurnaceRT.Modules.PMs;
  29. using MECF.Framework.Common.Device.Bases;
  30. using Aitex.Core.RT.Log;
  31. using FurnaceRT.Equipments.Boats;
  32. using MECF.Framework.Common.Event;
  33. namespace FurnaceRT.Equipments.PMs
  34. {
  35. public partial class PMModule : PMModuleBase, IRecipeExecutor
  36. {
  37. public enum STATE
  38. {
  39. NotInstall,
  40. NotConnected,
  41. Init,
  42. Idle,
  43. Homing,
  44. OpenSlitValve,
  45. CloseSlitValve,
  46. Error,
  47. PrepareTransfer,
  48. PostTransfer,
  49. PreProcess,
  50. PostProcess,
  51. Process,
  52. LeakCheck,
  53. MFCCali,
  54. Paused,
  55. InTransfer,
  56. }
  57. public enum MSG
  58. {
  59. Home,
  60. Connected,
  61. Disconnected,
  62. Transfer,
  63. PrepareTransfer,
  64. PostTransfer,
  65. Reset,
  66. Abort,
  67. Error,
  68. EndIdleRecipe,
  69. OpenSlitValve,
  70. CloseSlitValve,
  71. SelectRecipe,
  72. RunRecipe,
  73. RunIdleRecipe,
  74. RunOtherRecipe,
  75. RecipeSkipStep,
  76. RecipeJumpStep,
  77. RecipePause,
  78. RecipeContinue,
  79. RecipeAbort,
  80. Continue,
  81. SetOnline,
  82. SetOffline,
  83. PostProcess,
  84. Process,
  85. AlarmConditionJumpStep,
  86. LeakCheck,
  87. ToInit,
  88. StartMFCCalibration,
  89. }
  90. public enum ProcessFlowState
  91. {
  92. None,
  93. Idle,
  94. Standby,
  95. Ready,
  96. Run,
  97. End,
  98. Abort,
  99. }
  100. public override bool IsInit
  101. {
  102. get { return FsmState == (int)STATE.Init; }
  103. }
  104. public bool IsBusy
  105. {
  106. get { return !IsInit && !IsError && !IsReady; }
  107. }
  108. public bool IsProcessing
  109. {
  110. get { return FsmState == (int)STATE.Process; }
  111. }
  112. public override bool IsReady
  113. {
  114. get { return FsmState == (int)STATE.Idle && CheckAllMessageProcessed(); }
  115. }
  116. public override bool IsError
  117. {
  118. get
  119. {
  120. return _alarmNumber != 0;
  121. }
  122. }
  123. public event Action<string> OnEnterError;
  124. private PMHomeRoutine _homeRoutine;
  125. private PMLeakCheckRoutine _leakCheckRoutine;
  126. private PreProcess _preprocessRoutine;
  127. private Process _processRoutine;
  128. private PostProcess _postprocessRoutine;
  129. private PMPrepareTransferRoutine _prepareTransferRoutine;
  130. private PMPostTransferRoutine _postTransferRoutine;
  131. private ModuleName _module;
  132. private RecipeRunningInfo _recipeRunningInfo = new RecipeRunningInfo();
  133. private bool _isInit = true;
  134. private bool _isPrepareProcess = true;
  135. private bool _isStandbyStep;
  136. private StatsData _statTubeCleanNumber;
  137. private StatsData _statTubeCleanTime;
  138. private StatsData _statTubeCleanThick;
  139. private StatsData _statBoatCleanNumber;
  140. private StatsData _statBoatCleanTime;
  141. private StatsData _statBoatCleanThick;
  142. private StatsData _statForkCleanNumber;
  143. private StatsData _statForkCleanTime;
  144. private StatsData _statForkCleanThick;
  145. private Stopwatch _processTimer = new Stopwatch();
  146. public List<IoValve> ValveLists = new List<IoValve>();
  147. public List<IoFlowMeter> FlowmeterLists = new List<IoFlowMeter>();
  148. private bool _isExternalSensorConditionBypass;
  149. private bool _isTempStabilizeConditionBypass;
  150. private bool _isPressureStabilizeConditionBypass;
  151. private bool _isReachTempConditionBypass;
  152. private bool _isReachPressureConditionBypass;
  153. private bool _isFinishAutoProfileConditionBypass;
  154. private SerializableDictionary<string, bool> _conditionCheckDic = new SerializableDictionary<string, bool>();
  155. private Dictionary<string, string> _conditionCheckItemDic = new Dictionary<string, string>();
  156. private Stopwatch _waitTimer = new Stopwatch();
  157. public string StringProcessFlowState { get; set; }
  158. public bool IsExcuteRoutineFailed { get; set; }
  159. public bool IsJobProcess { get; private set; }
  160. public string EditRecipeName { get; set; } = string.Empty;
  161. public string EditRecipeStepName { get; set; } = string.Empty;
  162. public bool IsExcuteIdleRecipe { get; set; }
  163. public string ToolType { get; set; }
  164. public PMModule(ModuleName module) : base(SC.GetValue<int>($"Boat.SlotCount"))
  165. {
  166. _module = module;
  167. Module = module.ToString();
  168. Name = module.ToString();
  169. EnumLoop<STATE>.ForEach((item) =>
  170. {
  171. MapState((int)item, item.ToString());
  172. });
  173. EnumLoop<MSG>.ForEach((item) =>
  174. {
  175. MapMessage((int)item, item.ToString());
  176. });
  177. EnableFsm(1, STATE.Idle);
  178. }
  179. public override bool Initialize()
  180. {
  181. IsOnline = true;
  182. InitRoutine();
  183. InitDevice();
  184. InitAUX();
  185. InitInterlock();
  186. InitFsm();
  187. InitOp();
  188. InitData();
  189. InitLeakCheckData();
  190. InitStats();
  191. InitAlarmEvent();
  192. InitAlarmConditionChecker();
  193. InitScheduleMaintenance();
  194. Singleton<EventManager>.Instance.OnAlarmEvent += Instance_OnAlarmEvent;
  195. ToolType = SC.GetStringValue("System.SetUp.ToolType");
  196. return base.Initialize();
  197. }
  198. private void Instance_OnAlarmEvent(EventItem item)
  199. {
  200. if (item != null && item.Level == EventLevel.Alarm && (item.Source == Name || item.Source == Module))
  201. {
  202. var alarm = item as AlarmEventItem;
  203. DEVICE.GetDevice<SignalTowerBase>("System.SignalTower")?.Reset();
  204. LOG.Write($"{item.Source} {item.EventEnum} {item.Description}\n");
  205. //PostMsg(MSG.Error);
  206. }
  207. }
  208. private void InitRoutine()
  209. {
  210. _homeRoutine = new PMHomeRoutine(ModuleHelper.Converter(Module), this);
  211. _leakCheckRoutine = new PMLeakCheckRoutine(ModuleHelper.Converter(Module), this);
  212. _preprocessRoutine = new PreProcess(ModuleHelper.Converter(Module), this);
  213. _processRoutine = new Process(ModuleHelper.Converter(Module), this);
  214. _postprocessRoutine = new PostProcess(ModuleHelper.Converter(Module), this);
  215. _prepareTransferRoutine = new PMPrepareTransferRoutine(Module, this);
  216. _postTransferRoutine = new PMPostTransferRoutine(Module, this);
  217. }
  218. private void InitData()
  219. {
  220. DATA.Subscribe($"{Module}.IsError", () => IsError);
  221. DATA.Subscribe($"{Module}.Status", () => StringFsmStatus);
  222. DATA.Subscribe($"{Module}.IsOnline", () => IsOnline);
  223. DATA.Subscribe($"{Module}.IsProcessing", () => IsProcessing);
  224. //DATA.Subscribe($"{Module}.WaferSize", () => WaferManager.Instance.GetWaferSize(_module, 0).ToString());
  225. DATA.Subscribe($"{Module}.IsInMaintainMode", () => !IsOnline);
  226. //DATA.Subscribe($"{Name}.LeakCheckElapseTime", () =>
  227. //{
  228. // if (FsmState == (int)STATE.LeakCheck)
  229. // return _leakCheckRoutine.ElapsedTime;
  230. // return 0;
  231. //});
  232. DATA.Subscribe($"{Name}.ChamberPressure", () => ChamberPressure);
  233. //DATA.Subscribe($"{Name}.VAC1", () => _vac1);
  234. //DATA.Subscribe($"{Name}.VAC2", () => _vac2);
  235. //DATA.Subscribe($"{Name}.VAC3", () => _vac3);
  236. DATA.Subscribe($"{Name}.MainRecipeName", () => _recipeRunningInfo.MainRecipeName);
  237. DATA.Subscribe($"{Name}.SelectedRecipeName", () => _recipeRunningInfo.RecipeName);
  238. DATA.Subscribe($"{Name}.ProcessSubRecipe", () => _recipeRunningInfo.SubRecipeName);
  239. DATA.Subscribe($"{Name}.ProcessAbortRecipe", () => _recipeRunningInfo.AbortRecipeName);
  240. DATA.Subscribe($"{Name}.AbortRecipeName", () => _recipeRunningInfo.RecipeName);
  241. DATA.Subscribe($"{Name}.SubRecipeCurrentLoopCount", () => _recipeRunningInfo.SubRecipeCurrentLoopCount);
  242. DATA.Subscribe($"{Name}.SubRecipeLoopCount", () => _recipeRunningInfo.SubRecipeLoopCount);
  243. DATA.Subscribe($"{Name}.IsExecuteSubRecipe", () => _processRoutine.IsSubReciep);
  244. DATA.Subscribe($"{Name}.RecipeBeginTime", () => _recipeRunningInfo.BeginTime);
  245. DATA.Subscribe($"{Name}.RecipeStepNumber", () => _recipeRunningInfo.StepNumber);
  246. DATA.Subscribe($"{Name}.RecipeNextStepName", () => _recipeRunningInfo.NextStepName);
  247. DATA.Subscribe($"{Name}.RecipeStepName", () => _recipeRunningInfo.StepName);
  248. DATA.Subscribe($"{Name}.RecipeStepElapseTime", () => _recipeRunningInfo.StepElapseTime);
  249. DATA.Subscribe($"{Name}.RecipeStepTime", () => _recipeRunningInfo.StepTime);
  250. DATA.Subscribe($"{Name}.RecipeTotalElapseTime", () => _recipeRunningInfo.TotalElapseTime);
  251. DATA.Subscribe($"{Name}.RecipeTotalTime", () => _recipeRunningInfo.TotalTime);
  252. DATA.Subscribe($"{Name}.RecipeHoldTime", () => _recipeRunningInfo.HoldTime);
  253. DATA.Subscribe($"{Name}.RecipeHold", () => IsPaused);//按了hold按键
  254. DATA.Subscribe($"{Name}.RecipeHolded", () => IsHolded);//按了hold按键之后,当前step执行完了
  255. DATA.Subscribe($"{Name}.RecipeWait", () => IsWait);//等待wait条件的结束
  256. DATA.Subscribe($"{Name}.NewShowTime", () => GetNewShowTime());
  257. DATA.Subscribe($"{Name}.ExecRecipeType", () => _recipeRunningInfo.ExecRecipeType);
  258. DATA.Subscribe($"{Name}.LoopCountSet", () => _recipeRunningInfo.LoopCountSet);
  259. DATA.Subscribe($"{Name}.LoopCountCurrent", () => _recipeRunningInfo.LoopCountCurrent);
  260. DATA.Subscribe($"{Name}.IsLooping", () => _recipeRunningInfo.IsLooping);
  261. DATA.Subscribe("ProcessFlow.Status", () => StringProcessFlowState);
  262. DATA.Subscribe($"{Name}.ConditionCheck", () => _conditionCheckDic);
  263. //DATA.Subscribe($"{Name}.LZoneHeaterData", () => Heater2.DeviceData.IsLspModeFeedBack ? Heater2.DeviceData : Heater1.DeviceData);
  264. //DATA.Subscribe($"{Name}.CLZoneHeaterData", () => Heater4.DeviceData.IsLspModeFeedBack ? Heater4.DeviceData : Heater3.DeviceData);
  265. //DATA.Subscribe($"{Name}.CZoneHeaterData", () => Heater6.DeviceData.IsLspModeFeedBack ? Heater6.DeviceData : Heater5.DeviceData);
  266. //DATA.Subscribe($"{Name}.CUZoneHeaterData", () => Heater8.DeviceData.IsLspModeFeedBack ? Heater8.DeviceData : Heater7.DeviceData);
  267. //DATA.Subscribe($"{Name}.UZoneHeaterData", () => Heater10.DeviceData.IsLspModeFeedBack ? Heater10.DeviceData : Heater9.DeviceData);
  268. SensorRecipeOK = new AITSensorData()
  269. {
  270. DeviceName = "SensorRecipeOK",
  271. DeviceSchematicId = "SensorRecipe",
  272. DisplayName = "SensorRecipe",
  273. Value = false,
  274. };
  275. DATA.Subscribe($"{Module}.{SensorRecipeOK.DeviceName}", () => SensorRecipeOK);
  276. SensorPROCManualOK = new AITSensorData()
  277. {
  278. DeviceName = "SensorPROCManualOK",
  279. DeviceSchematicId = "PROCManual",
  280. DisplayName = "PROCManual",
  281. Value = false,
  282. };
  283. DATA.Subscribe($"{Module}.{SensorPROCManualOK.DeviceName}", () => SensorPROCManualOK);
  284. DATA.Subscribe($"{Module}.EditRecipeName", () => EditRecipeName);
  285. DATA.Subscribe($"{Module}.EditRecipeStepName", () => EditRecipeStepName);
  286. DATA.Subscribe($"{Module}.N2PurgeMode", () => _N2PurgeMode.ToString());
  287. DATA.Subscribe($"{Module}.HTR1Enable", () => IsHTR1Enable);
  288. DATA.Subscribe($"{Module}.HTR2Enable", () => IsHTR2Enable);
  289. DATA.Subscribe($"{Module}.HTR3Enable", () => IsHTR3Enable);
  290. DATA.Subscribe($"{Module}.IsCEXHOn", () => _isCEXHOn);
  291. DATA.Subscribe($"{Module}.IsF2ClnOn", () =>
  292. {
  293. return IsF2ClnOn;
  294. });
  295. DATA.Subscribe($"{Module}.IsHFClnOn", () =>
  296. {
  297. return IsHFClnOn;
  298. });
  299. DATA.Subscribe($"{Module}.IsDEPOOn", () => TrigDEPOSW != null ? TrigDEPOSW.Value : false);
  300. DATA.Subscribe($"{Module}.IsCREFOn", () => TrigCREFON != null ? TrigCREFON.Value : false);
  301. DATA.Subscribe($"{Module}.IsSIREFOn", () => TrigSIREFON != null ? TrigSIREFON.Value : false);
  302. }
  303. private void InitStats()
  304. {
  305. _statTubeCleanNumber = new StatsData($"{Module}.Tube Clean Number", "Tube clean number", 0);
  306. _statTubeCleanTime = new StatsData($"{Module}.Tube Clean Time", "Tube clean time(Min)", 0);
  307. _statTubeCleanThick = new StatsData($"{Module}.Tube Clean thick", "Tube clean thick(nm)", 0);
  308. _statBoatCleanNumber = new StatsData($"{Module}.Boat Clean Number", "Boat clean number", 0);
  309. _statBoatCleanTime = new StatsData($"{Module}.Boat Clean Time", "Boat clean time(Min)", 0);
  310. _statBoatCleanThick = new StatsData($"{Module}.Boat Clean thick", "Boat clean thick(nm)", 0);
  311. _statForkCleanNumber = new StatsData($"{Module}.Fork Clean Number", "Fork clean number", 0);
  312. _statForkCleanTime = new StatsData($"{Module}.Fork Clean Time", "Fork clean time(Min)", 0);
  313. _statBoatCleanThick = new StatsData($"{Module}.Boat Clean thick", "Boat clean thick(nm)", 0);
  314. _statForkCleanThick = new StatsData($"{Module}.Fork Clean thick", "Fork clean thick", 0);
  315. }
  316. private void InitOp()
  317. {
  318. OP.Subscribe($"{Module}.Home", (string cmd, object[] args) =>
  319. {
  320. if (!(Singleton<EquipmentManager>.Instance.Modules[ModuleName.WaferRobot] as IModuleDevice).IsReady)
  321. {
  322. TubeHomeFailedWarning.Set($"Wafer Robot is not in ilde state, init failed.");
  323. return false;
  324. }
  325. return CheckToPostMessage((int)MSG.Home);
  326. });
  327. OP.Subscribe($"{Module}.Reset", (string cmd, object[] args) => CheckToPostMessage((int)MSG.Reset));
  328. OP.Subscribe($"{Module}.Abort", (string cmd, object[] args) => CheckToPostMessage((int)MSG.Abort));
  329. OP.Subscribe($"{Module}.PutOnline", (string cmd, object[] args) => CheckToPostMessage((int)MSG.SetOnline));
  330. OP.Subscribe($"{Module}.PutOffline", (string cmd, object[] args) => CheckToPostMessage((int)MSG.SetOffline));
  331. OP.Subscribe($"{Name}.SelectRecipe", (string cmd, object[] args) => CheckToPostMessage((int)MSG.SelectRecipe, args[0]));
  332. OP.Subscribe($"{Name}.RunRecipe", (string cmd, object[] args) => CheckToPostMessage((int)MSG.RunRecipe, (string)args[0]));
  333. OP.Subscribe($"{Name}.RecipeSkipStep", (string cmd, object[] args) => CheckToPostMessage((int)MSG.RecipeSkipStep));
  334. OP.Subscribe($"{Name}.RecipeJumpStep", (string cmd, object[] args) => CheckToPostMessage((int)MSG.RecipeJumpStep, args[0], args[1]));
  335. OP.Subscribe($"{Name}.RecipePause", (string cmd, object[] args) => CheckToPostMessage((int)MSG.RecipePause));
  336. OP.Subscribe($"{Name}.RecipeContinue", (string cmd, object[] args) => CheckToPostMessage((int)MSG.RecipeContinue));
  337. OP.Subscribe($"{Name}.RecipeAbort", (string cmd, object[] args) => CheckToPostMessage((int)MSG.RecipeAbort));
  338. OP.Subscribe($"{Name}.LeakCheck", (string cmd, object[] args) => CheckToPostMessage((int)MSG.LeakCheck, args[0], args[1], args[2], args[3]));
  339. OP.Subscribe($"{Name}.Wait", (string cmd, object[] args) =>
  340. {
  341. IsWait = !IsWait;
  342. return true;
  343. });
  344. OP.Subscribe($"{Module}.AlarmAction", (string cmd, object[] args) =>
  345. {
  346. Enum.TryParse(args[0].ToString(), out AlarmAction alarmAction);
  347. string eventName = null;
  348. if (args.Length > 1)
  349. eventName = args[1].ToString();
  350. if (eventName != null)
  351. {
  352. EV.ClearAlarmEvent(eventName);
  353. var item = _triggeredAlarmList.FirstOrDefault(x => x.EventEnum == eventName);
  354. if (item != null)
  355. {
  356. item.Reset();
  357. _triggeredAlarmList.Remove(item);
  358. }
  359. if (item != null)
  360. {
  361. switch (alarmAction)
  362. {
  363. case AlarmAction.Retry:
  364. {
  365. CheckToPostMessage((int)item.RetryMessage, item.RetryMessageParas);
  366. }
  367. break;
  368. case AlarmAction.Abort:
  369. {
  370. CheckToPostMessage((int)MSG.Abort);
  371. }
  372. break;
  373. case AlarmAction.Clear:
  374. {
  375. int alarmCount = 0;
  376. var alarms = EV.GetAlarmEvent();
  377. foreach (var alarm in alarms)
  378. {
  379. if (alarm.Level == EventLevel.Alarm && alarm.Source == Name)
  380. alarmCount++;
  381. }
  382. if (alarmCount == 0 && !IsProcessing)
  383. {
  384. CheckToPostMessage((int)MSG.Reset);
  385. _alarmNumber = 0;
  386. }
  387. }
  388. break;
  389. case AlarmAction.Continue:
  390. {
  391. int alarmCount = 0;
  392. var alarms = EV.GetAlarmEvent();
  393. foreach (var alarm in alarms)
  394. {
  395. if (alarm.Level == EventLevel.Alarm && alarm.Source == Name)
  396. alarmCount++;
  397. }
  398. if (alarmCount == 0)
  399. CheckToPostMessage((int)MSG.Reset);
  400. }
  401. break;
  402. case AlarmAction.ClearAll:
  403. ResetAUXTrig();
  404. break;
  405. }
  406. }
  407. }
  408. return true;
  409. });
  410. OP.Subscribe($"{Name}.SetConditionCheck", SetConditionCheck);
  411. OP.Subscribe($"{Name}.SetBoatZAxisMotion", SetBoatZAxisMotion);
  412. OP.Subscribe($"{Name}.SetBoatRAxisMotion", SetBoatRAxisMotion);
  413. OP.Subscribe($"{Name}.SetAutoShutterUp", SetAutoShutterUp);
  414. OP.Subscribe($"{Name}.SetAutoShutterOpen", SetAutoShutterOpen);
  415. OP.Subscribe($"{Name}.SetAutoShutterRotateOpen", SetAutoShutterRotateOpen);
  416. OP.Subscribe($"{Name}.BypassStandbyFactor", SeBypassStandbyFactor);
  417. OP.Subscribe($"{Name}.SetCommand", SetCommand);
  418. OP.Subscribe($"{Name}.SetN2PurgeMode", SetN2PurgeMode);
  419. //OP.Subscribe($"{Name}.SetTemperatureDetail",)
  420. OP.Subscribe($"{Name}.SetSensorRecipeOK", SetSensorRecipeOK);
  421. OP.Subscribe($"{Name}.SetSensorPROCManualOK", SetSensorPROCManualOK);
  422. OP.Subscribe($"{Name}.SetEditRecipeName", SetEditRecipeName);
  423. OP.Subscribe($"{Name}.SetEditRecipeStepName", SetEditRecipeStepName);
  424. OP.Subscribe($"{Name}.Heater.SetParameters", (out string reason, int time, object[] param) =>
  425. {
  426. reason = string.Empty;
  427. //Mode参数;Correct Table;PID Table
  428. //"Heater;Parameter\\TempCorrection\\tempCorrect,2,Name2;Parameter\\TempPID\\tempPID,3,Name3"
  429. SetHeaterControlParameters(param);
  430. return true;
  431. });
  432. OP.Subscribe($"{Name}.Heater.SetPID", (out string reason, int time, object[] param) =>
  433. {
  434. reason = string.Empty;
  435. SetHeaterPIDParameters(param[0].ToString());
  436. return true;
  437. });
  438. OP.Subscribe($"{Name}.Heater.SetCorrect", (out string reason, int time, object[] param) =>
  439. {
  440. reason = string.Empty;
  441. SetHeaterCorrectParameters(param[0].ToString());
  442. return true;
  443. });
  444. //Recipe
  445. OP.Subscribe($"{Name}.SetBoatMotion", (out string reason, int time, object[] param) =>
  446. {
  447. reason = string.Empty;
  448. SetBoatMotion(param);
  449. return true;
  450. });
  451. //Recipe
  452. OP.Subscribe($"{Name}.SetValves", (out string reason, int time, object[] param) =>
  453. {
  454. reason = string.Empty;
  455. SetValves(param);
  456. return true;
  457. });
  458. //Recipe
  459. OP.Subscribe($"{Name}.SetAlarmConditionTable", (out string reason, int time, object[] param) =>
  460. {
  461. reason = string.Empty;
  462. SetAlarmConditionTable(param);
  463. return true;
  464. });
  465. //manual
  466. OP.Subscribe($"{Name}.SetAlarmConditionParameter", (out string reason, int time, object[] param) =>
  467. {
  468. reason = string.Empty;
  469. InitAlarmCondition(param[0].ToString());
  470. SetAlarmConditionTable(new object[1] { param[1] });
  471. return true;
  472. });
  473. OP.Subscribe($"{Name}.SetBoatManualMotion", (out string reason, int time, object[] param) =>
  474. {
  475. reason = string.Empty;
  476. SetBoatManualMotion(param);
  477. return true;
  478. });
  479. OP.Subscribe($"{Name}.SetCEXHEnable", (out string reason, int time, object[] param) =>
  480. {
  481. reason = string.Empty;
  482. SetCEXHEnable(param);
  483. return true;
  484. });
  485. OP.Subscribe($"{Name}.SetF2ClnEnable", (out string reason, int time, object[] param) =>
  486. {
  487. reason = string.Empty;
  488. SetF2ClnEnable(param);
  489. return true;
  490. });
  491. OP.Subscribe($"{Name}.SetHFClnEnable", (out string reason, int time, object[] param) =>
  492. {
  493. reason = string.Empty;
  494. SetHFClnEnable(param);
  495. return true;
  496. });
  497. OP.Subscribe($"{Name}.SetDEPOEnable", (out string reason, int time, object[] param) =>
  498. {
  499. reason = string.Empty;
  500. SetDEPOEnable(param);
  501. return true;
  502. });
  503. OP.Subscribe($"{Name}.SetHTR1Enable", (out string reason, int time, object[] param) =>
  504. {
  505. reason = string.Empty;
  506. SetHTR1Enable(param);
  507. return true;
  508. });
  509. OP.Subscribe($"{Name}.SetHTR2Enable", (out string reason, int time, object[] param) =>
  510. {
  511. reason = string.Empty;
  512. SetHTR2Enable(param);
  513. return true;
  514. });
  515. OP.Subscribe($"{Name}.SetHTR3Enable", (out string reason, int time, object[] param) =>
  516. {
  517. reason = string.Empty;
  518. SetHTR3Enable(param);
  519. return true;
  520. });
  521. OP.Subscribe($"{Name}.AUX.SetParameters", (out string reason, int time, object[] param) =>
  522. {
  523. reason = string.Empty;
  524. //Mode参数;Correct Table;PID Table
  525. //"Heater;Parameter\\TempCorrection\\tempCorrect,2,Name2;Parameter\\TempPID\\tempPID,3,Name3"
  526. SetAUXParameters(param);
  527. return true;
  528. });
  529. OP.Subscribe($"{Module}.SetAllMfcVirtualValue", (out string reason, int time, object[] param) =>
  530. {
  531. reason = string.Empty;
  532. var dict = param[0] as Dictionary<string, string>;
  533. foreach (var item in dict)
  534. {
  535. var mfc = _processMFCs.FirstOrDefault(x => x.Name == item.Key);
  536. if (mfc != null)
  537. {
  538. mfc.SetMfcVirtualValue(out reason, 0, new object[] { item.Value });
  539. }
  540. }
  541. return true;
  542. });
  543. OP.Subscribe($"{Module}.SetAllMfcValue", (out string reason, int time, object[] param) =>
  544. {
  545. reason = string.Empty;
  546. var dict = param[0] as Dictionary<string, string>;
  547. foreach (var item in dict)
  548. {
  549. var mfc = _processMFCs.FirstOrDefault(x => x.Name == item.Key);
  550. if (mfc != null)
  551. { mfc.SetMfcValue(out reason, 0, new object[] { item.Value }); }
  552. }
  553. return true;
  554. });
  555. OP.Subscribe($"{Module}.SetAllMfcSetPoint", (out string reason, int time, object[] param) =>
  556. {
  557. reason = string.Empty;
  558. var dict = param[0] as Dictionary<string, string>;
  559. foreach (var item in dict)
  560. {
  561. var mfc = _processMFCs.FirstOrDefault(x => x.Name == item.Key);
  562. if (mfc != null)
  563. { mfc.SetMfcSetPoint(out reason, 0, new object[] { item.Value }); }
  564. }
  565. return true;
  566. });
  567. OP.Subscribe($"{Module}.SetAll{AITValveOperation.GVVirtualTurnValve}", (out string reason, int time, object[] param) =>
  568. {
  569. reason = string.Empty;
  570. var dict = param[0] as Dictionary<string, bool>;
  571. foreach (var item in dict)
  572. {
  573. var valve = _valves.FirstOrDefault(x => x.Name == item.Key);
  574. if (valve != null)
  575. {
  576. valve.InvokeOpenCloseVirtualValve("", new object[] { item.Value });
  577. }
  578. }
  579. return true;
  580. });
  581. OP.Subscribe($"{Module}.SetAll{AITValveOperation.GVTurnValve}", (out string reason, int time, object[] param) =>
  582. {
  583. reason = string.Empty;
  584. var dict = param[0] as Dictionary<string, bool>;
  585. foreach (var item in dict)
  586. {
  587. _valves.FirstOrDefault(x => x.Name == item.Key).InvokeOpenCloseValve("", new object[] { item.Value });
  588. }
  589. return true;
  590. });
  591. OP.Subscribe($"{Name}.SetCREFEnable", (out string reason, int time, object[] param) =>
  592. {
  593. reason = string.Empty;
  594. SetCREFEnable(param);
  595. return true;
  596. });
  597. OP.Subscribe($"{Name}.SetSIREFEnable", (out string reason, int time, object[] param) =>
  598. {
  599. reason = string.Empty;
  600. SetSIREFEnable(param);
  601. return true;
  602. });
  603. }
  604. public void SetTemperatureDetail()
  605. {
  606. }
  607. private void InitFsm()
  608. {
  609. //Error
  610. Transition(STATE.Error, MSG.Reset, FsmReset, STATE.Idle);
  611. AnyStateTransition(MSG.Error, FsmOnError, STATE.Error);
  612. AnyStateTransition(MSG.Disconnected, FsmOnDisconnect, STATE.NotConnected);
  613. EnterExitTransition<STATE, FSM_MSG>(STATE.Error, FsmEnterError, FSM_MSG.NONE, FsmExitError);
  614. Transition(STATE.Idle, MSG.Abort, null, STATE.Idle);
  615. Transition(STATE.Idle, MSG.Reset, null, STATE.Idle);
  616. Transition(STATE.Init, MSG.Reset, null, STATE.Idle);
  617. Transition(STATE.Error, MSG.Abort, null, STATE.Error);
  618. //init
  619. Transition(STATE.Init, MSG.Home, FsmStartHome, STATE.Homing);
  620. AnyStateTransition(MSG.ToInit, FsmToInit, STATE.Init);
  621. //not connected
  622. Transition(STATE.NotConnected, MSG.Connected, null, STATE.Init);
  623. //Home
  624. EnterExitTransition((int)STATE.Homing, FsmEnterHome, (int)FSM_MSG.NONE, FsmExitHome);
  625. Transition(STATE.Error, MSG.Home, FsmStartHome, STATE.Homing);
  626. Transition(STATE.Idle, MSG.Home, FsmStartHome, STATE.Homing);
  627. Transition(STATE.Homing, FSM_MSG.TIMER, FsmMonitorHomeTask, STATE.Idle);
  628. Transition(STATE.Homing, MSG.Error, null, STATE.Init);
  629. Transition(STATE.Homing, MSG.Abort, FsmAbortTask, STATE.Init);
  630. //PrepareTransfer
  631. Transition(STATE.Idle, MSG.PrepareTransfer, FsmStartPrepareTransfer, STATE.PrepareTransfer);
  632. Transition(STATE.PrepareTransfer, FSM_MSG.TIMER, FsmMonitorTask, STATE.Idle);
  633. Transition(STATE.PrepareTransfer, MSG.Abort, FsmAbortTask, STATE.Idle);
  634. //PostTransfer
  635. Transition(STATE.InTransfer, MSG.PostTransfer, FsmStartPostTransfer, STATE.PostTransfer);
  636. Transition(STATE.Idle, MSG.PostTransfer, FsmStartPostTransfer, STATE.PostTransfer);
  637. Transition(STATE.PostTransfer, FSM_MSG.TIMER, FsmMonitorTask, STATE.Idle);
  638. Transition(STATE.PostTransfer, MSG.Abort, FsmAbortTask, STATE.Idle);
  639. //online
  640. Transition(STATE.Idle, MSG.SetOnline, FsmStartSetOnline, STATE.Idle);
  641. Transition(STATE.Idle, MSG.SetOffline, FsmStartSetOffline, STATE.Idle);
  642. //Leak check
  643. Transition(STATE.Idle, MSG.LeakCheck, FsmStartLeakCheck, STATE.LeakCheck);
  644. Transition(STATE.LeakCheck, FSM_MSG.TIMER, FsmMonitorTask, STATE.Idle);
  645. Transition(STATE.LeakCheck, MSG.Abort, FsmAbortTask, STATE.Idle);
  646. EnterExitTransition<STATE, FSM_MSG>(STATE.LeakCheck, FsmEnterLeakCheck, FSM_MSG.NONE, FsmExitLeakCheck);
  647. //open SlitValve
  648. Transition(STATE.Idle, MSG.OpenSlitValve, FsmStartOpenSlitValve, STATE.OpenSlitValve);
  649. Transition(STATE.OpenSlitValve, FSM_MSG.TIMER, FsmMonitorTask, STATE.Idle);
  650. Transition(STATE.OpenSlitValve, MSG.Abort, FsmAbortTask, STATE.Idle);
  651. //close SlitValve
  652. Transition(STATE.Idle, MSG.CloseSlitValve, FsmStartCloseSlitValve, STATE.CloseSlitValve);
  653. Transition(STATE.CloseSlitValve, FSM_MSG.TIMER, FsmMonitorTask, STATE.Idle);
  654. Transition(STATE.CloseSlitValve, MSG.Abort, FsmAbortTask, STATE.Idle);
  655. //PreProcess
  656. Transition(STATE.Process, MSG.RunIdleRecipe, FsmStartIdleRecipePreProcess, STATE.PreProcess);
  657. Transition(STATE.Process, MSG.RunOtherRecipe, FsmStartOtherRecipePreProcess, STATE.PreProcess);
  658. Transition(STATE.Idle, MSG.RunOtherRecipe, FsmStartOtherRecipePreProcess, STATE.PreProcess);
  659. Transition(STATE.Idle, MSG.SelectRecipe, FsmSelectRecipe, STATE.Idle);
  660. Transition(STATE.Idle, MSG.RunRecipe, FsmStartPreProcess, STATE.PreProcess);
  661. Transition(STATE.PreProcess, FSM_MSG.TIMER, FsmMonitorTask, STATE.PreProcess);
  662. Transition(STATE.PreProcess, MSG.Abort, FsmAbortTask, STATE.Idle);
  663. Transition(STATE.PreProcess, MSG.RecipeAbort, FsmAbortTask, STATE.Idle);
  664. //Process
  665. Transition(STATE.PreProcess, MSG.Process, FsmStartProcess, STATE.Process);
  666. Transition(STATE.Idle, MSG.AlarmConditionJumpStep, FsmStartAlarmConditionJumpStep, STATE.Process);
  667. Transition(STATE.Process, FSM_MSG.TIMER, FsmMonitorTask, STATE.Process);
  668. Transition(STATE.Process, MSG.Abort, FsmAbortTask, STATE.Idle);
  669. Transition(STATE.Process, MSG.EndIdleRecipe, null, STATE.Idle);
  670. EnterExitTransition<STATE, FSM_MSG>(STATE.Process, FsmEnterProcess, FSM_MSG.NONE, FsmExitProcess);
  671. Transition(STATE.Paused, FSM_MSG.TIMER, FsmMonitorTask, STATE.Paused);
  672. Transition(STATE.Paused, MSG.Continue, FsmStartContinue, STATE.Process);
  673. Transition(STATE.Paused, MSG.Error, null, STATE.Paused);
  674. Transition(STATE.Paused, MSG.Abort, FsmAbortTask, STATE.Idle);
  675. //Transition(STATE.Paused, MSG.Error, null, STATE.Paused);
  676. Transition(STATE.Process, MSG.RecipeSkipStep, FsmSkipStep, STATE.Process);
  677. Transition(STATE.Process, MSG.RecipeJumpStep, FsmJumpStep, STATE.Process);
  678. Transition(STATE.Process, MSG.RecipePause, FsmRecipePause, STATE.Process);
  679. Transition(STATE.Process, MSG.RecipeContinue, FsmRecipeContinue, STATE.Process);
  680. Transition(STATE.Process, MSG.RecipeAbort, FsmRecipeAbort, STATE.Process);
  681. //PostProcess
  682. Transition(STATE.Process, MSG.PostProcess, FsmStartPostProcess, STATE.PostProcess);
  683. Transition(STATE.PostProcess, FSM_MSG.TIMER, FsmMonitorTask, STATE.Idle);
  684. Transition(STATE.PostProcess, MSG.Abort, FsmAbortTask, STATE.Idle);
  685. EnterExitTransition<STATE, FSM_MSG>(STATE.PostProcess, null, FSM_MSG.NONE, ExitPostProcess);
  686. //MFC Calibration
  687. Transition(STATE.Idle, MSG.StartMFCCalibration, FsmStartMFCCalibration, STATE.MFCCali);
  688. Transition(STATE.MFCCali, FSM_MSG.TIMER, FsmMonitorTask, STATE.Idle);
  689. Transition(STATE.MFCCali, MSG.Abort, FsmAbortTask, STATE.Idle);
  690. }
  691. private bool FsmToInit(object[] param)
  692. {
  693. return true;
  694. }
  695. private bool FsmExitError(object[] param)
  696. {
  697. return true;
  698. }
  699. private bool FsmEnterError(object[] param)
  700. {
  701. if (OnEnterError != null)
  702. OnEnterError(Module);
  703. if (IsOnline)
  704. {
  705. //EV.PostWarningLog(Module, $"{Module}");
  706. }
  707. return true;
  708. }
  709. private bool FsmStartPostTransfer(object[] param)
  710. {
  711. _postTransferRoutine.Init((EnumTransferType)Enum.Parse(typeof(EnumTransferType), (string)param[0]));
  712. Result ret = StartRoutine(_postTransferRoutine);
  713. if (ret == Result.FAIL || ret == Result.DONE)
  714. return false;
  715. return ret == Result.RUN;
  716. }
  717. private bool FsmStartPrepareTransfer(object[] param)
  718. {
  719. _prepareTransferRoutine.Init((EnumTransferType)Enum.Parse(typeof(EnumTransferType), (string)param[0]));
  720. Result ret = StartRoutine(_prepareTransferRoutine);
  721. if (ret == Result.FAIL || ret == Result.DONE)
  722. return false;
  723. return ret == Result.RUN;
  724. }
  725. private bool FsmStartSetOffline(object[] param)
  726. {
  727. IsOnline = false;
  728. return true;
  729. }
  730. private bool FsmStartSetOnline(object[] param)
  731. {
  732. IsOnline = true;
  733. return true;
  734. }
  735. private bool FsmStartLeakCheck(object[] param)
  736. {
  737. _leakCheckRoutine.Init((int)param[0], (int)param[1], (string)param[2], (bool[])param[3]);
  738. Result ret = StartRoutine(_leakCheckRoutine);
  739. if (ret == Result.FAIL || ret == Result.DONE)
  740. return false;
  741. return ret == Result.RUN;
  742. }
  743. private bool FsmEnterLeakCheck(object[] param)
  744. {
  745. return true;
  746. }
  747. private bool FsmExitLeakCheck(object[] param)
  748. {
  749. //ChamberProcessPressureGauge.UnsetTuning();
  750. return true;
  751. }
  752. private bool FsmStartOpenSlitValve(object[] param)
  753. {
  754. return true;
  755. }
  756. private bool FsmStartCloseSlitValve(object[] param)
  757. {
  758. return true;
  759. }
  760. private bool FsmSelectRecipe(object[] param)
  761. {
  762. return true;
  763. }
  764. private bool FsmStartPreProcess(object[] param)
  765. {
  766. _recipeRunningInfo.RecipeName = (string)param[0];
  767. if (!RecipeParser.Parse(_recipeRunningInfo.RecipeName, ModuleName.PM1.ToString(), out var recipeHead, out var recipeSteps, out string reason, "Process"))
  768. {
  769. PreprocessStartFailedWarning.Set($"Load process recipe {_recipeRunningInfo.RecipeName} failed, {reason}");
  770. return false;
  771. }
  772. if (recipeSteps == null || recipeSteps.Count == 0)
  773. {
  774. PreprocessStartFailedWarning.Set($"Process recipe {_recipeRunningInfo.RecipeName} is empty");
  775. return false;
  776. }
  777. string abortRecipeName = SC.ContainsItem("System.Recipe.Abort Recipe") ? SC.GetStringValue("System.Recipe.Abort Recipe") : string.Empty;
  778. if (string.IsNullOrEmpty(abortRecipeName))
  779. {
  780. PreprocessStartFailedWarning.Set($"Load abort recipe failed, recipe file is null");
  781. return false;
  782. }
  783. SC.SetItemValueFromString("PM1.ProcessRecipe", _recipeRunningInfo.RecipeName);
  784. if (!IsJobProcess)
  785. Singleton<EquipmentManager>.Instance.CreatePj((string)param[0]);
  786. _preprocessRoutine.Init((string)param[0]);
  787. Result ret = StartRoutine(_preprocessRoutine);
  788. if (ret == Result.FAIL || ret == Result.DONE)
  789. return false;
  790. if (!IsJobProcess)
  791. SensorPROCManualOK.Value = true;
  792. return ret == Result.RUN;
  793. }
  794. private bool FsmStartOtherRecipePreProcess(object[] param)
  795. {
  796. _recipeRunningInfo.RecipeName = param[0].ToString();
  797. var recipeType = param[1].ToString();
  798. var tableID = 1;
  799. if (param.Length > 2)
  800. int.TryParse(param[2].ToString(), out tableID);
  801. if (!RecipeParser.Parse(_recipeRunningInfo.RecipeName, ModuleName.PM1.ToString(), out var recipeHead, out var recipeSteps, out string reason, recipeType, tableID))
  802. {
  803. PreprocessStartFailedWarning.Set($"Load {recipeType} recipe {_recipeRunningInfo.RecipeName} failed {reason}");
  804. return false;
  805. }
  806. if (recipeSteps == null || recipeSteps.Count == 0)
  807. {
  808. PreprocessStartFailedWarning.Set($"{recipeType} recipe {_recipeRunningInfo.RecipeName} is empty");
  809. return false;
  810. }
  811. if (!IsJobProcess)
  812. Singleton<EquipmentManager>.Instance.CreatePj(_recipeRunningInfo.RecipeName);
  813. _preprocessRoutine.Init(_recipeRunningInfo.RecipeName, false);
  814. RecipeRunningInfo.MainRecipeName = _recipeRunningInfo.RecipeName;
  815. RecipeRunningInfo.Head = recipeHead;
  816. RecipeRunningInfo.RecipeStepList = recipeSteps;
  817. Result ret = StartRoutine(_preprocessRoutine);
  818. if (ret == Result.FAIL || ret == Result.DONE)
  819. return false;
  820. if (!IsJobProcess)
  821. SensorPROCManualOK.Value = true;
  822. return ret == Result.RUN;
  823. }
  824. private bool FsmStartIdleRecipePreProcess(object[] param)
  825. {
  826. if (!CheckBoatState())
  827. {
  828. PreprocessStartFailedWarning.Set($"boat is not ready");
  829. return false;
  830. }
  831. _recipeRunningInfo.RecipeName = SC.ContainsItem("System.Recipe.Idle Recipe") ? SC.GetStringValue("System.Recipe.Idle Recipe") : string.Empty;
  832. if (!RecipeParser.Parse(_recipeRunningInfo.RecipeName, ModuleName.PM1.ToString(), out var recipeHead, out var recipeSteps, out string reason, "Idle"))
  833. {
  834. PreprocessStartFailedWarning.Set($"Load idle recipe {_recipeRunningInfo.RecipeName} failed {reason}");
  835. return false;
  836. }
  837. if (recipeSteps == null || recipeSteps.Count == 0)
  838. {
  839. PreprocessStartFailedWarning.Set($"Process recipe {_recipeRunningInfo.RecipeName} is empty");
  840. return false;
  841. }
  842. if (!IsJobProcess)
  843. Singleton<EquipmentManager>.Instance.CreatePj(_recipeRunningInfo.RecipeName);
  844. _preprocessRoutine.Init(_recipeRunningInfo.RecipeName, false);
  845. RecipeRunningInfo.MainRecipeName = _recipeRunningInfo.RecipeName;
  846. RecipeRunningInfo.Head = recipeHead;
  847. RecipeRunningInfo.RecipeStepList = recipeSteps;
  848. Result ret = StartRoutine(_preprocessRoutine);
  849. if (ret == Result.FAIL || ret == Result.DONE)
  850. return false;
  851. if (!IsJobProcess)
  852. SensorPROCManualOK.Value = true;
  853. return ret == Result.RUN;
  854. }
  855. private bool FsmStartProcess(object[] param)
  856. {
  857. Result ret = StartRoutine(_processRoutine);
  858. if (ret == Result.FAIL || ret == Result.DONE)
  859. return false;
  860. if (ret == Result.RUN && !IsJobProcess)
  861. Singleton<EquipmentManager>.Instance.StartPj();
  862. return ret == Result.RUN;
  863. }
  864. private bool FsmStartAlarmConditionJumpStep(object[] param)
  865. {
  866. if (param != null && param.Length > 0)
  867. {
  868. int.TryParse(param[0].ToString(), out int jumpStep);
  869. _processRoutine.AlarmConditionJumpStep = jumpStep;
  870. Result ret = StartRoutine(_processRoutine);
  871. if (ret == Result.FAIL || ret == Result.DONE)
  872. return false;
  873. return ret == Result.RUN;
  874. }
  875. return false;
  876. }
  877. private bool FsmEnterProcess(object[] param)
  878. {
  879. for (int i = 0; i < SC.GetValue<int>($"Boat.SlotCount"); i++)
  880. {
  881. if (!WaferManager.Instance.CheckHasWafer(ModuleHelper.Converter(Module), i))
  882. continue;
  883. WaferManager.Instance.UpdateWaferProcessStatus(ModuleHelper.Converter(Module), i, EnumWaferProcessStatus.InProcess);
  884. }
  885. _processTimer.Restart();
  886. return true;
  887. }
  888. private bool FsmExitProcess(object[] param)
  889. {
  890. _processRoutine.ExitProcess();
  891. //_statWaferCount.Increase();
  892. //_statProcessTime.Increase((int)(_processTimer.ElapsedMilliseconds/1000));
  893. _isPrepareProcess = true;
  894. IsJobProcess = false;
  895. SensorPROCManualOK.Value = false;
  896. //if (SC.GetStringValue($"System.Recipe.ExcuteAfterRecipeComplete") == "StandbyStep")
  897. //{
  898. // StringProcessFlowState = ProcessFlowState.Standby.ToString();
  899. // _recipeRunningInfo.StepName = "Standby";
  900. // var standbyStep = _recipeRunningInfo.RecipeStepList.Where(x => x.StepName == "Standby").FirstOrDefault();
  901. // if (standbyStep != null)
  902. // {
  903. // EV.PostInfoLog(Module, $"Recipe {_recipeRunningInfo.RecipeName} complete excute standby step");
  904. // foreach (var recipeCmd in standbyStep.RecipeCommands.Keys)
  905. // {
  906. // if (!OP.CanDoOperation($"{Module}.{recipeCmd}", out string reason, standbyStep.RecipeCommands[recipeCmd]))
  907. // {
  908. // if (!OP.CanDoOperation($"{ModuleName.PM1}.{recipeCmd}", out reason, standbyStep.RecipeCommands[recipeCmd]))
  909. // {
  910. // if (!OP.CanDoOperation($"{ModuleName.System}.{recipeCmd}", out reason, standbyStep.RecipeCommands[recipeCmd]))
  911. // {
  912. // reason = $"Can not execute {recipeCmd}, {reason}";
  913. // return false;
  914. // }
  915. // else
  916. // {
  917. // OP.DoOperation($"{ModuleName.System}.{recipeCmd}", out string reason1, 0, standbyStep.RecipeCommands[recipeCmd]);
  918. // }
  919. // }
  920. // else
  921. // {
  922. // OP.DoOperation($"{ModuleName.PM1}.{recipeCmd}", out string reason1, 0, standbyStep.RecipeCommands[recipeCmd]);
  923. // }
  924. // }
  925. // else
  926. // {
  927. // OP.DoOperation($"{Module}.{recipeCmd}", out string reason1, 0, standbyStep.RecipeCommands[recipeCmd]);
  928. // }
  929. // }
  930. // }
  931. // _isStandbyStep = true;
  932. // IsExcuteIdleRecipe = false;
  933. //}
  934. //else if (SC.GetStringValue($"System.Recipe.ExcuteAfterRecipeComplete") == "IdleRecipe")
  935. //{
  936. // if (!IsExcuteIdleRecipe)
  937. // {
  938. // PostMsg((int)MSG.RunIdleRecipe);
  939. // IsExcuteIdleRecipe = true;
  940. // }
  941. // else
  942. // {
  943. // IsExcuteIdleRecipe = false;
  944. // _isStandbyStep = false;
  945. // }
  946. //}
  947. //else
  948. //{
  949. // IsExcuteIdleRecipe = false;
  950. // _isStandbyStep = false;
  951. //}
  952. return true;
  953. }
  954. private bool FsmStartContinue(object[] param)
  955. {
  956. return true;
  957. }
  958. private bool FsmSkipStep(object[] param)
  959. {
  960. _processRoutine.SkipCurrentRecipeStep();
  961. return true;
  962. }
  963. private bool FsmJumpStep(object[] param)
  964. {
  965. int.TryParse(param[0].ToString(), out int stepNumber);
  966. _processRoutine.JumpCurrentRecipeStep(stepNumber, param[1].ToString());
  967. return true;
  968. }
  969. private bool FsmRecipePause(object[] param)
  970. {
  971. _processRoutine.PauseRecipe();
  972. return true;
  973. }
  974. private bool FsmRecipeContinue(object[] param)
  975. {
  976. _processRoutine.ContinueRecipe();
  977. return true;
  978. }
  979. private bool FsmRecipeAbort(object[] param)
  980. {
  981. Singleton<EquipmentManager>.Instance.EndPj("Recipe Abort");
  982. _processRoutine.Abort();
  983. IsWait = false;
  984. return true;
  985. }
  986. private bool FsmStartPostProcess(object[] param)
  987. {
  988. Result ret = StartRoutine(_postprocessRoutine);
  989. if (ret == Result.FAIL || ret == Result.DONE)
  990. return false;
  991. return ret == Result.RUN;
  992. }
  993. private bool ExitPostProcess(object[] param)
  994. {
  995. return true;
  996. }
  997. private bool FsmStartMFCCalibration(object[] param)
  998. {
  999. return true;
  1000. }
  1001. private bool FsmOnDisconnect(object[] param)
  1002. {
  1003. if (FsmState == (int)STATE.Error)
  1004. {
  1005. return false;
  1006. }
  1007. return true;
  1008. }
  1009. private bool FsmOnError(object[] param)
  1010. {
  1011. if (FsmState == (int)STATE.Error)
  1012. {
  1013. return false;
  1014. }
  1015. if ((FsmState == (int)STATE.Process) || (FsmState == (int)STATE.PreProcess) || (FsmState == (int)STATE.PostProcess))
  1016. {
  1017. for (int i = 0; i < SC.GetValue<int>($"Boat.SlotCount"); i++)
  1018. {
  1019. if (!WaferManager.Instance.CheckHasWafer(ModuleHelper.Converter(Module), i))
  1020. continue;
  1021. WaferManager.Instance.UpdateWaferProcessStatus(ModuleHelper.Converter(Module), i, EnumWaferProcessStatus.Failed);
  1022. }
  1023. _processRoutine.Abort();
  1024. _postprocessRoutine.Abort();
  1025. _preprocessRoutine.Abort();
  1026. IsWait = false;
  1027. }
  1028. return true;
  1029. }
  1030. private bool FsmReset(object[] param)
  1031. {
  1032. if (!_isInit)
  1033. {
  1034. PostMsg(MSG.ToInit);
  1035. return false;
  1036. }
  1037. foreach (var device in _allModuleDevice)
  1038. {
  1039. if (device.HasAlarm)
  1040. {
  1041. CheckHasAlarmWarning.Set($"{device.Name} has error");
  1042. }
  1043. }
  1044. if (CheckHasAlarm())
  1045. return false;
  1046. return true;
  1047. }
  1048. private bool FsmStartHome(object[] param)
  1049. {
  1050. //if (!CheckIsConnected())
  1051. //{
  1052. // PostMsg(MSG.Disconnected);
  1053. // return false;
  1054. //}
  1055. if (CheckHasAlarm())
  1056. {
  1057. CheckHasAlarmWarning.Set($"There exist active alarm, reset error before continue the initialization");
  1058. PostMsg(MSG.Error);
  1059. return false;
  1060. }
  1061. Result ret = StartRoutine(_homeRoutine);
  1062. if (ret == Result.FAIL || ret == Result.DONE)
  1063. return false;
  1064. _isInit = false;
  1065. return ret == Result.RUN;
  1066. }
  1067. private bool FsmExitHome(object[] param)
  1068. {
  1069. return true;
  1070. }
  1071. private bool FsmEnterHome(object[] param)
  1072. {
  1073. return true;
  1074. }
  1075. private bool FsmAbortTask(object[] param)
  1076. {
  1077. AbortRoutine();
  1078. _isPrepareProcess = true;
  1079. return true;
  1080. }
  1081. private bool FsmMonitorHomeTask(object[] param)
  1082. {
  1083. Result ret = MonitorRoutine();
  1084. if (ret == Result.FAIL)
  1085. {
  1086. PostMsg(MSG.Error);
  1087. return false;
  1088. }
  1089. if (ret == Result.DONE)
  1090. {
  1091. _isInit = true;
  1092. return true;
  1093. }
  1094. return false;
  1095. }
  1096. private bool FsmMonitorTask(object[] param)
  1097. {
  1098. Result ret = MonitorRoutine();
  1099. if (ret == Result.FAIL)
  1100. {
  1101. PostMsg(MSG.Error);
  1102. return false;
  1103. }
  1104. if (ret == Result.DONE && FsmState == (int)STATE.PreProcess)
  1105. {
  1106. PostMsg(MSG.Process);
  1107. return true;
  1108. }
  1109. if (ret == Result.DONE && FsmState == (int)STATE.Process)
  1110. {
  1111. PostMsg(MSG.PostProcess);
  1112. return true;
  1113. }
  1114. if (ret == Result.DONE && IsExcuteIdleRecipe && FsmState == (int)STATE.PostProcess)
  1115. {
  1116. PostMsg(MSG.RunIdleRecipe);
  1117. return true;
  1118. }
  1119. return ret == Result.DONE;
  1120. }
  1121. #region Service functions
  1122. public override bool Home(out string reason)
  1123. {
  1124. CheckToPostMessage((int)MSG.Home);
  1125. reason = string.Empty;
  1126. return true;
  1127. }
  1128. public override void Reset()
  1129. {
  1130. ResetAUXTrig();
  1131. if (!IsProcessing)
  1132. CheckToPostMessage((int)MSG.Reset);
  1133. }
  1134. public override bool PrepareTransfer(ModuleName robot, Hand blade, int targetSlot, EnumTransferType transferType, out string reason)
  1135. {
  1136. CheckToPostMessage((int)MSG.PrepareTransfer, transferType.ToString());
  1137. reason = string.Empty;
  1138. return true;
  1139. }
  1140. public override bool TransferHandoff(ModuleName robot, Hand blade, int targetSlot, EnumTransferType transferType, out string reason)
  1141. {
  1142. reason = string.Empty;
  1143. return true;
  1144. }
  1145. public override bool PostTransfer(ModuleName robot, Hand blade, int targetSlot, EnumTransferType transferType, out string reason)
  1146. {
  1147. CheckToPostMessage((int)MSG.PostTransfer, transferType.ToString());
  1148. reason = string.Empty;
  1149. return true;
  1150. }
  1151. public override bool CheckReadyForTransfer(ModuleName robot, Hand blade, int targetSlot, EnumTransferType transferType, out string reason)
  1152. {
  1153. reason = string.Empty;
  1154. var boat = Singleton<EquipmentManager>.Instance.Modules[ModuleName.Boat] as BoatModule;
  1155. if (!boat.IsBoatElevatorAtHomePosition)
  1156. {
  1157. reason = "Boat z axis is not at home position";
  1158. return false;
  1159. }
  1160. if (!boat.IsBoatRotationAtHomePosition)
  1161. {
  1162. reason = "Boat r axis is not at home position";
  1163. return false;
  1164. }
  1165. return true;
  1166. }
  1167. public override void NoteTransferStart(ModuleName robot, Hand blade, int targetSlot, EnumTransferType transferType)
  1168. {
  1169. //if (FsmState == (int)STATE.InTransfer)
  1170. // CheckToPostMessage(MSG.Transfer)
  1171. }
  1172. public override void NoteTransferStop(ModuleName robot, Hand blade, int targetSlot, EnumTransferType transferType)
  1173. {
  1174. //if (FsmState == (int)STATE.InTransfer)
  1175. // CheckToPostMessage(MSG.Transfer)
  1176. }
  1177. public override bool Process(string recipeName, bool isCleanRecipe, bool withWafer, out string reason)
  1178. {
  1179. _recipeRunningInfo.RecipeName = recipeName;
  1180. _isPrepareProcess = false;
  1181. _isStandbyStep = false;
  1182. IsJobProcess = true;
  1183. IsExcuteIdleRecipe = false;
  1184. CheckToPostMessage((int)MSG.RunRecipe, recipeName);
  1185. reason = string.Empty;
  1186. return true;
  1187. }
  1188. public override bool Standby(string recipeName, out string reason)
  1189. {
  1190. reason = string.Empty;
  1191. _recipeRunningInfo.RecipeName = recipeName;
  1192. _recipeRunningInfo.MainRecipeName = recipeName;
  1193. if (!RecipeParser.Parse(_recipeRunningInfo.RecipeName, ModuleName.PM1.ToString(), out var recipeHead, out var recipeSteps, out reason, "Process"))
  1194. {
  1195. reason = $"Load process recipe {_recipeRunningInfo.RecipeName} failed, {reason}";
  1196. return false;
  1197. }
  1198. if (recipeSteps == null || recipeSteps.Count == 0)
  1199. {
  1200. reason = $"Process recipe {_recipeRunningInfo.RecipeName} is empty";
  1201. return false;
  1202. }
  1203. _isStandbyStep = true;
  1204. var standbyStep = recipeSteps.Where(x => x.StepName == "Standby").FirstOrDefault();
  1205. if (standbyStep != null)
  1206. {
  1207. StringProcessFlowState = ProcessFlowState.Standby.ToString();
  1208. _recipeRunningInfo.StepName = "Standby";
  1209. EV.PostInfoLog(Module, $"pj job excute recipe {recipeName} standby step");
  1210. foreach (var recipeCmd in standbyStep.RecipeCommands.Keys)
  1211. {
  1212. if (!OP.CanDoOperation($"{Module}.{recipeCmd}", out reason, standbyStep.RecipeCommands[recipeCmd]))
  1213. {
  1214. if (!OP.CanDoOperation($"{ModuleName.PM1}.{recipeCmd}", out reason, standbyStep.RecipeCommands[recipeCmd]))
  1215. {
  1216. if (!OP.CanDoOperation($"{ModuleName.System}.{recipeCmd}", out reason, standbyStep.RecipeCommands[recipeCmd]))
  1217. {
  1218. reason = $"Can not execute {recipeCmd}, {reason}";
  1219. return false;
  1220. }
  1221. else
  1222. {
  1223. OP.DoOperation($"{ModuleName.System}.{recipeCmd}", out string reason1, 0, standbyStep.RecipeCommands[recipeCmd]);
  1224. }
  1225. }
  1226. else
  1227. {
  1228. OP.DoOperation($"{ModuleName.PM1}.{recipeCmd}", out string reason1, 0, standbyStep.RecipeCommands[recipeCmd]);
  1229. }
  1230. }
  1231. else
  1232. {
  1233. OP.DoOperation($"{Module}.{recipeCmd}", out string reason1, 0, standbyStep.RecipeCommands[recipeCmd]);
  1234. }
  1235. }
  1236. }
  1237. return true;
  1238. }
  1239. public void EndIdleRecipe()
  1240. {
  1241. CheckToPostMessage((int)MSG.EndIdleRecipe);
  1242. }
  1243. private double GetNewShowTime()
  1244. {
  1245. return GetWaitTime() + _recipeRunningInfo.HoldTime;
  1246. }
  1247. private double GetWaitTime()
  1248. {
  1249. if (StringFsmStatus=="Idle")
  1250. {
  1251. _waitTimer.Reset();
  1252. }
  1253. if (IsWait)
  1254. {
  1255. _waitTimer.Start();
  1256. }
  1257. else
  1258. {
  1259. _waitTimer.Stop();
  1260. }
  1261. return _waitTimer.ElapsedMilliseconds / 1000;
  1262. }
  1263. }
  1264. #endregion
  1265. }