PMModule.cs 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524
  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($"{Name}.RemainTimeToEnterCooling", () => _recipeRunningInfo.RemainTimeExcludeEndStep - _recipeRunningInfo.TotalElapseTime, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  262. DATA.Subscribe("ProcessFlow.Status", () => StringProcessFlowState);
  263. DATA.Subscribe($"{Name}.ConditionCheck", () => _conditionCheckDic);
  264. //DATA.Subscribe($"{Name}.LZoneHeaterData", () => Heater2.DeviceData.IsLspModeFeedBack ? Heater2.DeviceData : Heater1.DeviceData);
  265. //DATA.Subscribe($"{Name}.CLZoneHeaterData", () => Heater4.DeviceData.IsLspModeFeedBack ? Heater4.DeviceData : Heater3.DeviceData);
  266. //DATA.Subscribe($"{Name}.CZoneHeaterData", () => Heater6.DeviceData.IsLspModeFeedBack ? Heater6.DeviceData : Heater5.DeviceData);
  267. //DATA.Subscribe($"{Name}.CUZoneHeaterData", () => Heater8.DeviceData.IsLspModeFeedBack ? Heater8.DeviceData : Heater7.DeviceData);
  268. //DATA.Subscribe($"{Name}.UZoneHeaterData", () => Heater10.DeviceData.IsLspModeFeedBack ? Heater10.DeviceData : Heater9.DeviceData);
  269. SensorRecipeOK = new AITSensorData()
  270. {
  271. DeviceName = "SensorRecipeOK",
  272. DeviceSchematicId = "SensorRecipe",
  273. DisplayName = "SensorRecipe",
  274. Value = false,
  275. };
  276. DATA.Subscribe($"{Module}.{SensorRecipeOK.DeviceName}", () => SensorRecipeOK);
  277. SensorPROCManualOK = new AITSensorData()
  278. {
  279. DeviceName = "SensorPROCManualOK",
  280. DeviceSchematicId = "PROCManual",
  281. DisplayName = "PROCManual",
  282. Value = false,
  283. };
  284. DATA.Subscribe($"{Module}.{SensorPROCManualOK.DeviceName}", () => SensorPROCManualOK);
  285. DATA.Subscribe($"{Module}.EditRecipeName", () => EditRecipeName);
  286. DATA.Subscribe($"{Module}.EditRecipeStepName", () => EditRecipeStepName);
  287. DATA.Subscribe($"{Module}.N2PurgeMode", () => _N2PurgeMode.ToString());
  288. DATA.Subscribe($"{Module}.HTR1Enable", () => IsHTR1Enable);
  289. DATA.Subscribe($"{Module}.HTR2Enable", () => IsHTR2Enable);
  290. DATA.Subscribe($"{Module}.HTR3Enable", () => IsHTR3Enable);
  291. DATA.Subscribe($"{Module}.IsCEXHOn", () => _isCEXHOn);
  292. DATA.Subscribe($"{Module}.IsF2ClnOn", () =>
  293. {
  294. return IsF2ClnOn;
  295. });
  296. DATA.Subscribe($"{Module}.IsHFClnOn", () =>
  297. {
  298. return IsHFClnOn;
  299. });
  300. DATA.Subscribe($"{Module}.IsDEPOOn", () => TrigDEPOSW != null ? TrigDEPOSW.Value : false);
  301. DATA.Subscribe($"{Module}.IsCREFOn", () => TrigCREFON != null ? TrigCREFON.Value : false);
  302. DATA.Subscribe($"{Module}.IsSIREFOn", () => TrigSIREFON != null ? TrigSIREFON.Value : false);
  303. }
  304. private void InitStats()
  305. {
  306. _statTubeCleanNumber = new StatsData($"{Module}.Tube Clean Number", "Tube clean number", 0);
  307. _statTubeCleanTime = new StatsData($"{Module}.Tube Clean Time", "Tube clean time(Min)", 0);
  308. _statTubeCleanThick = new StatsData($"{Module}.Tube Clean thick", "Tube clean thick(nm)", 0);
  309. _statBoatCleanNumber = new StatsData($"{Module}.Boat Clean Number", "Boat clean number", 0);
  310. _statBoatCleanTime = new StatsData($"{Module}.Boat Clean Time", "Boat clean time(Min)", 0);
  311. _statBoatCleanThick = new StatsData($"{Module}.Boat Clean thick", "Boat clean thick(nm)", 0);
  312. _statForkCleanNumber = new StatsData($"{Module}.Fork Clean Number", "Fork clean number", 0);
  313. _statForkCleanTime = new StatsData($"{Module}.Fork Clean Time", "Fork clean time(Min)", 0);
  314. _statBoatCleanThick = new StatsData($"{Module}.Boat Clean thick", "Boat clean thick(nm)", 0);
  315. _statForkCleanThick = new StatsData($"{Module}.Fork Clean thick", "Fork clean thick", 0);
  316. }
  317. private void InitOp()
  318. {
  319. OP.Subscribe($"{Module}.Home", (string cmd, object[] args) =>
  320. {
  321. if (!(Singleton<EquipmentManager>.Instance.Modules[ModuleName.WaferRobot] as IModuleDevice).IsReady)
  322. {
  323. TubeHomeFailedWarning.Set($"Wafer Robot is not in ilde state, init failed.");
  324. return false;
  325. }
  326. return CheckToPostMessage((int)MSG.Home);
  327. });
  328. OP.Subscribe($"{Module}.Reset", (string cmd, object[] args) => CheckToPostMessage((int)MSG.Reset));
  329. OP.Subscribe($"{Module}.Abort", (string cmd, object[] args) => CheckToPostMessage((int)MSG.Abort));
  330. OP.Subscribe($"{Module}.PutOnline", (string cmd, object[] args) => CheckToPostMessage((int)MSG.SetOnline));
  331. OP.Subscribe($"{Module}.PutOffline", (string cmd, object[] args) => CheckToPostMessage((int)MSG.SetOffline));
  332. OP.Subscribe($"{Name}.SelectRecipe", (string cmd, object[] args) => CheckToPostMessage((int)MSG.SelectRecipe, args[0]));
  333. OP.Subscribe($"{Name}.RunRecipe", (string cmd, object[] args) => CheckToPostMessage((int)MSG.RunRecipe, (string)args[0]));
  334. OP.Subscribe($"{Name}.RecipeSkipStep", (string cmd, object[] args) => CheckToPostMessage((int)MSG.RecipeSkipStep));
  335. OP.Subscribe($"{Name}.RecipeJumpStep", (string cmd, object[] args) => CheckToPostMessage((int)MSG.RecipeJumpStep, args[0], args[1]));
  336. OP.Subscribe($"{Name}.RecipePause", (string cmd, object[] args) => CheckToPostMessage((int)MSG.RecipePause));
  337. OP.Subscribe($"{Name}.RecipeContinue", (string cmd, object[] args) => CheckToPostMessage((int)MSG.RecipeContinue));
  338. OP.Subscribe($"{Name}.RecipeAbort", (string cmd, object[] args) => CheckToPostMessage((int)MSG.RecipeAbort));
  339. OP.Subscribe($"{Name}.LeakCheck", (string cmd, object[] args) => CheckToPostMessage((int)MSG.LeakCheck, args[0], args[1], args[2], args[3]));
  340. OP.Subscribe($"{Name}.Wait", (string cmd, object[] args) =>
  341. {
  342. IsWait = !IsWait;
  343. return true;
  344. });
  345. OP.Subscribe($"{Module}.AlarmAction", (string cmd, object[] args) =>
  346. {
  347. Enum.TryParse(args[0].ToString(), out AlarmAction alarmAction);
  348. string eventName = null;
  349. if (args.Length > 1)
  350. eventName = args[1].ToString();
  351. if (eventName != null)
  352. {
  353. EV.ClearAlarmEvent(eventName);
  354. var item = _triggeredAlarmList.FirstOrDefault(x => x.EventEnum == eventName);
  355. if (item != null)
  356. {
  357. item.Reset();
  358. _triggeredAlarmList.Remove(item);
  359. }
  360. if (item != null)
  361. {
  362. switch (alarmAction)
  363. {
  364. case AlarmAction.Retry:
  365. {
  366. CheckToPostMessage((int)item.RetryMessage, item.RetryMessageParas);
  367. }
  368. break;
  369. case AlarmAction.Abort:
  370. {
  371. CheckToPostMessage((int)MSG.Abort);
  372. }
  373. break;
  374. case AlarmAction.Clear:
  375. {
  376. int alarmCount = 0;
  377. var alarms = EV.GetAlarmEvent();
  378. foreach (var alarm in alarms)
  379. {
  380. if (alarm.Level == EventLevel.Alarm && alarm.Source == Name)
  381. alarmCount++;
  382. }
  383. if (alarmCount == 0 && !IsProcessing)
  384. {
  385. CheckToPostMessage((int)MSG.Reset);
  386. _alarmNumber = 0;
  387. }
  388. }
  389. break;
  390. case AlarmAction.Continue:
  391. {
  392. int alarmCount = 0;
  393. var alarms = EV.GetAlarmEvent();
  394. foreach (var alarm in alarms)
  395. {
  396. if (alarm.Level == EventLevel.Alarm && alarm.Source == Name)
  397. alarmCount++;
  398. }
  399. if (alarmCount == 0)
  400. CheckToPostMessage((int)MSG.Reset);
  401. }
  402. break;
  403. case AlarmAction.ClearAll:
  404. ResetAUXTrig();
  405. break;
  406. }
  407. }
  408. }
  409. return true;
  410. });
  411. OP.Subscribe($"{Name}.SetConditionCheck", SetConditionCheck);
  412. OP.Subscribe($"{Name}.SetBoatZAxisMotion", SetBoatZAxisMotion);
  413. OP.Subscribe($"{Name}.SetBoatRAxisMotion", SetBoatRAxisMotion);
  414. OP.Subscribe($"{Name}.SetAutoShutterUp", SetAutoShutterUp);
  415. OP.Subscribe($"{Name}.SetAutoShutterOpen", SetAutoShutterOpen);
  416. OP.Subscribe($"{Name}.SetAutoShutterRotateOpen", SetAutoShutterRotateOpen);
  417. OP.Subscribe($"{Name}.BypassStandbyFactor", SeBypassStandbyFactor);
  418. OP.Subscribe($"{Name}.SetCommand", SetCommand);
  419. OP.Subscribe($"{Name}.SetN2PurgeMode", SetN2PurgeMode);
  420. //OP.Subscribe($"{Name}.SetTemperatureDetail",)
  421. OP.Subscribe($"{Name}.SetSensorRecipeOK", SetSensorRecipeOK);
  422. OP.Subscribe($"{Name}.SetSensorPROCManualOK", SetSensorPROCManualOK);
  423. OP.Subscribe($"{Name}.SetEditRecipeName", SetEditRecipeName);
  424. OP.Subscribe($"{Name}.SetEditRecipeStepName", SetEditRecipeStepName);
  425. OP.Subscribe($"{Name}.Heater.SetParameters", (out string reason, int time, object[] param) =>
  426. {
  427. reason = string.Empty;
  428. //Mode参数;Correct Table;PID Table
  429. //"Heater;Parameter\\TempCorrection\\tempCorrect,2,Name2;Parameter\\TempPID\\tempPID,3,Name3"
  430. SetHeaterControlParameters(param);
  431. return true;
  432. });
  433. OP.Subscribe($"{Name}.Heater.SetPID", (out string reason, int time, object[] param) =>
  434. {
  435. reason = string.Empty;
  436. SetHeaterPIDParameters(param[0].ToString());
  437. return true;
  438. });
  439. OP.Subscribe($"{Name}.Heater.SetCorrect", (out string reason, int time, object[] param) =>
  440. {
  441. reason = string.Empty;
  442. SetHeaterCorrectParameters(param[0].ToString());
  443. return true;
  444. });
  445. //Recipe
  446. OP.Subscribe($"{Name}.SetBoatMotion", (out string reason, int time, object[] param) =>
  447. {
  448. reason = string.Empty;
  449. SetBoatMotion(param);
  450. return true;
  451. });
  452. //Recipe
  453. OP.Subscribe($"{Name}.SetValves", (out string reason, int time, object[] param) =>
  454. {
  455. reason = string.Empty;
  456. SetValves(param);
  457. return true;
  458. });
  459. //Recipe
  460. OP.Subscribe($"{Name}.SetAlarmConditionTable", (out string reason, int time, object[] param) =>
  461. {
  462. reason = string.Empty;
  463. SetAlarmConditionTable(param);
  464. return true;
  465. });
  466. //manual
  467. OP.Subscribe($"{Name}.SetAlarmConditionParameter", (out string reason, int time, object[] param) =>
  468. {
  469. reason = string.Empty;
  470. InitAlarmCondition(param[0].ToString());
  471. SetAlarmConditionTable(new object[1] { param[1] });
  472. return true;
  473. });
  474. OP.Subscribe($"{Name}.SetBoatManualMotion", (out string reason, int time, object[] param) =>
  475. {
  476. reason = string.Empty;
  477. SetBoatManualMotion(param);
  478. return true;
  479. });
  480. OP.Subscribe($"{Name}.SetCEXHEnable", (out string reason, int time, object[] param) =>
  481. {
  482. reason = string.Empty;
  483. SetCEXHEnable(param);
  484. return true;
  485. });
  486. OP.Subscribe($"{Name}.SetF2ClnEnable", (out string reason, int time, object[] param) =>
  487. {
  488. reason = string.Empty;
  489. SetF2ClnEnable(param);
  490. return true;
  491. });
  492. OP.Subscribe($"{Name}.SetHFClnEnable", (out string reason, int time, object[] param) =>
  493. {
  494. reason = string.Empty;
  495. SetHFClnEnable(param);
  496. return true;
  497. });
  498. OP.Subscribe($"{Name}.SetDEPOEnable", (out string reason, int time, object[] param) =>
  499. {
  500. reason = string.Empty;
  501. SetDEPOEnable(param);
  502. return true;
  503. });
  504. OP.Subscribe($"{Name}.SetHTR1Enable", (out string reason, int time, object[] param) =>
  505. {
  506. reason = string.Empty;
  507. SetHTR1Enable(param);
  508. return true;
  509. });
  510. OP.Subscribe($"{Name}.SetHTR2Enable", (out string reason, int time, object[] param) =>
  511. {
  512. reason = string.Empty;
  513. SetHTR2Enable(param);
  514. return true;
  515. });
  516. OP.Subscribe($"{Name}.SetHTR3Enable", (out string reason, int time, object[] param) =>
  517. {
  518. reason = string.Empty;
  519. SetHTR3Enable(param);
  520. return true;
  521. });
  522. OP.Subscribe($"{Name}.AUX.SetParameters", (out string reason, int time, object[] param) =>
  523. {
  524. reason = string.Empty;
  525. //Mode参数;Correct Table;PID Table
  526. //"Heater;Parameter\\TempCorrection\\tempCorrect,2,Name2;Parameter\\TempPID\\tempPID,3,Name3"
  527. SetAUXParameters(param);
  528. return true;
  529. });
  530. OP.Subscribe($"{Module}.SetAllMfcVirtualValue", (out string reason, int time, object[] param) =>
  531. {
  532. reason = string.Empty;
  533. var dict = param[0] as Dictionary<string, string>;
  534. foreach (var item in dict)
  535. {
  536. var mfc = _processMFCs.FirstOrDefault(x => x.Name == item.Key);
  537. if (mfc != null)
  538. {
  539. mfc.SetMfcVirtualValue(out reason, 0, new object[] { item.Value });
  540. }
  541. }
  542. return true;
  543. });
  544. OP.Subscribe($"{Module}.SetAllMfcValue", (out string reason, int time, object[] param) =>
  545. {
  546. reason = string.Empty;
  547. var dict = param[0] as Dictionary<string, string>;
  548. foreach (var item in dict)
  549. {
  550. var mfc = _processMFCs.FirstOrDefault(x => x.Name == item.Key);
  551. if (mfc != null)
  552. { mfc.SetMfcValue(out reason, 0, new object[] { item.Value }); }
  553. }
  554. return true;
  555. });
  556. OP.Subscribe($"{Module}.SetAllMfcSetPoint", (out string reason, int time, object[] param) =>
  557. {
  558. reason = string.Empty;
  559. var dict = param[0] as Dictionary<string, string>;
  560. foreach (var item in dict)
  561. {
  562. var mfc = _processMFCs.FirstOrDefault(x => x.Name == item.Key);
  563. if (mfc != null)
  564. { mfc.SetMfcSetPoint(out reason, 0, new object[] { item.Value }); }
  565. }
  566. return true;
  567. });
  568. OP.Subscribe($"{Module}.SetAll{AITValveOperation.GVVirtualTurnValve}", (out string reason, int time, object[] param) =>
  569. {
  570. reason = string.Empty;
  571. var dict = param[0] as Dictionary<string, bool>;
  572. foreach (var item in dict)
  573. {
  574. var valve = _valves.FirstOrDefault(x => x.Name == item.Key);
  575. if (valve != null)
  576. {
  577. valve.InvokeOpenCloseVirtualValve("", new object[] { item.Value });
  578. }
  579. }
  580. return true;
  581. });
  582. OP.Subscribe($"{Module}.SetAll{AITValveOperation.GVTurnValve}", (out string reason, int time, object[] param) =>
  583. {
  584. reason = string.Empty;
  585. var dict = param[0] as Dictionary<string, bool>;
  586. foreach (var item in dict)
  587. {
  588. _valves.FirstOrDefault(x => x.Name == item.Key).InvokeOpenCloseValve("", new object[] { item.Value });
  589. }
  590. return true;
  591. });
  592. OP.Subscribe($"{Name}.SetCREFEnable", (out string reason, int time, object[] param) =>
  593. {
  594. reason = string.Empty;
  595. SetCREFEnable(param);
  596. return true;
  597. });
  598. OP.Subscribe($"{Name}.SetSIREFEnable", (out string reason, int time, object[] param) =>
  599. {
  600. reason = string.Empty;
  601. SetSIREFEnable(param);
  602. return true;
  603. });
  604. }
  605. public void SetTemperatureDetail()
  606. {
  607. }
  608. private void InitFsm()
  609. {
  610. //Error
  611. Transition(STATE.Error, MSG.Reset, FsmReset, STATE.Idle);
  612. AnyStateTransition(MSG.Error, FsmOnError, STATE.Error);
  613. AnyStateTransition(MSG.Disconnected, FsmOnDisconnect, STATE.NotConnected);
  614. EnterExitTransition<STATE, FSM_MSG>(STATE.Error, FsmEnterError, FSM_MSG.NONE, FsmExitError);
  615. Transition(STATE.Idle, MSG.Abort, null, STATE.Idle);
  616. Transition(STATE.Idle, MSG.Reset, null, STATE.Idle);
  617. Transition(STATE.Init, MSG.Reset, null, STATE.Idle);
  618. Transition(STATE.Error, MSG.Abort, null, STATE.Error);
  619. //init
  620. Transition(STATE.Init, MSG.Home, FsmStartHome, STATE.Homing);
  621. AnyStateTransition(MSG.ToInit, FsmToInit, STATE.Init);
  622. //not connected
  623. Transition(STATE.NotConnected, MSG.Connected, null, STATE.Init);
  624. //Home
  625. EnterExitTransition((int)STATE.Homing, FsmEnterHome, (int)FSM_MSG.NONE, FsmExitHome);
  626. Transition(STATE.Error, MSG.Home, FsmStartHome, STATE.Homing);
  627. Transition(STATE.Idle, MSG.Home, FsmStartHome, STATE.Homing);
  628. Transition(STATE.Homing, FSM_MSG.TIMER, FsmMonitorHomeTask, STATE.Idle);
  629. Transition(STATE.Homing, MSG.Error, null, STATE.Init);
  630. Transition(STATE.Homing, MSG.Abort, FsmAbortTask, STATE.Init);
  631. //PrepareTransfer
  632. Transition(STATE.Idle, MSG.PrepareTransfer, FsmStartPrepareTransfer, STATE.PrepareTransfer);
  633. Transition(STATE.PrepareTransfer, FSM_MSG.TIMER, FsmMonitorTask, STATE.Idle);
  634. Transition(STATE.PrepareTransfer, MSG.Abort, FsmAbortTask, STATE.Idle);
  635. //PostTransfer
  636. Transition(STATE.InTransfer, MSG.PostTransfer, FsmStartPostTransfer, STATE.PostTransfer);
  637. Transition(STATE.Idle, MSG.PostTransfer, FsmStartPostTransfer, STATE.PostTransfer);
  638. Transition(STATE.PostTransfer, FSM_MSG.TIMER, FsmMonitorTask, STATE.Idle);
  639. Transition(STATE.PostTransfer, MSG.Abort, FsmAbortTask, STATE.Idle);
  640. //online
  641. Transition(STATE.Idle, MSG.SetOnline, FsmStartSetOnline, STATE.Idle);
  642. Transition(STATE.Idle, MSG.SetOffline, FsmStartSetOffline, STATE.Idle);
  643. //Leak check
  644. Transition(STATE.Idle, MSG.LeakCheck, FsmStartLeakCheck, STATE.LeakCheck);
  645. Transition(STATE.LeakCheck, FSM_MSG.TIMER, FsmMonitorTask, STATE.Idle);
  646. Transition(STATE.LeakCheck, MSG.Abort, FsmAbortTask, STATE.Idle);
  647. EnterExitTransition<STATE, FSM_MSG>(STATE.LeakCheck, FsmEnterLeakCheck, FSM_MSG.NONE, FsmExitLeakCheck);
  648. //open SlitValve
  649. Transition(STATE.Idle, MSG.OpenSlitValve, FsmStartOpenSlitValve, STATE.OpenSlitValve);
  650. Transition(STATE.OpenSlitValve, FSM_MSG.TIMER, FsmMonitorTask, STATE.Idle);
  651. Transition(STATE.OpenSlitValve, MSG.Abort, FsmAbortTask, STATE.Idle);
  652. //close SlitValve
  653. Transition(STATE.Idle, MSG.CloseSlitValve, FsmStartCloseSlitValve, STATE.CloseSlitValve);
  654. Transition(STATE.CloseSlitValve, FSM_MSG.TIMER, FsmMonitorTask, STATE.Idle);
  655. Transition(STATE.CloseSlitValve, MSG.Abort, FsmAbortTask, STATE.Idle);
  656. //PreProcess
  657. Transition(STATE.Process, MSG.RunIdleRecipe, FsmStartIdleRecipePreProcess, STATE.PreProcess);
  658. Transition(STATE.Process, MSG.RunOtherRecipe, FsmStartOtherRecipePreProcess, STATE.PreProcess);
  659. Transition(STATE.Idle, MSG.RunOtherRecipe, FsmStartOtherRecipePreProcess, STATE.PreProcess);
  660. Transition(STATE.Idle, MSG.SelectRecipe, FsmSelectRecipe, STATE.Idle);
  661. Transition(STATE.Idle, MSG.RunRecipe, FsmStartPreProcess, STATE.PreProcess);
  662. Transition(STATE.PreProcess, FSM_MSG.TIMER, FsmMonitorTask, STATE.PreProcess);
  663. Transition(STATE.PreProcess, MSG.Abort, FsmAbortTask, STATE.Idle);
  664. Transition(STATE.PreProcess, MSG.RecipeAbort, FsmAbortTask, STATE.Idle);
  665. //Process
  666. Transition(STATE.PreProcess, MSG.Process, FsmStartProcess, STATE.Process);
  667. Transition(STATE.Idle, MSG.AlarmConditionJumpStep, FsmStartAlarmConditionJumpStep, STATE.Process);
  668. Transition(STATE.Process, FSM_MSG.TIMER, FsmMonitorTask, STATE.Process);
  669. Transition(STATE.Process, MSG.Abort, FsmAbortTask, STATE.Idle);
  670. Transition(STATE.Process, MSG.EndIdleRecipe, null, STATE.Idle);
  671. EnterExitTransition<STATE, FSM_MSG>(STATE.Process, FsmEnterProcess, FSM_MSG.NONE, FsmExitProcess);
  672. Transition(STATE.Paused, FSM_MSG.TIMER, FsmMonitorTask, STATE.Paused);
  673. Transition(STATE.Paused, MSG.Continue, FsmStartContinue, STATE.Process);
  674. Transition(STATE.Paused, MSG.Error, null, STATE.Paused);
  675. Transition(STATE.Paused, MSG.Abort, FsmAbortTask, STATE.Idle);
  676. //Transition(STATE.Paused, MSG.Error, null, STATE.Paused);
  677. Transition(STATE.Process, MSG.RecipeSkipStep, FsmSkipStep, STATE.Process);
  678. Transition(STATE.Process, MSG.RecipeJumpStep, FsmJumpStep, STATE.Process);
  679. Transition(STATE.Process, MSG.RecipePause, FsmRecipePause, STATE.Process);
  680. Transition(STATE.Process, MSG.RecipeContinue, FsmRecipeContinue, STATE.Process);
  681. Transition(STATE.Process, MSG.RecipeAbort, FsmRecipeAbort, STATE.Process);
  682. //PostProcess
  683. Transition(STATE.Process, MSG.PostProcess, FsmStartPostProcess, STATE.PostProcess);
  684. Transition(STATE.PostProcess, FSM_MSG.TIMER, FsmMonitorTask, STATE.Idle);
  685. Transition(STATE.PostProcess, MSG.Abort, FsmAbortTask, STATE.Idle);
  686. EnterExitTransition<STATE, FSM_MSG>(STATE.PostProcess, null, FSM_MSG.NONE, ExitPostProcess);
  687. //MFC Calibration
  688. Transition(STATE.Idle, MSG.StartMFCCalibration, FsmStartMFCCalibration, STATE.MFCCali);
  689. Transition(STATE.MFCCali, FSM_MSG.TIMER, FsmMonitorTask, STATE.Idle);
  690. Transition(STATE.MFCCali, MSG.Abort, FsmAbortTask, STATE.Idle);
  691. }
  692. private bool FsmToInit(object[] param)
  693. {
  694. return true;
  695. }
  696. private bool FsmExitError(object[] param)
  697. {
  698. return true;
  699. }
  700. private bool FsmEnterError(object[] param)
  701. {
  702. if (OnEnterError != null)
  703. OnEnterError(Module);
  704. if (IsOnline)
  705. {
  706. //EV.PostWarningLog(Module, $"{Module}");
  707. }
  708. return true;
  709. }
  710. private bool FsmStartPostTransfer(object[] param)
  711. {
  712. _postTransferRoutine.Init((EnumTransferType)Enum.Parse(typeof(EnumTransferType), (string)param[0]));
  713. Result ret = StartRoutine(_postTransferRoutine);
  714. if (ret == Result.FAIL || ret == Result.DONE)
  715. return false;
  716. return ret == Result.RUN;
  717. }
  718. private bool FsmStartPrepareTransfer(object[] param)
  719. {
  720. _prepareTransferRoutine.Init((EnumTransferType)Enum.Parse(typeof(EnumTransferType), (string)param[0]));
  721. Result ret = StartRoutine(_prepareTransferRoutine);
  722. if (ret == Result.FAIL || ret == Result.DONE)
  723. return false;
  724. return ret == Result.RUN;
  725. }
  726. private bool FsmStartSetOffline(object[] param)
  727. {
  728. IsOnline = false;
  729. return true;
  730. }
  731. private bool FsmStartSetOnline(object[] param)
  732. {
  733. IsOnline = true;
  734. return true;
  735. }
  736. private bool FsmStartLeakCheck(object[] param)
  737. {
  738. _leakCheckRoutine.Init((int)param[0], (int)param[1], (string)param[2], (bool[])param[3]);
  739. Result ret = StartRoutine(_leakCheckRoutine);
  740. if (ret == Result.FAIL || ret == Result.DONE)
  741. return false;
  742. return ret == Result.RUN;
  743. }
  744. private bool FsmEnterLeakCheck(object[] param)
  745. {
  746. return true;
  747. }
  748. private bool FsmExitLeakCheck(object[] param)
  749. {
  750. //ChamberProcessPressureGauge.UnsetTuning();
  751. return true;
  752. }
  753. private bool FsmStartOpenSlitValve(object[] param)
  754. {
  755. return true;
  756. }
  757. private bool FsmStartCloseSlitValve(object[] param)
  758. {
  759. return true;
  760. }
  761. private bool FsmSelectRecipe(object[] param)
  762. {
  763. return true;
  764. }
  765. private bool FsmStartPreProcess(object[] param)
  766. {
  767. _recipeRunningInfo.RecipeName = (string)param[0];
  768. if (!RecipeParser.Parse(_recipeRunningInfo.RecipeName, ModuleName.PM1.ToString(), out var recipeHead, out var recipeSteps, out string reason, "Process"))
  769. {
  770. PreprocessStartFailedWarning.Set($"Load process recipe {_recipeRunningInfo.RecipeName} failed, {reason}");
  771. return false;
  772. }
  773. if (recipeSteps == null || recipeSteps.Count == 0)
  774. {
  775. PreprocessStartFailedWarning.Set($"Process recipe {_recipeRunningInfo.RecipeName} is empty");
  776. return false;
  777. }
  778. string abortRecipeName = SC.ContainsItem("System.Recipe.Abort Recipe") ? SC.GetStringValue("System.Recipe.Abort Recipe") : string.Empty;
  779. if (string.IsNullOrEmpty(abortRecipeName))
  780. {
  781. PreprocessStartFailedWarning.Set($"Load abort recipe failed, recipe file is null");
  782. return false;
  783. }
  784. SC.SetItemValueFromString("PM1.ProcessRecipe", _recipeRunningInfo.RecipeName);
  785. if (!IsJobProcess)
  786. Singleton<EquipmentManager>.Instance.CreatePj((string)param[0]);
  787. _preprocessRoutine.Init((string)param[0]);
  788. Result ret = StartRoutine(_preprocessRoutine);
  789. if (ret == Result.FAIL || ret == Result.DONE)
  790. return false;
  791. if (!IsJobProcess)
  792. SensorPROCManualOK.Value = true;
  793. return ret == Result.RUN;
  794. }
  795. private bool FsmStartOtherRecipePreProcess(object[] param)
  796. {
  797. _recipeRunningInfo.RecipeName = param[0].ToString();
  798. var recipeType = param[1].ToString();
  799. var tableID = 1;
  800. if (param.Length > 2)
  801. int.TryParse(param[2].ToString(), out tableID);
  802. if (!RecipeParser.Parse(_recipeRunningInfo.RecipeName, ModuleName.PM1.ToString(), out var recipeHead, out var recipeSteps, out string reason, recipeType, tableID))
  803. {
  804. PreprocessStartFailedWarning.Set($"Load {recipeType} recipe {_recipeRunningInfo.RecipeName} failed {reason}");
  805. return false;
  806. }
  807. if (recipeSteps == null || recipeSteps.Count == 0)
  808. {
  809. PreprocessStartFailedWarning.Set($"{recipeType} recipe {_recipeRunningInfo.RecipeName} is empty");
  810. return false;
  811. }
  812. if (!IsJobProcess)
  813. Singleton<EquipmentManager>.Instance.CreatePj(_recipeRunningInfo.RecipeName);
  814. _preprocessRoutine.Init(_recipeRunningInfo.RecipeName, false);
  815. RecipeRunningInfo.MainRecipeName = _recipeRunningInfo.RecipeName;
  816. RecipeRunningInfo.Head = recipeHead;
  817. RecipeRunningInfo.RecipeStepList = recipeSteps;
  818. Result ret = StartRoutine(_preprocessRoutine);
  819. if (ret == Result.FAIL || ret == Result.DONE)
  820. return false;
  821. if (!IsJobProcess)
  822. SensorPROCManualOK.Value = true;
  823. return ret == Result.RUN;
  824. }
  825. private bool FsmStartIdleRecipePreProcess(object[] param)
  826. {
  827. if (!CheckBoatState())
  828. {
  829. PreprocessStartFailedWarning.Set($"boat is not ready");
  830. return false;
  831. }
  832. _recipeRunningInfo.RecipeName = SC.ContainsItem("System.Recipe.Idle Recipe") ? SC.GetStringValue("System.Recipe.Idle Recipe") : string.Empty;
  833. if (!RecipeParser.Parse(_recipeRunningInfo.RecipeName, ModuleName.PM1.ToString(), out var recipeHead, out var recipeSteps, out string reason, "Idle"))
  834. {
  835. PreprocessStartFailedWarning.Set($"Load idle recipe {_recipeRunningInfo.RecipeName} failed {reason}");
  836. return false;
  837. }
  838. if (recipeSteps == null || recipeSteps.Count == 0)
  839. {
  840. PreprocessStartFailedWarning.Set($"Process recipe {_recipeRunningInfo.RecipeName} is empty");
  841. return false;
  842. }
  843. if (!IsJobProcess)
  844. Singleton<EquipmentManager>.Instance.CreatePj(_recipeRunningInfo.RecipeName);
  845. _preprocessRoutine.Init(_recipeRunningInfo.RecipeName, false);
  846. RecipeRunningInfo.MainRecipeName = _recipeRunningInfo.RecipeName;
  847. RecipeRunningInfo.Head = recipeHead;
  848. RecipeRunningInfo.RecipeStepList = recipeSteps;
  849. Result ret = StartRoutine(_preprocessRoutine);
  850. if (ret == Result.FAIL || ret == Result.DONE)
  851. return false;
  852. if (!IsJobProcess)
  853. SensorPROCManualOK.Value = true;
  854. return ret == Result.RUN;
  855. }
  856. private bool FsmStartProcess(object[] param)
  857. {
  858. Result ret = StartRoutine(_processRoutine);
  859. if (ret == Result.FAIL || ret == Result.DONE)
  860. return false;
  861. if (ret == Result.RUN && !IsJobProcess)
  862. Singleton<EquipmentManager>.Instance.StartPj();
  863. return ret == Result.RUN;
  864. }
  865. private bool FsmStartAlarmConditionJumpStep(object[] param)
  866. {
  867. if (param != null && param.Length > 0)
  868. {
  869. int.TryParse(param[0].ToString(), out int jumpStep);
  870. _processRoutine.AlarmConditionJumpStep = jumpStep;
  871. Result ret = StartRoutine(_processRoutine);
  872. if (ret == Result.FAIL || ret == Result.DONE)
  873. return false;
  874. return ret == Result.RUN;
  875. }
  876. return false;
  877. }
  878. private bool FsmEnterProcess(object[] param)
  879. {
  880. for (int i = 0; i < SC.GetValue<int>($"Boat.SlotCount"); i++)
  881. {
  882. if (!WaferManager.Instance.CheckHasWafer(ModuleHelper.Converter(Module), i))
  883. continue;
  884. WaferManager.Instance.UpdateWaferProcessStatus(ModuleHelper.Converter(Module), i, EnumWaferProcessStatus.InProcess);
  885. }
  886. _processTimer.Restart();
  887. return true;
  888. }
  889. private bool FsmExitProcess(object[] param)
  890. {
  891. _processRoutine.ExitProcess();
  892. if (!IsJobProcess && !_processRoutine.IsExecuteAbort)//非jobprocess需要recipe结束也需要更新数据库
  893. {
  894. var firstPjId = Singleton<EquipmentManager>.Instance.GetFirstPJId();
  895. Singleton<EquipmentManager>.Instance.EndPj();
  896. _processRoutine.UpdateProcessDataPJid(firstPjId);
  897. }
  898. //_statWaferCount.Increase();
  899. //_statProcessTime.Increase((int)(_processTimer.ElapsedMilliseconds/1000));
  900. _isPrepareProcess = true;
  901. IsJobProcess = false;
  902. SensorPROCManualOK.Value = false;
  903. //if (SC.GetStringValue($"System.Recipe.ExcuteAfterRecipeComplete") == "StandbyStep")
  904. //{
  905. // StringProcessFlowState = ProcessFlowState.Standby.ToString();
  906. // _recipeRunningInfo.StepName = "Standby";
  907. // var standbyStep = _recipeRunningInfo.RecipeStepList.Where(x => x.StepName == "Standby").FirstOrDefault();
  908. // if (standbyStep != null)
  909. // {
  910. // EV.PostInfoLog(Module, $"Recipe {_recipeRunningInfo.RecipeName} complete excute standby step");
  911. // foreach (var recipeCmd in standbyStep.RecipeCommands.Keys)
  912. // {
  913. // if (!OP.CanDoOperation($"{Module}.{recipeCmd}", out string reason, standbyStep.RecipeCommands[recipeCmd]))
  914. // {
  915. // if (!OP.CanDoOperation($"{ModuleName.PM1}.{recipeCmd}", out reason, standbyStep.RecipeCommands[recipeCmd]))
  916. // {
  917. // if (!OP.CanDoOperation($"{ModuleName.System}.{recipeCmd}", out reason, standbyStep.RecipeCommands[recipeCmd]))
  918. // {
  919. // reason = $"Can not execute {recipeCmd}, {reason}";
  920. // return false;
  921. // }
  922. // else
  923. // {
  924. // OP.DoOperation($"{ModuleName.System}.{recipeCmd}", out string reason1, 0, standbyStep.RecipeCommands[recipeCmd]);
  925. // }
  926. // }
  927. // else
  928. // {
  929. // OP.DoOperation($"{ModuleName.PM1}.{recipeCmd}", out string reason1, 0, standbyStep.RecipeCommands[recipeCmd]);
  930. // }
  931. // }
  932. // else
  933. // {
  934. // OP.DoOperation($"{Module}.{recipeCmd}", out string reason1, 0, standbyStep.RecipeCommands[recipeCmd]);
  935. // }
  936. // }
  937. // }
  938. // _isStandbyStep = true;
  939. // IsExcuteIdleRecipe = false;
  940. //}
  941. //else if (SC.GetStringValue($"System.Recipe.ExcuteAfterRecipeComplete") == "IdleRecipe")
  942. //{
  943. // if (!IsExcuteIdleRecipe)
  944. // {
  945. // PostMsg((int)MSG.RunIdleRecipe);
  946. // IsExcuteIdleRecipe = true;
  947. // }
  948. // else
  949. // {
  950. // IsExcuteIdleRecipe = false;
  951. // _isStandbyStep = false;
  952. // }
  953. //}
  954. //else
  955. //{
  956. // IsExcuteIdleRecipe = false;
  957. // _isStandbyStep = false;
  958. //}
  959. return true;
  960. }
  961. private bool FsmStartContinue(object[] param)
  962. {
  963. return true;
  964. }
  965. private bool FsmSkipStep(object[] param)
  966. {
  967. _processRoutine.SkipCurrentRecipeStep();
  968. return true;
  969. }
  970. private bool FsmJumpStep(object[] param)
  971. {
  972. int.TryParse(param[0].ToString(), out int stepNumber);
  973. _processRoutine.JumpCurrentRecipeStep(stepNumber, param[1].ToString());
  974. return true;
  975. }
  976. private bool FsmRecipePause(object[] param)
  977. {
  978. _processRoutine.PauseRecipe();
  979. return true;
  980. }
  981. private bool FsmRecipeContinue(object[] param)
  982. {
  983. _processRoutine.ContinueRecipe();
  984. return true;
  985. }
  986. private bool FsmRecipeAbort(object[] param)
  987. {
  988. Singleton<EquipmentManager>.Instance.EndPj("Recipe Abort");
  989. _processRoutine.Abort();
  990. IsWait = false;
  991. return true;
  992. }
  993. private bool FsmStartPostProcess(object[] param)
  994. {
  995. Result ret = StartRoutine(_postprocessRoutine);
  996. if (ret == Result.FAIL || ret == Result.DONE)
  997. return false;
  998. return ret == Result.RUN;
  999. }
  1000. private bool ExitPostProcess(object[] param)
  1001. {
  1002. return true;
  1003. }
  1004. private bool FsmStartMFCCalibration(object[] param)
  1005. {
  1006. return true;
  1007. }
  1008. private bool FsmOnDisconnect(object[] param)
  1009. {
  1010. if (FsmState == (int)STATE.Error)
  1011. {
  1012. return false;
  1013. }
  1014. return true;
  1015. }
  1016. private bool FsmOnError(object[] param)
  1017. {
  1018. if (FsmState == (int)STATE.Error)
  1019. {
  1020. return false;
  1021. }
  1022. if ((FsmState == (int)STATE.Process) || (FsmState == (int)STATE.PreProcess) || (FsmState == (int)STATE.PostProcess))
  1023. {
  1024. for (int i = 0; i < SC.GetValue<int>($"Boat.SlotCount"); i++)
  1025. {
  1026. if (!WaferManager.Instance.CheckHasWafer(ModuleHelper.Converter(Module), i))
  1027. continue;
  1028. WaferManager.Instance.UpdateWaferProcessStatus(ModuleHelper.Converter(Module), i, EnumWaferProcessStatus.Failed);
  1029. }
  1030. _processRoutine.Abort();
  1031. _postprocessRoutine.Abort();
  1032. _preprocessRoutine.Abort();
  1033. IsWait = false;
  1034. }
  1035. return true;
  1036. }
  1037. private bool FsmReset(object[] param)
  1038. {
  1039. if (!_isInit)
  1040. {
  1041. PostMsg(MSG.ToInit);
  1042. return false;
  1043. }
  1044. foreach (var device in _allModuleDevice)
  1045. {
  1046. if (device.HasAlarm)
  1047. {
  1048. CheckHasAlarmWarning.Set($"{device.Name} has error");
  1049. }
  1050. }
  1051. if (CheckHasAlarm())
  1052. return false;
  1053. return true;
  1054. }
  1055. private bool FsmStartHome(object[] param)
  1056. {
  1057. //if (!CheckIsConnected())
  1058. //{
  1059. // PostMsg(MSG.Disconnected);
  1060. // return false;
  1061. //}
  1062. if (CheckHasAlarm())
  1063. {
  1064. CheckHasAlarmWarning.Set($"There exist active alarm, reset error before continue the initialization");
  1065. PostMsg(MSG.Error);
  1066. return false;
  1067. }
  1068. Result ret = StartRoutine(_homeRoutine);
  1069. if (ret == Result.FAIL || ret == Result.DONE)
  1070. return false;
  1071. _isInit = false;
  1072. return ret == Result.RUN;
  1073. }
  1074. private bool FsmExitHome(object[] param)
  1075. {
  1076. return true;
  1077. }
  1078. private bool FsmEnterHome(object[] param)
  1079. {
  1080. return true;
  1081. }
  1082. private bool FsmAbortTask(object[] param)
  1083. {
  1084. AbortRoutine();
  1085. _isPrepareProcess = true;
  1086. return true;
  1087. }
  1088. private bool FsmMonitorHomeTask(object[] param)
  1089. {
  1090. Result ret = MonitorRoutine();
  1091. if (ret == Result.FAIL)
  1092. {
  1093. PostMsg(MSG.Error);
  1094. return false;
  1095. }
  1096. if (ret == Result.DONE)
  1097. {
  1098. _isInit = true;
  1099. return true;
  1100. }
  1101. return false;
  1102. }
  1103. private bool FsmMonitorTask(object[] param)
  1104. {
  1105. Result ret = MonitorRoutine();
  1106. if (ret == Result.FAIL)
  1107. {
  1108. PostMsg(MSG.Error);
  1109. return false;
  1110. }
  1111. if (ret == Result.DONE && FsmState == (int)STATE.PreProcess)
  1112. {
  1113. PostMsg(MSG.Process);
  1114. return true;
  1115. }
  1116. if (ret == Result.DONE && FsmState == (int)STATE.Process)
  1117. {
  1118. PostMsg(MSG.PostProcess);
  1119. return true;
  1120. }
  1121. if (ret == Result.DONE && IsExcuteIdleRecipe && FsmState == (int)STATE.PostProcess)
  1122. {
  1123. PostMsg(MSG.RunIdleRecipe);
  1124. return true;
  1125. }
  1126. return ret == Result.DONE;
  1127. }
  1128. #region Service functions
  1129. public override bool Home(out string reason)
  1130. {
  1131. CheckToPostMessage((int)MSG.Home);
  1132. reason = string.Empty;
  1133. return true;
  1134. }
  1135. public override void Reset()
  1136. {
  1137. ResetAUXTrig();
  1138. if (!IsProcessing)
  1139. CheckToPostMessage((int)MSG.Reset);
  1140. }
  1141. public override bool PrepareTransfer(ModuleName robot, Hand blade, int targetSlot, EnumTransferType transferType, out string reason)
  1142. {
  1143. CheckToPostMessage((int)MSG.PrepareTransfer, transferType.ToString());
  1144. reason = string.Empty;
  1145. return true;
  1146. }
  1147. public override bool TransferHandoff(ModuleName robot, Hand blade, int targetSlot, EnumTransferType transferType, out string reason)
  1148. {
  1149. reason = string.Empty;
  1150. return true;
  1151. }
  1152. public override bool PostTransfer(ModuleName robot, Hand blade, int targetSlot, EnumTransferType transferType, out string reason)
  1153. {
  1154. CheckToPostMessage((int)MSG.PostTransfer, transferType.ToString());
  1155. reason = string.Empty;
  1156. return true;
  1157. }
  1158. public override bool CheckReadyForTransfer(ModuleName robot, Hand blade, int targetSlot, EnumTransferType transferType, out string reason)
  1159. {
  1160. reason = string.Empty;
  1161. var boat = Singleton<EquipmentManager>.Instance.Modules[ModuleName.Boat] as BoatModule;
  1162. if (!boat.IsBoatElevatorAtHomePosition)
  1163. {
  1164. reason = "Boat z axis is not at home position";
  1165. return false;
  1166. }
  1167. if (!boat.IsBoatRotationAtHomePosition)
  1168. {
  1169. reason = "Boat r axis is not at home position";
  1170. return false;
  1171. }
  1172. return true;
  1173. }
  1174. public override void NoteTransferStart(ModuleName robot, Hand blade, int targetSlot, EnumTransferType transferType)
  1175. {
  1176. //if (FsmState == (int)STATE.InTransfer)
  1177. // CheckToPostMessage(MSG.Transfer)
  1178. }
  1179. public override void NoteTransferStop(ModuleName robot, Hand blade, int targetSlot, EnumTransferType transferType)
  1180. {
  1181. //if (FsmState == (int)STATE.InTransfer)
  1182. // CheckToPostMessage(MSG.Transfer)
  1183. }
  1184. public override bool Process(string recipeName, bool isCleanRecipe, bool withWafer, out string reason)
  1185. {
  1186. _recipeRunningInfo.RecipeName = recipeName;
  1187. _isPrepareProcess = false;
  1188. _isStandbyStep = false;
  1189. IsJobProcess = true;
  1190. IsExcuteIdleRecipe = false;
  1191. CheckToPostMessage((int)MSG.RunRecipe, recipeName);
  1192. reason = string.Empty;
  1193. return true;
  1194. }
  1195. public override bool Standby(string recipeName, out string reason)
  1196. {
  1197. reason = string.Empty;
  1198. _recipeRunningInfo.RecipeName = recipeName;
  1199. _recipeRunningInfo.MainRecipeName = recipeName;
  1200. if (!RecipeParser.Parse(_recipeRunningInfo.RecipeName, ModuleName.PM1.ToString(), out var recipeHead, out var recipeSteps, out reason, "Process"))
  1201. {
  1202. reason = $"Load process recipe {_recipeRunningInfo.RecipeName} failed, {reason}";
  1203. return false;
  1204. }
  1205. if (recipeSteps == null || recipeSteps.Count == 0)
  1206. {
  1207. reason = $"Process recipe {_recipeRunningInfo.RecipeName} is empty";
  1208. return false;
  1209. }
  1210. _isStandbyStep = true;
  1211. var standbyStep = recipeSteps.Where(x => x.StepName == "Standby").FirstOrDefault();
  1212. if (standbyStep != null)
  1213. {
  1214. StringProcessFlowState = ProcessFlowState.Standby.ToString();
  1215. _recipeRunningInfo.StepName = "Standby";
  1216. EV.PostInfoLog(Module, $"pj job excute recipe {recipeName} standby step");
  1217. foreach (var recipeCmd in standbyStep.RecipeCommands.Keys)
  1218. {
  1219. if (!OP.CanDoOperation($"{Module}.{recipeCmd}", out reason, standbyStep.RecipeCommands[recipeCmd]))
  1220. {
  1221. if (!OP.CanDoOperation($"{ModuleName.PM1}.{recipeCmd}", out reason, standbyStep.RecipeCommands[recipeCmd]))
  1222. {
  1223. if (!OP.CanDoOperation($"{ModuleName.System}.{recipeCmd}", out reason, standbyStep.RecipeCommands[recipeCmd]))
  1224. {
  1225. reason = $"Can not execute {recipeCmd}, {reason}";
  1226. return false;
  1227. }
  1228. else
  1229. {
  1230. OP.DoOperation($"{ModuleName.System}.{recipeCmd}", out string reason1, 0, standbyStep.RecipeCommands[recipeCmd]);
  1231. }
  1232. }
  1233. else
  1234. {
  1235. OP.DoOperation($"{ModuleName.PM1}.{recipeCmd}", out string reason1, 0, standbyStep.RecipeCommands[recipeCmd]);
  1236. }
  1237. }
  1238. else
  1239. {
  1240. OP.DoOperation($"{Module}.{recipeCmd}", out string reason1, 0, standbyStep.RecipeCommands[recipeCmd]);
  1241. }
  1242. }
  1243. }
  1244. return true;
  1245. }
  1246. public void EndIdleRecipe()
  1247. {
  1248. CheckToPostMessage((int)MSG.EndIdleRecipe);
  1249. }
  1250. private double GetNewShowTime()
  1251. {
  1252. return GetWaitTime() + _recipeRunningInfo.HoldTime;
  1253. }
  1254. private double GetWaitTime()
  1255. {
  1256. if (StringFsmStatus == "Idle")
  1257. {
  1258. _waitTimer.Reset();
  1259. }
  1260. if (IsWait)
  1261. {
  1262. _waitTimer.Start();
  1263. }
  1264. else
  1265. {
  1266. _waitTimer.Stop();
  1267. }
  1268. return _waitTimer.ElapsedMilliseconds / 1000;
  1269. }
  1270. }
  1271. #endregion
  1272. }