LoadPortEntity.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. using System;
  2. using Aitex.Core.RT.Event;
  3. using Aitex.Core.RT.Fsm;
  4. using Aitex.Core.RT.Log;
  5. using Aitex.Core.RT.OperationCenter;
  6. using Aitex.Core.RT.Routine;
  7. using Aitex.Core.Util;
  8. using EFEM.RT.Modules;
  9. using EFEM.RT.Routines.LP;
  10. using MECF.Framework.Common.Equipment;
  11. namespace EFEM.RT.Devices
  12. {
  13. class LoadPortEntity : Entity, IEntity
  14. {
  15. public enum STATE
  16. {
  17. INIT,
  18. IDLE,
  19. HOME,
  20. LOAD,
  21. UNLOAD,
  22. READ,
  23. WRITE,
  24. ReadAndLoad,
  25. ERROR,
  26. Reset,
  27. };
  28. public enum MSG
  29. {
  30. HOME,
  31. ReadRFID,
  32. WriteRFID,
  33. Load,
  34. Unload,
  35. ReadAndLoad,
  36. RESET,
  37. ABORT,
  38. ERROR,
  39. };
  40. //routine
  41. private HomeRoutine homeRoutine = null;
  42. private LoadFoupRoutine loadRoutine = null;
  43. private UnloadFoupRoutine unloadRoutine = null;
  44. private ReadAndLoadRoutine readAndLoadRoutine = null;
  45. public string Name { get; set; }
  46. public bool IsIdle
  47. {
  48. get
  49. {
  50. return fsm.State == (int)LoadPortEntity.STATE.IDLE;
  51. }
  52. }
  53. public bool IsRunning
  54. {
  55. get
  56. {
  57. return fsm.State != (int)LoadPortEntity.STATE.INIT
  58. && fsm.State != (int)LoadPortEntity.STATE.IDLE
  59. && fsm.State != (int)LoadPortEntity.STATE.ERROR;
  60. }
  61. }
  62. public int FsmState
  63. {
  64. get
  65. {
  66. return fsm.State;
  67. }
  68. }
  69. public bool IsAlarm { get { return false; } }
  70. public bool IsWarning { get { return false; } }
  71. private ModuleName _chamber;
  72. public LoadPortEntity(string name)
  73. {
  74. Name = name;
  75. _chamber = (ModuleName)Enum.Parse(typeof(ModuleName), Name);
  76. fsm = new StateMachine<LoadPortEntity>(Name, (int)LoadPortEntity.STATE.INIT, 50);
  77. AnyStateTransition(LoadPortEntity.MSG.ERROR, fError, LoadPortEntity.STATE.ERROR);
  78. AnyStateTransition((int)FSM_MSG.ALARM, fError, (int)LoadPortEntity.STATE.ERROR);
  79. AnyStateTransition(LoadPortEntity.MSG.RESET, fInit, LoadPortEntity.STATE.IDLE);
  80. Transition(LoadPortEntity.STATE.INIT, FSM_MSG.TIMER, fInit, LoadPortEntity.STATE.IDLE);
  81. Transition(LoadPortEntity.STATE.INIT, LoadPortEntity.MSG.ERROR, fError, LoadPortEntity.STATE.ERROR);
  82. Transition(LoadPortEntity.STATE.ERROR, LoadPortEntity.MSG.HOME, fStartHome, LoadPortEntity.STATE.HOME);
  83. Transition(LoadPortEntity.STATE.IDLE, LoadPortEntity.MSG.HOME, fStartHome, LoadPortEntity.STATE.HOME);
  84. Transition(LoadPortEntity.STATE.HOME, FSM_MSG.TIMER, fHome, LoadPortEntity.STATE.IDLE);
  85. Transition(LoadPortEntity.STATE.IDLE, LoadPortEntity.MSG.Load, fStartLoad, LoadPortEntity.STATE.LOAD);
  86. Transition(LoadPortEntity.STATE.LOAD, FSM_MSG.TIMER, fLoad, LoadPortEntity.STATE.IDLE);
  87. Transition(LoadPortEntity.STATE.IDLE, LoadPortEntity.MSG.Unload, fStartUnload, LoadPortEntity.STATE.UNLOAD);
  88. Transition(LoadPortEntity.STATE.UNLOAD, FSM_MSG.TIMER, fUnload, LoadPortEntity.STATE.IDLE);
  89. Transition(LoadPortEntity.STATE.IDLE, LoadPortEntity.MSG.ReadAndLoad, fStartReadAndLoad, LoadPortEntity.STATE.ReadAndLoad);
  90. Transition(LoadPortEntity.STATE.ReadAndLoad, FSM_MSG.TIMER, fReadAndLoad, LoadPortEntity.STATE.IDLE);
  91. Running = true;
  92. }
  93. public bool Check(int msg, out string reason, object[] objs)
  94. {
  95. bool bRet = true;
  96. reason = "";
  97. switch (msg)
  98. {
  99. case (int)LoadPortEntity.MSG.Load:
  100. {
  101. if (fsm.State != (int)LoadPortEntity.STATE.IDLE)
  102. {
  103. reason = String.Format("{0} is busy {1},can't excute {2}", Name, State2String(fsm.State), Msg2String(msg));
  104. return false;
  105. }
  106. }
  107. break;
  108. default:
  109. break;
  110. }
  111. return bRet;
  112. }
  113. private string Msg2String(int msg)
  114. {
  115. string result = "";
  116. switch (msg)
  117. {
  118. case (int)LoadPortEntity.MSG.RESET:
  119. result = "复位";
  120. break;
  121. case (int)LoadPortEntity.MSG.ABORT:
  122. result = "终止";
  123. break;
  124. }
  125. return result;
  126. }
  127. private string State2String(int state)
  128. {
  129. string result = "";
  130. switch (state)
  131. {
  132. case (int)LoadPortEntity.STATE.INIT:
  133. case (int)LoadPortEntity.STATE.Reset:
  134. result = "初始化";
  135. break;
  136. case (int)LoadPortEntity.STATE.IDLE:
  137. result = "就绪";
  138. break;
  139. case (int)LoadPortEntity.STATE.ERROR:
  140. result = "错误";
  141. break;
  142. }
  143. return result;
  144. }
  145. protected override bool Init()
  146. {
  147. loadRoutine = new LoadFoupRoutine(Name, "Load");
  148. loadRoutine.Chamber = _chamber;
  149. loadRoutine.Initalize();
  150. unloadRoutine = new UnloadFoupRoutine();
  151. unloadRoutine.Initalize();
  152. unloadRoutine.Chamber = _chamber;
  153. homeRoutine = new HomeRoutine(Name, "Home");
  154. homeRoutine.Initalize();
  155. homeRoutine.Chamber = _chamber;
  156. readAndLoadRoutine = new ReadAndLoadRoutine(Name, "Read And Load");
  157. readAndLoadRoutine.Initalize();
  158. readAndLoadRoutine.Chamber = _chamber;
  159. OP.Subscribe($"{_chamber}.LPReset", (string cmd, object[] args) =>
  160. {
  161. if (FsmState != 8) return true;
  162. return CheckToPostMsg(MSG.RESET);
  163. });
  164. return true;
  165. }
  166. protected override void Term()
  167. {
  168. }
  169. #region
  170. private bool fStartHome(object[] objs)
  171. {
  172. Running = false;
  173. Result ret = homeRoutine.Start(objs);
  174. if (ret == Result.DONE)
  175. {
  176. return false;
  177. }
  178. else if (ret == Result.FAIL)
  179. {
  180. return false; //do noting
  181. }
  182. return true;
  183. }
  184. private bool fHome(object[] objs)
  185. {
  186. Result ret = homeRoutine.Monitor();
  187. if (ret == Result.DONE)
  188. {
  189. Running = true;
  190. return true;
  191. }
  192. else if (ret == Result.FAIL)
  193. {
  194. //do nothing
  195. //state = (int)STATE.ERROR;
  196. return true;
  197. }
  198. return false;
  199. }
  200. private bool fStartLoad(object[] objs)
  201. {
  202. Running = false;
  203. Result ret = loadRoutine.Start(objs);
  204. if (ret == Result.DONE)
  205. {
  206. return false;
  207. }
  208. else if (ret == Result.FAIL)
  209. {
  210. return false; //do noting
  211. }
  212. return true;
  213. }
  214. private bool fLoad(object[] objs)
  215. {
  216. Result ret = loadRoutine.Monitor();
  217. if (ret == Result.DONE)
  218. {
  219. Running = true;
  220. return true;
  221. }
  222. else if (ret == Result.FAIL)
  223. {
  224. PostMsg(MSG.ERROR);
  225. return true;
  226. }
  227. return false;
  228. }
  229. private bool fStartUnload(object[] objs)
  230. {
  231. Running = false;
  232. Result ret = unloadRoutine.Start(objs);
  233. if (ret == Result.DONE)
  234. {
  235. return false;
  236. }
  237. else if (ret == Result.FAIL)
  238. {
  239. return false; //do noting
  240. }
  241. return true;
  242. }
  243. private bool fUnload(object[] objs)
  244. {
  245. Result ret = unloadRoutine.Monitor();
  246. if (ret == Result.DONE)
  247. {
  248. Running = true;
  249. return true;
  250. }
  251. else if (ret == Result.FAIL)
  252. {
  253. //do nothing
  254. //state = (int)STATE.ERROR;
  255. PostMsg(MSG.ERROR);
  256. return true;
  257. }
  258. return false;
  259. }
  260. private bool fStartReadAndLoad(object[] objs)
  261. {
  262. Running = false;
  263. Result ret = readAndLoadRoutine.Start(objs);
  264. if (ret == Result.DONE)
  265. {
  266. return false;
  267. }
  268. else if (ret == Result.FAIL)
  269. {
  270. return false; //do noting
  271. }
  272. return true;
  273. }
  274. private bool fReadAndLoad(object[] objs)
  275. {
  276. Result ret = readAndLoadRoutine.Monitor();
  277. if (ret == Result.DONE)
  278. {
  279. Running = true;
  280. return true;
  281. }
  282. else if (ret == Result.FAIL)
  283. {
  284. //do nothing
  285. //state = (int)STATE.ERROR;
  286. PostMsg(MSG.ERROR);
  287. return false;
  288. }
  289. return false;
  290. }
  291. private bool fInit(object[] objs)
  292. {
  293. return true;
  294. }
  295. private bool fError(object[] objs)
  296. {
  297. Singleton<RouteManager>.Instance.CheckToPostMsg(RouteManager.MSG.ERROR);
  298. return true;
  299. }
  300. public bool CheckToPostMsg(MSG msg)
  301. {
  302. if (!fsm.FindTransition(fsm.State, (int)msg))
  303. {
  304. EV.PostMessage("System", EventEnum.DefaultWarning,
  305. string.Format("{0} is in {1} state,can not do {2}", Name, (STATE)fsm.State, (MSG)msg));
  306. return false;
  307. }
  308. PostMsg(msg);
  309. return true;
  310. }
  311. #endregion
  312. }
  313. }