VceEntity.cs 16 KB

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