RouteManager.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using Aitex.Core.RT.Fsm;
  8. using Aitex.Core.Common;
  9. using Aitex.Core.RT.DataCenter;
  10. using Aitex.Core.RT.Event;
  11. using Aitex.Core.RT.OperationCenter;
  12. using Aitex.Core.RT.Routine;
  13. using Aitex.Core.RT.SCCore;
  14. using Aitex.Core.Util;
  15. using MECF.Framework.Common.Equipment;
  16. using MECF.Framework.Common.SubstrateTrackings;
  17. using Venus_Core;
  18. using Venus_RT.Modules.PMs;
  19. using Aitex.Core.RT.Log;
  20. namespace Venus_RT.Modules
  21. {
  22. class RouteManager : Entity, IEntity
  23. {
  24. public enum MSG
  25. {
  26. MoveWafer,
  27. ReturnWafer,
  28. HomeUnit,
  29. PauseAuto,
  30. ResumeAuto,
  31. Stop,
  32. StartCycle,
  33. HOME,
  34. RESET,
  35. ABORT,
  36. ERROR,
  37. SetAutoMode,
  38. SetManualMode,
  39. ResetIdleCleanTime,
  40. ResetIdlePurgeTime,
  41. CreateJob,
  42. PauseJob,
  43. ResumeJob,
  44. StartJob,
  45. StopJob,
  46. AbortJob,
  47. JobDone,
  48. CassetteLeave, //For unload light control off afer job done
  49. Map,
  50. ReturnAllWafer,
  51. TMCycle,
  52. }
  53. public PMEntity PMA { get; private set; }
  54. public PMEntity PMB { get; private set; }
  55. public PMEntity PMC { get; private set; }
  56. public PMEntity PMD { get; private set; }
  57. public TMEntity TM { get; private set; }
  58. public LLEntity LLA { get; private set; }
  59. public LLEntity LLB { get; private set; }
  60. public EfemEntity EFEM { get; private set; }
  61. public string Name { get; set; }
  62. private TMCycle _TMCycle;
  63. public RouteManager()
  64. {
  65. Name = "System";
  66. if (ModuleHelper.IsInstalled(ModuleName.PMA))
  67. PMA = new PMEntity(ModuleName.PMA);
  68. if (ModuleHelper.IsInstalled(ModuleName.PMB))
  69. PMB = new PMEntity(ModuleName.PMB);
  70. if (ModuleHelper.IsInstalled(ModuleName.PMC))
  71. PMC = new PMEntity(ModuleName.PMC);
  72. if (ModuleHelper.IsInstalled(ModuleName.PMD))
  73. PMD = new PMEntity(ModuleName.PMD);
  74. if (ModuleHelper.IsInstalled(ModuleName.TM))
  75. TM = new TMEntity();
  76. if (ModuleHelper.IsInstalled(ModuleName.LLA))
  77. LLA = new LLEntity(ModuleName.LLA);
  78. if (ModuleHelper.IsInstalled(ModuleName.LLB))
  79. LLB = new LLEntity(ModuleName.LLB);
  80. fsm = new StateMachine<RouteManager>(Name, (int)RtState.Init, 200);
  81. SubscribeOperation();
  82. }
  83. public bool Check(int msg, out string reason, params object[] args)
  84. {
  85. if (!fsm.FindTransition(fsm.State, msg))
  86. {
  87. reason = String.Format("{0} is in {1} state,can not do {2}", Name, 0, (MSG)msg);
  88. return false;
  89. }
  90. if (msg == (int)MSG.StartCycle)
  91. {
  92. //if (!IsAutoMode)
  93. {
  94. reason = String.Format("can not do {0}, isn't auto mode.", msg.ToString());
  95. return false;
  96. }
  97. }
  98. reason = "";
  99. return true;
  100. }
  101. void SubscribeOperation()
  102. {
  103. OP.Subscribe("CreateWafer", InvokeCreateWafer);
  104. OP.Subscribe("DeleteWafer", InvokeDeleteWafer);
  105. }
  106. private bool InvokeCreateWafer(string arg1, object[] args)
  107. {
  108. ModuleName chamber = ModuleHelper.Converter(args[0].ToString());
  109. int slot = (int)args[1];
  110. WaferStatus state = WaferStatus.Normal;
  111. if (WaferManager.Instance.IsWaferSlotLocationValid(chamber, slot))
  112. {
  113. if (WaferManager.Instance.CheckHasWafer(chamber, slot))
  114. {
  115. EV.PostInfoLog("System", string.Format("{0} slot {1} already has wafer.create wafer is not valid", chamber, slot));
  116. }
  117. else if (WaferManager.Instance.CreateWafer(chamber, slot, state) != null)
  118. {
  119. //EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferCreate, chamber.ToString(), slot + 1, state.ToString());
  120. LOG.Write(eEvent.EV_WAFER_CREATE, ModuleName.System, chamber.ToString(), (slot + 1).ToString(), state.ToString());
  121. }
  122. }
  123. else
  124. {
  125. EV.PostWarningLog("System", string.Format("Invalid position,{0},{1}", chamber.ToString(), slot.ToString()));
  126. return false;
  127. }
  128. return true;
  129. }
  130. private bool InvokeDeleteWafer(string arg1, object[] args)
  131. {
  132. ModuleName chamber = ModuleHelper.Converter(args[0].ToString());
  133. int slot = (int)args[1];
  134. if (WaferManager.Instance.IsWaferSlotLocationValid(chamber, slot))
  135. {
  136. if (WaferManager.Instance.CheckHasWafer(chamber, slot))
  137. {
  138. WaferManager.Instance.DeleteWafer(chamber, slot);
  139. EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferDelete, chamber.ToString(), slot + 1);
  140. }
  141. else
  142. {
  143. EV.PostInfoLog("System", string.Format("No wafer at {0} {1}, delete not valid", chamber.ToString(), slot + 1));
  144. }
  145. }
  146. else
  147. {
  148. EV.PostWarningLog("System", string.Format("Invalid position,{0},{1}", chamber.ToString(), slot.ToString()));
  149. return false;
  150. }
  151. return true;
  152. }
  153. public PMEntity GetPM(ModuleName mod)
  154. {
  155. if (ModuleHelper.IsInstalled(mod))
  156. {
  157. switch (mod)
  158. {
  159. case ModuleName.PMA:
  160. return PMA;
  161. case ModuleName.PMB:
  162. return PMB;
  163. case ModuleName.PMC:
  164. return PMC;
  165. case ModuleName.PMD:
  166. return PMD;
  167. }
  168. }
  169. return null;
  170. }
  171. public LLEntity GetLL(ModuleName mod)
  172. {
  173. if (ModuleHelper.IsInstalled(mod))
  174. {
  175. switch (mod)
  176. {
  177. case ModuleName.LLA:
  178. return LLA;
  179. case ModuleName.LLB:
  180. return LLB;
  181. }
  182. }
  183. return null;
  184. }
  185. protected override bool Init()
  186. {
  187. PMA?.Initialize();
  188. PMB?.Initialize();
  189. TM?.Initialize();
  190. LLA?.Initialize();
  191. LLB?.Initialize();
  192. _TMCycle = new TMCycle();
  193. BuildTransitionTable();
  194. return true;
  195. }
  196. private void BuildTransitionTable()
  197. {
  198. fsm = new StateMachine<RouteManager>(ModuleName.System.ToString(), (int)RtState.Init, 50);
  199. //Init sequence
  200. Transition(RtState.Init, MSG.HOME, FsmStartHome, RtState.Initializing);
  201. Transition(RtState.Idle, MSG.HOME, FsmStartHome, RtState.Initializing);
  202. Transition(RtState.Error, MSG.HOME, FsmStartHome, RtState.Initializing);
  203. //// EnterExitTransition<RtState, FSM_MSG>(RtState.Initializing, fStartInit, FSM_MSG.NONE, null);
  204. ///
  205. Transition(RtState.Idle, FSM_MSG.TIMER, FsmMonitor, RtState.Idle);
  206. Transition(RtState.Init, FSM_MSG.TIMER, FsmMonitor, RtState.Init);
  207. Transition(RtState.Initializing, FSM_MSG.TIMER, FsmMonitorHome, RtState.Idle);
  208. Transition(RtState.Initializing, MSG.ERROR, FsmError, RtState.Error);
  209. Transition(RtState.Initializing, MSG.ABORT, FsmAbort, RtState.Init);
  210. // TM Cycle
  211. Transition(RtState.Idle, MSG.TMCycle, FsmStartTMCycle, RtState.TMCycle);
  212. Transition(RtState.TMCycle, FSM_MSG.TIMER, FsmMonitorTMCycle, RtState.Idle);
  213. Transition(RtState.TMCycle, MSG.ABORT, FsmAbort, RtState.Idle);
  214. }
  215. private bool FsmMonitor(object[] objs)
  216. {
  217. _debugRoutine();
  218. return true;
  219. }
  220. private bool FsmStartHome(object[] objs)
  221. {
  222. PMA?.Invoke("Home");
  223. PMB?.Invoke("Home");
  224. PMC?.Invoke("Home");
  225. PMD?.Invoke("Home");
  226. TM?.Invoke("Home");
  227. LLA?.Invoke("Home");
  228. LLB?.Invoke("Home");
  229. return true;
  230. }
  231. private bool FsmMonitorHome(object[] objs)
  232. {
  233. bool CheckHomed(string name, bool bValid, bool bDone)
  234. {
  235. if (bValid && !bDone)
  236. {
  237. if (fsm.ElapsedTime > 20 * 1000)
  238. {
  239. LOG.Write(eEvent.ERR_ROUTER, ModuleName.System, $"{name} home timeout");
  240. PostMsg(MSG.ERROR);
  241. return true;
  242. }
  243. else
  244. return false;
  245. }
  246. return true;
  247. }
  248. return CheckHomed("PMA", PMA != null, PMA != null&&PMA.IsIdle) &&
  249. CheckHomed("PMB", PMB != null, PMB != null&&PMA.IsIdle) &&
  250. CheckHomed("PMC", PMC != null, PMC != null&&PMC.IsIdle) &&
  251. CheckHomed("PMD", PMD != null, PMD != null&&PMD.IsIdle) &&
  252. CheckHomed("LLA", LLA != null, LLA != null&&LLA.IsIdle) &&
  253. CheckHomed("LLB", LLB != null, LLB != null&&LLB.IsIdle) &&
  254. CheckHomed("TM", TM != null, TM != null&&TM.IsIdle);
  255. }
  256. private bool FsmError(object[] objs)
  257. {
  258. return true;
  259. }
  260. private bool FsmAbort(object[] objs)
  261. {
  262. return true;
  263. }
  264. private bool FsmStartTMCycle(object[] objs)
  265. {
  266. return _TMCycle.Start() == RState.Running;
  267. }
  268. private bool FsmMonitorTMCycle(object[] objs)
  269. {
  270. RState ret = _TMCycle.Monitor();
  271. if (ret == RState.Failed || ret == RState.Timeout)
  272. {
  273. PostMsg(MSG.ERROR);
  274. return false;
  275. }
  276. return ret == RState.End;
  277. }
  278. private void _debugRoutine()
  279. {
  280. int flag = 0;
  281. // Test Home routine
  282. if (flag == 1)
  283. {
  284. PostMsg(MSG.HOME);
  285. }
  286. else if (flag == 2)
  287. {
  288. PostMsg(MSG.TMCycle);
  289. }
  290. }
  291. }
  292. }