FIMSModule.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  1. using Aitex.Core.Common.DeviceData;
  2. using Aitex.Core.RT.DataCenter;
  3. using Aitex.Core.RT.Device;
  4. using Aitex.Core.RT.Device.Unit;
  5. using Aitex.Core.RT.Event;
  6. using Aitex.Core.RT.Fsm;
  7. using Aitex.Core.RT.Log;
  8. using Aitex.Core.RT.OperationCenter;
  9. using Aitex.Core.RT.Routine;
  10. using Aitex.Core.RT.SCCore;
  11. using Aitex.Core.Util;
  12. using Aitex.Core.Utilities;
  13. using Aitex.Sorter.Common;
  14. using FurnaceRT.Equipments.PMs;
  15. using FurnaceRT.Equipments.Systems;
  16. using MECF.Framework.Common.Alarms;
  17. using MECF.Framework.Common.Device.Bases;
  18. using MECF.Framework.Common.Equipment;
  19. using MECF.Framework.Common.Schedulers;
  20. using MECF.Framework.Common.SubstrateTrackings;
  21. using System;
  22. using System.Collections.Generic;
  23. using System.Linq;
  24. using System.ServiceModel;
  25. using System.Text;
  26. using System.Threading.Tasks;
  27. namespace FurnaceRT.Equipments.FIMSs
  28. {
  29. public partial class FIMSModule : FIMSModuleBase
  30. {
  31. public enum STATE
  32. {
  33. NotInstall,
  34. NotConnected,
  35. Idle,
  36. Error,
  37. Init,
  38. Homing,
  39. Unloading,
  40. Loading,
  41. Cycle,
  42. InTransfer,
  43. }
  44. public enum MSG
  45. {
  46. Home,
  47. Disconnected,
  48. Connected,
  49. Reset,
  50. Abort,
  51. Error,
  52. InTransfer,
  53. Cycle,
  54. TransferComplete,
  55. Load,
  56. Unload,
  57. LoadRetry,
  58. UnloadRetry,
  59. }
  60. public override bool IsReady
  61. {
  62. get { return FsmState == (int)STATE.Idle && CheckAllMessageProcessed(); }
  63. }
  64. public override bool IsError
  65. {
  66. get
  67. {
  68. return FsmState == (int)STATE.Error;
  69. }
  70. }
  71. public override bool IsInit
  72. {
  73. get { return false; }
  74. }
  75. public bool IsFoupExist => FIMSDevice != null ? FIMSDevice.IsFoupExist : false;
  76. public bool IsLoading
  77. {
  78. get
  79. {
  80. return FsmState == (int)STATE.Loading;
  81. }
  82. }
  83. private bool _isOnline;
  84. public override bool IsOnline
  85. {
  86. get
  87. {
  88. return _isOnline;
  89. }
  90. set
  91. {
  92. _isOnline = value;
  93. SC.SetItemValue($"FIMS.{Name}.IsOnline", value);
  94. }
  95. }
  96. #region fields
  97. private FIMSHomeRoutine _homeRoutine;
  98. private FIMSLoadRoutine _loadRoutine;
  99. private FIMSUnloadRoutine _unloadRoutine;
  100. private FIMSCycleTest _moveCycleTest;
  101. private List<AITWaterMappingData> _mappingData;
  102. #endregion
  103. public FIMSModule(ModuleName module) : base(SC.GetValue<int>("System.CassetteSlotCount"))
  104. {
  105. Name = module.ToString();
  106. Module = module.ToString();
  107. IsOnline = SC.GetValue<bool>($"FIMS.{Name}.IsOnline");
  108. }
  109. public override bool Initialize()
  110. {
  111. InitRoutine();
  112. InitDevice();
  113. InitFsm();
  114. InitOp();
  115. InitData();
  116. InitAlarmEvent();
  117. Singleton<EventManager>.Instance.OnAlarmEvent += Instance_OnAlarmEvent;
  118. return base.Initialize();
  119. }
  120. private void Instance_OnAlarmEvent(EventItem item)
  121. {
  122. if (item != null && item.Level == EventLevel.Alarm && (item.Source == Name || item.Source == Module))
  123. {
  124. DEVICE.GetDevice<SignalTowerBase>("System.SignalTower")?.Reset();
  125. LOG.Write($"{item.Source} {item.EventEnum} {item.Description}\n");
  126. PostMsg(MSG.Error);
  127. }
  128. }
  129. private void InitRoutine()
  130. {
  131. _homeRoutine = new FIMSHomeRoutine(this);
  132. _loadRoutine = new FIMSLoadRoutine(this);
  133. _unloadRoutine = new FIMSUnloadRoutine(this);
  134. _moveCycleTest = new FIMSCycleTest(this);
  135. }
  136. private void InitData()
  137. {
  138. DATA.Subscribe($"{Module}.MappingData", () => new List<AITWaterMappingData>()
  139. {
  140. new AITWaterMappingData(){Slot = 1,Detect=2500, Base=2500,Diff = 0,Thickness = 10},
  141. new AITWaterMappingData(){Slot = 2,Detect=2500, Base=2500,Diff = 0,Thickness = 10},
  142. new AITWaterMappingData(){Slot = 3,Detect=2500, Base=2500,Diff = 0,Thickness = 10},
  143. new AITWaterMappingData(){Slot = 4,Detect=2500, Base=2500,Diff = 0,Thickness = 10},
  144. new AITWaterMappingData(){Slot = 5,Detect=2500, Base=2500,Diff = 0,Thickness = 10},
  145. new AITWaterMappingData(){Slot = 6,Detect=2500, Base=2500,Diff = 0,Thickness = 10},
  146. new AITWaterMappingData(){Slot = 7,Detect=2500, Base=2500,Diff = 0,Thickness = 10},
  147. new AITWaterMappingData(){Slot = 8,Detect=2500, Base=2500,Diff = 0,Thickness = 10},
  148. new AITWaterMappingData(){Slot = 9,Detect=2500, Base=2500,Diff = 0,Thickness = 10},
  149. new AITWaterMappingData(){Slot = 10,Detect=2500, Base=2500,Diff = 0,Thickness = 10},
  150. new AITWaterMappingData(){Slot = 11,Detect=2500, Base=2500,Diff = 0,Thickness = 10},
  151. new AITWaterMappingData(){Slot = 12,Detect=2500, Base=2500,Diff = 0,Thickness = 10},
  152. new AITWaterMappingData(){Slot = 13,Detect=2500, Base=2500,Diff = 0,Thickness = 10},
  153. new AITWaterMappingData(){Slot = 14,Detect=2500, Base=2500,Diff = 0,Thickness = 10},
  154. new AITWaterMappingData(){Slot = 15,Detect=2500, Base=2500,Diff = 0,Thickness = 10},
  155. new AITWaterMappingData(){Slot = 16,Detect=2500, Base=2500,Diff = 0,Thickness = 10},
  156. new AITWaterMappingData(){Slot = 17,Detect=2500, Base=2500,Diff = 0,Thickness = 10},
  157. new AITWaterMappingData(){Slot = 18,Detect=2500, Base=2500,Diff = 0,Thickness = 10},
  158. new AITWaterMappingData(){Slot = 19,Detect=2500, Base=2500,Diff = 0,Thickness = 10},
  159. new AITWaterMappingData(){Slot = 20,Detect=2500, Base=2500,Diff = 0,Thickness = 10},
  160. new AITWaterMappingData(){Slot = 21,Detect=2500, Base=2500,Diff = 0,Thickness = 10},
  161. new AITWaterMappingData(){Slot = 22,Detect=2500, Base=2500,Diff = 0,Thickness = 10},
  162. new AITWaterMappingData(){Slot = 23,Detect=2500, Base=2500,Diff = 0,Thickness = 10},
  163. new AITWaterMappingData(){Slot = 24,Detect=2500, Base=2500,Diff = 0,Thickness = 10},
  164. new AITWaterMappingData(){Slot = 25,Detect=2500, Base=2500,Diff = 0,Thickness = 10},
  165. });
  166. DATA.Subscribe($"{Module}.SlotNo1Distance", () => 100.0f);
  167. DATA.Subscribe($"{Module}.SlotPitchDistance", () => 100f);
  168. DATA.Subscribe($"{Module}.ThicknessReferenceValue", () => 5f);
  169. DATA.Subscribe($"{Module}.ThicknessPermissions", () => 8f);
  170. DATA.Subscribe($"{Module}.MappingResult", () => "Normal Complete");
  171. DATA.Subscribe($"{Module}.Status", () => StringFsmStatus);
  172. DATA.Subscribe($"{Module}.IsOnline", () => IsOnline);
  173. DATA.Subscribe($"{Module}.IsError", () => IsError);
  174. DATA.Subscribe($"{Module}.FIMSCycledCount", () => _moveCycleTest.LoopCounter);
  175. //DATA.Subscribe(Module, "CassettePresent", () => _diStationCassettePresent.Value);
  176. //DATA.Subscribe($"{Module}.StageValveState", () => StageValveState.ToString());
  177. }
  178. private void InitOp()
  179. {
  180. OP.Subscribe($"{Module}.Abort", (string cmd, object[] args) => CheckToPostMessage((int)MSG.Abort));
  181. OP.Subscribe($"{Module}.Home", (string cmd, object[] args) => CheckToPostMessage((int)MSG.Home));
  182. OP.Subscribe($"{Module}.Load", (string cmd, object[] args) => CheckToPostMessage((int)MSG.Load, args));
  183. OP.Subscribe($"{Module}.Unload", (string cmd, object[] args) => CheckToPostMessage((int)MSG.Unload, args));
  184. OP.Subscribe($"{Module}.Reset", (string cmd, object[] args) => CheckToPostMessage((int)MSG.Reset));
  185. OP.Subscribe($"{Module}.Cycle", (string cmd, object[] args) => CheckToPostMessage((int)MSG.Cycle));
  186. OP.Subscribe($"{Module}.SetOnline", (string cmd, object[] args) =>
  187. {
  188. IsOnline = true;
  189. return true;
  190. });
  191. OP.Subscribe($"{Module}.SetOffline", (string cmd, object[] args) =>
  192. {
  193. IsOnline = false;
  194. return true;
  195. });
  196. OP.Subscribe($"{Module}.AlarmAction", (string cmd, object[] args) =>
  197. {
  198. Enum.TryParse(args[0].ToString(), out AlarmAction alarmAction);
  199. string eventName = null;
  200. if (args.Length > 1)
  201. eventName = args[1].ToString();
  202. if (eventName != null)
  203. {
  204. EV.ClearAlarmEvent(eventName);
  205. var item = _triggeredAlarmList.FirstOrDefault(x => x.EventEnum == eventName);
  206. if (item != null)
  207. {
  208. item.Reset();
  209. _triggeredAlarmList.Remove(item);
  210. }
  211. if (item != null)
  212. {
  213. switch (alarmAction)
  214. {
  215. case AlarmAction.Retry:
  216. {
  217. CheckToPostMessage((int)item.RetryMessage, item.RetryMessageParas);
  218. }
  219. break;
  220. case AlarmAction.Abort:
  221. {
  222. CheckToPostMessage((int)MSG.Abort);
  223. }
  224. break;
  225. case AlarmAction.Clear:
  226. {
  227. int alarmCount = 0;
  228. var alarms = EV.GetAlarmEvent();
  229. foreach (var alarm in alarms)
  230. {
  231. if (alarm.Level == EventLevel.Alarm && alarm.Source == Name)
  232. alarmCount++;
  233. }
  234. if (alarmCount == 0)
  235. CheckToPostMessage((int)MSG.Reset);
  236. }
  237. break;
  238. case AlarmAction.Continue:
  239. {
  240. int alarmCount = 0;
  241. var alarms = EV.GetAlarmEvent();
  242. foreach (var alarm in alarms)
  243. {
  244. if (alarm.Level == EventLevel.Alarm && alarm.Source == Name)
  245. alarmCount++;
  246. }
  247. if (alarmCount == 0)
  248. CheckToPostMessage((int)MSG.Reset);
  249. }
  250. break;
  251. }
  252. }
  253. }
  254. return true;
  255. });
  256. }
  257. private void InitFsm()
  258. {
  259. EnumLoop<STATE>.ForEach((item) =>
  260. {
  261. MapState((int)item, item.ToString());
  262. });
  263. EnumLoop<MSG>.ForEach((item) =>
  264. {
  265. MapMessage((int)item, item.ToString());
  266. });
  267. EnableFsm(100, STATE.Init);
  268. Transition(STATE.Init, MSG.Home, FsmStartHome, STATE.Homing);
  269. Transition(STATE.Error, MSG.Home, FsmStartHome, STATE.Homing);
  270. Transition(STATE.Idle, MSG.Home, FsmStartHome, STATE.Homing);
  271. Transition(STATE.Homing, FSM_MSG.TIMER, FsmMonitorHomeTask, STATE.Idle);
  272. Transition(STATE.Homing, MSG.Error, null, STATE.Init);
  273. Transition(STATE.Homing, MSG.Abort, FsmAbortTask, STATE.Init);
  274. Transition(STATE.Idle, MSG.Disconnected, null, STATE.NotConnected);
  275. Transition(STATE.Idle, MSG.InTransfer, null, STATE.InTransfer);
  276. Transition(STATE.InTransfer, MSG.TransferComplete, null, STATE.Idle);
  277. Transition(STATE.InTransfer, MSG.Abort, null, STATE.Idle);
  278. Transition(STATE.NotConnected, MSG.Connected, null, STATE.Idle);
  279. //Error
  280. AnyStateTransition(MSG.Error, FsmOnError, STATE.Error);
  281. Transition(STATE.Error, MSG.Reset, FsmReset, STATE.Idle);
  282. Transition(STATE.Init, MSG.Reset, FsmReset, STATE.Init);
  283. Transition(STATE.Idle, MSG.Reset, FsmReset, STATE.Idle);
  284. //load
  285. Transition(STATE.Error, MSG.LoadRetry, FsmStartLoad, STATE.Loading);
  286. Transition(STATE.Idle, MSG.Load, FsmStartLoad, STATE.Loading);
  287. Transition(STATE.Loading, FSM_MSG.TIMER, FsmMonitorLoadTask, STATE.Idle);
  288. Transition(STATE.Loading, MSG.Abort, FsmAbortTask, STATE.Idle);
  289. //unload
  290. Transition(STATE.Error, MSG.UnloadRetry, FsmStartUnload, STATE.Unloading);
  291. Transition(STATE.Idle, MSG.Unload, FsmStartUnload, STATE.Unloading);
  292. Transition(STATE.Unloading, FSM_MSG.TIMER, FsmMonitorUnloadTask, STATE.Idle);
  293. Transition(STATE.Unloading, MSG.Abort, FsmAbortTask, STATE.Idle);
  294. Transition(STATE.Idle, MSG.Cycle, FsmStartMoveTest, STATE.Cycle);
  295. Transition(STATE.Cycle, FSM_MSG.TIMER, FsmMonitorTask, STATE.Idle);
  296. Transition(STATE.Cycle, MSG.Abort, FsmAbortTask, STATE.Idle);
  297. }
  298. #region Service Functions
  299. private bool FsmStartHome(object[] param)
  300. {
  301. Result ret = StartRoutine(_homeRoutine);
  302. if (ret == Result.FAIL || ret == Result.DONE)
  303. return false;
  304. return ret == Result.RUN;
  305. }
  306. private bool FsmAbortTask(object[] param)
  307. {
  308. (Singleton<EquipmentManager>.Instance.Modules[ModuleName.PM1] as PMModule)?.SetN2PurgeProcess(false);
  309. return true;
  310. }
  311. private bool FsmMonitorHomeTask(object[] param)
  312. {
  313. Result ret = MonitorRoutine();
  314. if (ret == Result.FAIL)
  315. {
  316. PostMsg(MSG.Error);
  317. return false;
  318. }
  319. if (ret == Result.DONE)
  320. {
  321. return true;
  322. }
  323. return false;
  324. }
  325. private bool FsmStartMoveTest(object[] param)
  326. {
  327. Result ret = StartRoutine(_moveCycleTest);
  328. if (ret == Result.FAIL || ret == Result.DONE)
  329. return false;
  330. return ret == Result.RUN;
  331. }
  332. private bool FsmStartLoad(object[] param)
  333. {
  334. bool isNeedN2Purge = false;
  335. string transferMode = "";
  336. if (param.Length > 0)
  337. {
  338. bool.TryParse(param[0].ToString(), out isNeedN2Purge);
  339. }
  340. if (param.Length > 1)
  341. {
  342. transferMode = param[1].ToString();
  343. }
  344. _loadRoutine.Init(isNeedN2Purge, transferMode);
  345. QueueRoutine.Clear();
  346. QueueRoutine.Enqueue(_loadRoutine);
  347. Result ret = QueueRoutine.Peek().Start();
  348. if (ret == Result.FAIL || ret == Result.DONE)
  349. return false;
  350. return ret == Result.RUN;
  351. }
  352. private bool FsmStartUnload(object[] param)
  353. {
  354. bool isNeedN2Purge = false;
  355. string transferMode = "";
  356. if (param.Length > 0)
  357. {
  358. bool.TryParse(param[0].ToString(), out isNeedN2Purge);
  359. }
  360. if (param.Length > 1)
  361. {
  362. transferMode = param[1].ToString();
  363. }
  364. _unloadRoutine.Init(isNeedN2Purge, transferMode);
  365. QueueRoutine.Clear();
  366. Result ret = StartRoutine(_unloadRoutine);
  367. if (ret == Result.FAIL || ret == Result.DONE)
  368. return false;
  369. return ret == Result.RUN;
  370. }
  371. private bool FsmMonitorLoadTask(object[] param)
  372. {
  373. Result ret = MonitorRoutine();
  374. if (ret == Result.FAIL)
  375. {
  376. PostMsg(MSG.Error);
  377. return false;
  378. }
  379. if (ret == Result.DONE)
  380. IsOnline = true;
  381. return ret == Result.DONE;
  382. }
  383. private bool FsmMonitorTask(object[] param)
  384. {
  385. Result ret = MonitorRoutine();
  386. if (ret == Result.FAIL)
  387. {
  388. PostMsg(MSG.Error);
  389. return false;
  390. }
  391. return ret == Result.DONE;
  392. }
  393. private bool FsmMonitorUnloadTask(object[] param)
  394. {
  395. Result ret = MonitorRoutine();
  396. if (ret == Result.FAIL)
  397. {
  398. PostMsg(MSG.Error);
  399. return false;
  400. }
  401. return ret == Result.DONE;
  402. }
  403. public override bool Home(out string reason)
  404. {
  405. CheckToPostMessage((int)MSG.Home);
  406. reason = string.Empty;
  407. return true;
  408. }
  409. private bool FsmOnError(object[] param)
  410. {
  411. if (FsmState == (int)STATE.Error)
  412. {
  413. return false;
  414. }
  415. if (FsmState != (int)STATE.Init && FsmState != (int)STATE.Idle)
  416. AbortRoutine();
  417. return true;
  418. }
  419. public override void Reset()
  420. {
  421. if (IsError)
  422. {
  423. CheckToPostMessage((int)MSG.Reset);
  424. }
  425. }
  426. private bool FsmReset(object[] param)
  427. {
  428. FIMSDevice.SetAlarmReset();
  429. return true;
  430. }
  431. public override bool PrepareTransfer(ModuleName robot, Hand blade, int targetSlot, EnumTransferType transferType, out string reason)
  432. {
  433. reason = string.Empty;
  434. return true;
  435. }
  436. public override bool TransferHandoff(ModuleName robot, Hand blade, int targetSlot, EnumTransferType transferType, out string reason)
  437. {
  438. reason = string.Empty;
  439. return true;
  440. }
  441. public override bool PostTransfer(ModuleName robot, Hand blade, int targetSlot, EnumTransferType transferType, out string reason)
  442. {
  443. reason = string.Empty;
  444. return true;
  445. }
  446. public override bool CheckReadyForTransfer(ModuleName robot, Hand blade, int targetSlot, EnumTransferType transferType,
  447. out string reason)
  448. {
  449. reason = string.Empty;
  450. if (!IsReady)
  451. {
  452. reason = $"{Module} status={StringFsmStatus} is busy";
  453. return false;
  454. }
  455. if (robot == ModuleName.WaferRobot)
  456. {
  457. if (!FIMSDevice.IsLoadCompleted)
  458. {
  459. reason = $"{Module} is not loaded";
  460. return false;
  461. }
  462. if (!IsDoorOpen)
  463. {
  464. reason = $"{Module} door is not open";
  465. }
  466. }
  467. if (robot == ModuleName.CarrierRobot)
  468. {
  469. if (!FIMSDevice.IsUnloadCompleted)
  470. {
  471. reason = $"{Module} is not unloaded";
  472. return false;
  473. }
  474. if (transferType == EnumTransferType.Pick)
  475. {
  476. if (!CarrierManager.Instance.CheckHasCarrier(Module, 0))
  477. {
  478. reason = $"{Module} carrier not present";
  479. return false;
  480. }
  481. }
  482. if (transferType == EnumTransferType.Place)
  483. {
  484. if (!CarrierManager.Instance.CheckNoCarrier(Module, 0))
  485. {
  486. reason = $"{Module} carrier present";
  487. return false;
  488. }
  489. }
  490. }
  491. return true;
  492. }
  493. public override void NoteTransferStart(ModuleName robot, Hand blade, int targetSlot, EnumTransferType transferType)
  494. {
  495. CheckToPostMessage(MSG.InTransfer);
  496. }
  497. public override void NoteTransferStop(ModuleName robot, Hand blade, int targetSlot, EnumTransferType transferType)
  498. {
  499. if (FsmState == (int)STATE.InTransfer)
  500. CheckToPostMessage(MSG.TransferComplete);
  501. }
  502. public void InvokeLoad(bool isNeedN2Purge, string transferMode)
  503. {
  504. CheckToPostMessage((int)MSG.Load, isNeedN2Purge, transferMode);
  505. }
  506. public void InvokeUnload(bool isNeedN2Purge,string transferMode)
  507. {
  508. CheckToPostMessage((int)MSG.Unload, isNeedN2Purge, transferMode);
  509. }
  510. #endregion
  511. }
  512. }