VceEntity.cs 18 KB

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