VceEntity.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  1. using Aitex.Core.RT.DataCenter;
  2. using Aitex.Core.RT.Device;
  3. using Aitex.Core.RT.Fsm;
  4. using Aitex.Core.RT.Log;
  5. using Aitex.Core.RT.OperationCenter;
  6. using Aitex.Core.Utilities;
  7. using MECF.Framework.Common.Equipment;
  8. using MECF.Framework.Common.Schedulers;
  9. using MECF.Framework.Common.SubstrateTrackings;
  10. using MECF.Framework.RT.ModuleLibrary.VceModules;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Linq;
  14. using System.Reflection;
  15. using System.Text;
  16. using System.Threading.Tasks;
  17. using System.Windows;
  18. using Venus_Core;
  19. using Venus_RT.Devices;
  20. using Venus_RT.Devices.SMIF;
  21. using Venus_RT.Devices.VCE;
  22. using Venus_RT.Modules.PMs;
  23. using Venus_RT.Modules.TM;
  24. using Venus_RT.Modules.TM.VenusEntity;
  25. namespace Venus_RT.Modules.VCE
  26. {
  27. #region 状态和消息
  28. public enum VceMSG
  29. {
  30. Home,
  31. Error,
  32. DoorOpen,
  33. DoorClose,
  34. Map,
  35. ReadMap,
  36. Load,
  37. UnLoad,
  38. LoadPrepare,
  39. LoadWithSMIF,
  40. UnLoadWithSMIF,
  41. Reset,
  42. Goto,
  43. GotoLP,
  44. SafeLoad,
  45. SafeUnload,
  46. Pump,
  47. Vent,
  48. Abort,
  49. None
  50. }
  51. #endregion
  52. public class VceEntity : Entity, IEntity, IModuleEntity
  53. {
  54. private ModuleName _modulename;
  55. private readonly VceModuleBase _vce;
  56. private readonly ISMIF _smif;
  57. private bool _CassetteArrive;
  58. public bool IsIdle => fsm.State == (int)VceSTATE.Idle;
  59. public bool IsInit => fsm.State == (int)VceSTATE.Init || fsm.State == (int)VceSTATE.Unknown;
  60. public bool IsBusy => !IsInit && !IsError && !IsIdle;
  61. public bool IsError => fsm.State == (int)VceSTATE.Error;
  62. public bool VCEOutDoorClosed => !_vce.OutDoorIsOpen;
  63. public bool CassetteArrive => _CassetteArrive;
  64. public int CurrentSlot => currentSlot;
  65. private int currentSlot;
  66. private int targetSlot;
  67. private LoadRoutine _loadRoutine;
  68. private LoadPrepareRoutine _prepareRoutine;
  69. private UnloadRoutine _unloadRoutine;
  70. private LoadWithSMIFRoutine _loadwithSMIFRoutine;
  71. private UnloadWithSMIFRoutine _unloadwithSMIFRoutine;
  72. private readonly SEMFPumpRoutine _pumpRoutine;
  73. private readonly SEMFVentRoutine _ventRoutine;
  74. public VceEntity(ModuleName moduleName)
  75. {
  76. currentSlot = 0;
  77. _modulename = moduleName;
  78. _vce = new HongHuVce(25, _modulename);
  79. _smif = new FortrendPLUS500(_modulename);
  80. _loadRoutine = new LoadRoutine(_modulename, _vce);
  81. _prepareRoutine = new LoadPrepareRoutine(_modulename, _vce);
  82. _unloadRoutine = new UnloadRoutine(_modulename, _vce);
  83. _loadwithSMIFRoutine = new LoadWithSMIFRoutine(_modulename, _vce, _smif);
  84. _unloadwithSMIFRoutine = new UnloadWithSMIFRoutine(_modulename, _vce, _smif);
  85. _pumpRoutine = new SEMFPumpRoutine(DEVICE.GetDevice<HongHuTM>("SETM"), _modulename);
  86. _ventRoutine = new SEMFVentRoutine(DEVICE.GetDevice<HongHuTM>("SETM"), _modulename);
  87. InitFsmMap();
  88. }
  89. protected override bool Init()
  90. {
  91. DATA.Subscribe($"{_modulename}.VCEOutDoorClosed", () => !VCEOutDoorClosed);
  92. DATA.Subscribe($"{_modulename}.CurrentSlot", () => currentSlot);
  93. DATA.Subscribe($"{_modulename}.FsmState", () => ((VceSTATE)fsm.State).ToString());
  94. DATA.Subscribe($"{_modulename}.CassetteArrive", () => CassetteArrive);
  95. //DATA.Subscribe($"{_modulename}.IsRunning", () => IsIdle);
  96. OP.Subscribe($"{_modulename}.HOME", (cmd, args) => { PostMsg(VceMSG.Home); return true; });
  97. OP.Subscribe($"{_modulename}.DoorOpen", (cmd, args) => { PostMsg(VceMSG.DoorOpen); return true; });
  98. OP.Subscribe($"{_modulename}.DoorClose", (cmd, args) => { PostMsg(VceMSG.DoorClose); return true; });
  99. OP.Subscribe($"{_modulename}.Map", (cmd, args) => { PostMsg(VceMSG.Map); return true; });
  100. OP.Subscribe($"{_modulename}.ReadMap", (cmd, args) => { PostMsg(VceMSG.ReadMap); return true; });
  101. OP.Subscribe($"{_modulename}.Load", (cmd, args) => { PostMsg(VceMSG.Load); return true; });
  102. OP.Subscribe($"{_modulename}.UnLoad", (cmd, args) => { PostMsg(VceMSG.UnLoad); return true; });
  103. OP.Subscribe($"{_modulename}.Reset", (cmd, args) => { PostMsg(VceMSG.Reset); return true; });
  104. OP.Subscribe($"{_modulename}.Goto", (cmd, args) => { PostMsg(VceMSG.Goto, args[0]); return true; });
  105. OP.Subscribe($"{_modulename}.GotoLP", (cmd, args) => { PostMsg(VceMSG.GotoLP); return true; });
  106. OP.Subscribe($"{_modulename}.Abort", (cmd, args) => { PostMsg(VceMSG.Abort); return true; });
  107. OP.Subscribe($"{_modulename}.PumpDown", (cmd, args) => { PostMsg(VceMSG.Pump); return true; });
  108. OP.Subscribe($"{_modulename}.Vent", (cmd, args) => { PostMsg(VceMSG.Vent); return true; });
  109. OP.Subscribe($"{_modulename}.LoadPrepare", (cmd, args) => { PostMsg(VceMSG.LoadPrepare); return true; });
  110. OP.Subscribe($"{_modulename}.SafeLoad", (cmd, args) => { PostMsg(VceMSG.SafeLoad); return true; });
  111. OP.Subscribe($"{_modulename}.SafeUnload", (cmd, args) => { PostMsg(VceMSG.SafeUnload); return true; });
  112. OP.Subscribe($"{_modulename}.LoadWithSMIF", (cmd, args) => { PostMsg(VceMSG.LoadWithSMIF); return true; });
  113. OP.Subscribe($"{_modulename}.UnLoadWithSMIF", (cmd, args) => { PostMsg(VceMSG.UnLoadWithSMIF); return true; });
  114. return true;
  115. }
  116. /// <summary>
  117. /// 定义状态机的迁移表
  118. /// </summary>
  119. private void InitFsmMap()
  120. {
  121. fsm = new StateMachine<VceEntity>(_modulename.ToString(), (int)VceSTATE.Init, 50);
  122. fsm.EnableRepeatedMsg(true);
  123. AnyStateTransition(VceMSG.Error, fnError, VceSTATE.Error);
  124. AnyStateTransition(VceMSG.Abort, fnAbort, VceSTATE.Idle);
  125. AnyStateTransition(VceMSG.Home, fnStartHome, VceSTATE.Homing);
  126. //HOME init->homing idle->homing
  127. Transition(VceSTATE.Init, VceMSG.Home, fnStartHome, VceSTATE.Homing);
  128. Transition(VceSTATE.Idle, VceMSG.Home, fnStartHome, VceSTATE.Homing);
  129. Transition(VceSTATE.Error, VceMSG.Home, fnStartHome, VceSTATE.Homing);
  130. Transition(VceSTATE.Homing, FSM_MSG.TIMER, fnHomeTimeout, VceSTATE.Idle);
  131. //Open Door 开门
  132. Transition(VceSTATE.Idle, VceMSG.DoorOpen, fnStartOpenDoor, VceSTATE.DoorOpenning);
  133. Transition(VceSTATE.DoorOpenning, FSM_MSG.TIMER, fnOpenDoorTimeout, VceSTATE.Idle);
  134. //Close Door 关门
  135. Transition(VceSTATE.Idle, VceMSG.DoorClose, fnStartCloseDoor, VceSTATE.DoorClosing);
  136. Transition(VceSTATE.DoorClosing, FSM_MSG.TIMER, fnCloseDoorTimeout, VceSTATE.Idle);
  137. //Map 扫片
  138. Transition(VceSTATE.Idle, VceMSG.Map, fnStartMapping, VceSTATE.Mapping);
  139. Transition(VceSTATE.Mapping, FSM_MSG.TIMER, fnMappingTimeout, VceSTATE.Idle);
  140. //Load 取cassette
  141. Transition(VceSTATE.Idle, VceMSG.Load, fnStartLoading, VceSTATE.Loading);
  142. Transition(VceSTATE.Loading, FSM_MSG.TIMER, fnLoadingTimeout, VceSTATE.Idle);
  143. //UnLoad 放cassette
  144. Transition(VceSTATE.Idle, VceMSG.UnLoad, fnStartUnLoading, VceSTATE.UnLoading);
  145. Transition(VceSTATE.UnLoading, FSM_MSG.TIMER, fnUnLoadingTimeout, VceSTATE.Idle);
  146. //Goto 指定槽对准窗口
  147. Transition(VceSTATE.Idle, VceMSG.Goto, fnStartGoto, VceSTATE.Goting);
  148. Transition(VceSTATE.Goting, FSM_MSG.TIMER, fnGotingTimeout, VceSTATE.Idle);
  149. //ReadMap
  150. Transition(VceSTATE.Idle, VceMSG.ReadMap, fnStartReadingMap, VceSTATE.ReadingMap);
  151. Transition(VceSTATE.ReadingMap, FSM_MSG.TIMER, fnReadingMapTimeout, VceSTATE.Idle);
  152. //Load Prepare
  153. Transition(VceSTATE.Idle, VceMSG.LoadPrepare, fnStartLoadPrepare, VceSTATE.LoadPreparing);
  154. Transition(VceSTATE.LoadPreparing, FSM_MSG.TIMER, fnLoadingPrepareTimeout,VceSTATE.Idle);
  155. //Safe Load
  156. Transition(VceSTATE.Idle, VceMSG.SafeLoad, fnStartSafeLoad, VceSTATE.SafeLoading);
  157. Transition(VceSTATE.SafeLoading, FSM_MSG.TIMER, fnSafeLoadTimeout, VceSTATE.Idle);
  158. //LoadWithSMIF => LoadPrepare & SMIF Load & Load
  159. Transition(VceSTATE.Idle, VceMSG.LoadWithSMIF, fnStartLoadWithSMIF, VceSTATE.LoadingWithSMIF);
  160. Transition(VceSTATE.LoadingWithSMIF, FSM_MSG.TIMER, fnLoadWithSMIFTimeout, VceSTATE.Idle);
  161. //Safe UnLoad
  162. Transition(VceSTATE.Idle, VceMSG.SafeUnload, fnStartSafeUnLoad, VceSTATE.SafeUnloading);
  163. Transition(VceSTATE.SafeUnloading, FSM_MSG.TIMER, fnSafeUnLoadTimeout, VceSTATE.Idle);
  164. //UnLoad With SMIF => UnLoad with smif
  165. Transition(VceSTATE.Idle, VceMSG.UnLoadWithSMIF, fnStartUnLoadWithSMIF, VceSTATE.UnLoadingWithSMIF);
  166. Transition(VceSTATE.UnLoadingWithSMIF, FSM_MSG.TIMER, fnUnLoadWithSMIFTimeout,VceSTATE.Idle);
  167. //Goto LP
  168. Transition(VceSTATE.Idle, VceMSG.GotoLP, fnStartGotoLP, VceSTATE.GotingLP);
  169. Transition(VceSTATE.GotingLP, FSM_MSG.TIMER, fnGotoLPTimeout, VceSTATE.Idle);
  170. //Pump
  171. Transition(VceSTATE.Idle, VceMSG.Pump, fnStartPump, VceSTATE.Pumping);
  172. Transition(VceSTATE.Pumping, FSM_MSG.TIMER, fnPumpTimeout, VceSTATE.Idle);
  173. Transition(VceSTATE.Pumping, VceMSG.Abort, fnAbortPump, VceSTATE.Idle);
  174. //Vent
  175. Transition(VceSTATE.Idle, VceMSG.Vent, fnStartVent, VceSTATE.Venting);
  176. Transition(VceSTATE.Venting, FSM_MSG.TIMER, fnVentTimeout, VceSTATE.Idle);
  177. Transition(VceSTATE.Venting, VceMSG.Abort, fnAbortVent, VceSTATE.Idle);
  178. EnumLoop<VceSTATE>.ForEach((item) => { fsm.MapState((int)item, item.ToString()); });
  179. EnumLoop<VceMSG>.ForEach((item) => { fsm.MapMessage((int)item, item.ToString()); });
  180. Running = true;
  181. }
  182. private bool fnAbortVent(object[] param)
  183. {
  184. _ventRoutine.Abort();
  185. return true;
  186. }
  187. private bool fnVentTimeout(object[] param)
  188. {
  189. RState ret = _ventRoutine.Monitor();
  190. if (ret == RState.Timeout || ret == RState.Failed)
  191. {
  192. PostMsg(VceMSG.Error);
  193. return false;
  194. }
  195. return ret == RState.End;
  196. }
  197. private bool fnStartVent(object[] param)
  198. {
  199. return _ventRoutine.Start(param) == RState.Running;
  200. }
  201. private bool fnAbortPump(object[] param)
  202. {
  203. _pumpRoutine.Abort();
  204. return true;
  205. }
  206. private bool fnPumpTimeout(object[] param)
  207. {
  208. RState ret = _pumpRoutine.Monitor();
  209. if (ret == RState.Timeout || ret == RState.Failed)
  210. {
  211. PostMsg(VceMSG.Error);
  212. return false;
  213. }
  214. return ret == RState.End;
  215. }
  216. private bool fnStartPump(object[] param)
  217. {
  218. return _pumpRoutine.Start(param) == RState.Running;
  219. }
  220. private bool fnGotoLPTimeout(object[] param)
  221. {
  222. if (_vce.Status == RState.Timeout || _vce.Status == RState.Failed)
  223. {
  224. PostMsg(VceMSG.Error);
  225. return false;
  226. }
  227. if (_vce.Status == RState.End)
  228. {
  229. currentSlot = targetSlot;
  230. }
  231. return _vce.Status == RState.End;
  232. }
  233. private bool fnStartGotoLP(object[] param)
  234. {
  235. if (_vce.GotoLP())
  236. {
  237. targetSlot = -1;
  238. return true;
  239. }
  240. else
  241. return false;
  242. }
  243. private bool fnSafeUnLoadTimeout(object[] param)
  244. {
  245. RState ret = _unloadRoutine.Monitor();
  246. if (ret == RState.Timeout || ret == RState.Failed)
  247. {
  248. PostMsg(VceMSG.Error);
  249. return false;
  250. }
  251. if (ret == RState.End)
  252. {
  253. _CassetteArrive = false;
  254. WaferManager.Instance.DeleteWafer(_modulename, 0, 25);
  255. }
  256. return ret == RState.End;
  257. }
  258. private bool fnStartSafeUnLoad(object[] param)
  259. {
  260. return _unloadRoutine.Start(param) == RState.Running;
  261. }
  262. private bool fnSafeLoadTimeout(object[] param)
  263. {
  264. RState ret = _loadRoutine.Monitor();
  265. if (ret == RState.Timeout || ret == RState.Failed)
  266. {
  267. PostMsg(VceMSG.Error);
  268. return false;
  269. }
  270. if (ret == RState.End)
  271. {
  272. _CassetteArrive = true;
  273. }
  274. return ret == RState.End;
  275. }
  276. private bool fnStartLoadWithSMIF(object[] param)
  277. {
  278. return _loadwithSMIFRoutine.Start(param) == RState.Running;
  279. }
  280. private bool fnLoadWithSMIFTimeout(object[] param)
  281. {
  282. RState ret = _loadwithSMIFRoutine.Monitor();
  283. if (ret == RState.Timeout || ret == RState.Failed)
  284. {
  285. PostMsg(VceMSG.Error);
  286. return false;
  287. }
  288. if (ret == RState.End)
  289. {
  290. _CassetteArrive = true;
  291. }
  292. return ret == RState.End;
  293. }
  294. private bool fnStartUnLoadWithSMIF(object[] param)
  295. {
  296. return _unloadwithSMIFRoutine.Start(param) == RState.Running;
  297. }
  298. private bool fnUnLoadWithSMIFTimeout(object[] param)
  299. {
  300. RState ret = _unloadwithSMIFRoutine.Monitor();
  301. if (ret == RState.Timeout || ret == RState.Failed)
  302. {
  303. PostMsg(VceMSG.Error);
  304. return false;
  305. }
  306. if (ret == RState.End)
  307. {
  308. _CassetteArrive = false;
  309. WaferManager.Instance.DeleteWafer(_modulename, 0, 25);
  310. }
  311. return ret == RState.End;
  312. }
  313. private bool fnStartSafeLoad(object[] param)
  314. {
  315. return _loadRoutine.Start(param) == RState.Running;
  316. }
  317. private bool fnLoadingPrepareTimeout(object[] param)
  318. {
  319. RState ret = _prepareRoutine.Monitor();
  320. if (ret == RState.Timeout || ret == RState.Failed)
  321. {
  322. PostMsg(VceMSG.Error);
  323. return false;
  324. }
  325. return ret == RState.End;
  326. }
  327. private bool fnStartLoadPrepare(object[] param)
  328. {
  329. return _prepareRoutine.Start(param) == RState.Running;
  330. }
  331. private bool fnReadingMapTimeout(object[] param)
  332. {
  333. if (_vce.Status == RState.Timeout || _vce.Status == RState.Failed)
  334. {
  335. PostMsg(VceMSG.Error);
  336. return false;
  337. }
  338. return _vce.Status == RState.End;
  339. }
  340. private bool fnStartReadingMap(object[] param)
  341. {
  342. return _vce.ReadMap();
  343. }
  344. //急停
  345. private bool fnAbort(object[] param)
  346. {
  347. return true;
  348. }
  349. //升降到槽位
  350. private bool fnStartGoto(object[] param)
  351. {
  352. if (_vce.Goto(Convert.ToInt32(param[0])))
  353. {
  354. targetSlot = Convert.ToInt32(param[0]);
  355. return true;
  356. }
  357. else
  358. return false;
  359. }
  360. private bool fnGotingTimeout(object[] param)
  361. {
  362. if (_vce.Status == RState.Timeout || _vce.Status == RState.Failed)
  363. {
  364. PostMsg(VceMSG.Error);
  365. return false;
  366. }
  367. if(_vce.Status == RState.End)
  368. currentSlot = targetSlot;
  369. return _vce.Status == RState.End;
  370. }
  371. private bool fnError(object[] param)
  372. {
  373. return true;
  374. }
  375. private bool fnStartHome(object[] param)
  376. {
  377. return _vce.HomeALL();
  378. }
  379. private bool fnHomeTimeout(object[] param)
  380. {
  381. if (_vce.Status == RState.Timeout || _vce.Status == RState.Failed)
  382. {
  383. PostMsg(VceMSG.Error);
  384. return false;
  385. }
  386. return _vce.Status == RState.End;
  387. }
  388. private bool fnStartOpenDoor(object[] param)
  389. {
  390. return _vce.OpenDoor();
  391. }
  392. private bool fnOpenDoorTimeout(object[] param)
  393. {
  394. if (_vce.Status == RState.Timeout || _vce.Status == RState.Failed)
  395. {
  396. PostMsg(VceMSG.Error);
  397. return false;
  398. }
  399. return _vce.Status == RState.End;
  400. }
  401. private bool fnStartCloseDoor(object[] param)
  402. {
  403. return _vce.CloseDoor();
  404. }
  405. private bool fnCloseDoorTimeout(object[] param)
  406. {
  407. if (_vce.Status == RState.Timeout || _vce.Status == RState.Failed)
  408. {
  409. PostMsg(VceMSG.Error);
  410. return false;
  411. }
  412. return _vce.Status == RState.End;
  413. }
  414. private bool fnStartMapping(object[] param)
  415. {
  416. return _vce.Map();
  417. }
  418. private bool fnMappingTimeout(object[] param)
  419. {
  420. if(_vce.Status == RState.Timeout || _vce.Status == RState.Failed)
  421. {
  422. PostMsg(VceMSG.Error);
  423. return false;
  424. }
  425. return _vce.Status == RState.End;
  426. }
  427. private bool fnStartLoading(object[] param)
  428. {
  429. return _vce.Load();
  430. }
  431. private bool fnLoadingTimeout(object[] param)
  432. {
  433. if (_vce.Status == RState.Timeout || _vce.Status == RState.Failed)
  434. {
  435. PostMsg(VceMSG.Error);
  436. return false;
  437. }
  438. return _vce.Status == RState.End;
  439. }
  440. private bool fnStartUnLoading(object[] param)
  441. {
  442. return _vce.UnLoad();
  443. }
  444. private bool fnUnLoadingTimeout(object[] param)
  445. {
  446. if (_vce.Status == RState.Timeout || _vce.Status == RState.Failed)
  447. {
  448. PostMsg(VceMSG.Error);
  449. return false;
  450. }
  451. return _vce.Status == RState.End;
  452. }
  453. public bool Check(int msg, out string reason, params object[] args)
  454. {
  455. reason = "";
  456. return true;
  457. }
  458. public int Invoke(string function, params object[] args)
  459. {
  460. switch (function)
  461. {
  462. case "Home":
  463. CheckToPostMessage((int)VceMSG.Home);
  464. return (int)VceMSG.Home;
  465. }
  466. return (int)VceMSG.None;
  467. }
  468. public bool CheckToPostMessage(int msg, params object[] args)
  469. {
  470. if (!fsm.FindTransition(fsm.State, msg))
  471. {
  472. LOG.Write(eEvent.WARN_FSM_WARN, _modulename, $"{_modulename} is in {(VceSTATE)fsm.State} state,can not do {(VceMSG)msg}");
  473. return false;
  474. }
  475. Running = true;
  476. fsm.PostMsg(msg, args);
  477. return true;
  478. }
  479. public bool CheckAcked(int msg)
  480. {
  481. return fsm.CheckExecuted(msg);
  482. }
  483. public bool IsPrepareTransferReady(ModuleName module, EnumTransferType transferType, int slot)
  484. {
  485. return false;
  486. }
  487. }
  488. }