VceEntity.cs 20 KB

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