RouteManager.cs 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986
  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.SCCore;
  13. using Aitex.Core.Util;
  14. using MECF.Framework.Common.Jobs;
  15. using MECF.Framework.Common.Equipment;
  16. using MECF.Framework.Common.SubstrateTrackings;
  17. using PunkHPX8_Core;
  18. using Aitex.Core.RT.Log;
  19. using SecsGem.Core.Application;
  20. using PunkHPX8_RT.Modules.SRD;
  21. using Aitex.Core.RT.Device;
  22. using MECF.Framework.Common.ToolLayout;
  23. using MECF.Framework.Common.Routine;
  24. using PunkHPX8_RT.Dispatch;
  25. using PunkHPX8_RT.Modules.Reservoir;
  26. using System.IO;
  27. using PunkHPX8_RT.Modules.Transporter;
  28. using PunkHPX8_RT.Devices.SRD;
  29. using MECF.Framework.Common.Alarm;
  30. using System.Diagnostics;
  31. using PunkHPX8_RT.Schedulers;
  32. using MECF.Framework.Common.ProcessCell;
  33. using System.Reflection;
  34. using PunkHPX8_RT.Modules.VpwMain;
  35. using PunkHPX8_RT.Modules.PlatingCell;
  36. namespace PunkHPX8_RT.Modules
  37. {
  38. class RouteManager : Entity, IEntity
  39. {
  40. public enum MSG
  41. {
  42. MoveWafer,
  43. ReturnWafer,
  44. HomeUnit,
  45. PauseAuto,
  46. ResumeAuto,
  47. Stop,
  48. StartCycle,
  49. StopCycle,
  50. HOME,
  51. RESET,
  52. ABORT,
  53. ERROR,
  54. SetAutoMode,
  55. SetManualMode,
  56. ResetIdleCleanTime,
  57. ResetIdlePurgeTime,
  58. CreateJob,
  59. PauseJob,
  60. PauseAllJobs,
  61. ResumeJob,
  62. ResumeAllJobs,
  63. StartJob,
  64. StopJob,
  65. AbortJob,
  66. JobDone,
  67. CassetteLeave, //For unload light control off afer job done
  68. Map,
  69. ReturnAllWafer,
  70. TMCycle,
  71. Retry,
  72. ConfirmComplete,
  73. ResetWafers,
  74. FaStartJob,
  75. FaStopJob,
  76. }
  77. #region 属性
  78. public string Name { get; set; }
  79. public bool IsAutoMode
  80. {
  81. get
  82. {
  83. return fsm.State == (int)RtState.AutoRunning || fsm.State == (int)RtState.AutoIdle||fsm.State==(int)RtState.AutoAborting;
  84. }
  85. }
  86. public bool IsFaAutoMode
  87. {
  88. get
  89. {
  90. return fsm.State == (int)RtState.AutoRunning || fsm.State == (int)RtState.AutoIdle;
  91. }
  92. }
  93. public bool IsInit
  94. {
  95. get { return fsm.State == (int)RtState.Init; }
  96. }
  97. public bool IsIdle
  98. {
  99. get { return fsm.State == (int)RtState.Idle || fsm.State == (int)RtState.AutoIdle; }
  100. }
  101. public bool IsAlarm
  102. {
  103. get { return fsm.State == (int)RtState.Error; }
  104. }
  105. public bool IsPaused
  106. {
  107. get { return _jobCycle.CycleState == RState.Paused; }
  108. }
  109. public bool IsRunning
  110. {
  111. get
  112. {
  113. return !IsInit && !IsAlarm && !IsIdle;
  114. }
  115. }
  116. /// <summary>
  117. /// 是否AutoRunning
  118. /// </summary>
  119. public bool IsAutoRunning
  120. {
  121. get { return fsm.State == (int)RtState.AutoRunning||fsm.State==(int)RtState.AutoAborting; }
  122. }
  123. /// <summary>
  124. /// 是否
  125. /// </summary>
  126. public bool IsAutoIdle
  127. {
  128. get { return fsm.State == (int)RtState.AutoIdle; }
  129. }
  130. /// <summary>
  131. /// EFEM实体
  132. /// </summary>
  133. public EfemEntity EFEM { get; }
  134. public WaferSize WaferSize { get; private set; }
  135. #endregion
  136. #region 内部变量
  137. private string _systemControlIp;
  138. private ICycle _jobCycle;
  139. /// <summary>
  140. /// 模块实体字典
  141. /// </summary>
  142. private Dictionary<string, IModuleEntity> _moduleEntitiesDic = new Dictionary<string, IModuleEntity>();
  143. /// <summary>
  144. /// 模块类型实体字典
  145. /// </summary>
  146. private Dictionary<ModuleType, List<IModuleEntity>> _modultTypeEntitiesDic = new Dictionary<ModuleType, List<IModuleEntity>>();
  147. /// <summary>
  148. /// Home stopwatch
  149. /// </summary>
  150. private Stopwatch _homeStopWatch = new Stopwatch();
  151. /// <summary>
  152. ///
  153. /// </summary>
  154. private List<ReservoirCellHomeRoutine> _reservoirCellRoutines = new List<ReservoirCellHomeRoutine>();
  155. #endregion
  156. /// <summary>
  157. /// 构造函数
  158. /// </summary>
  159. public RouteManager()
  160. {
  161. Name = "System";
  162. WaferSize = (WaferSize)SC.GetValue<int>("System.WaferSize");
  163. if (ModuleHelper.IsInstalled(ModuleName.EFEM))
  164. {
  165. EFEM = new EfemEntity();
  166. EFEM.Initialize();
  167. _moduleEntitiesDic[ModuleName.EFEM.ToString()] = EFEM;
  168. }
  169. InitialModuleList(VpwMainItemManager.Instance.InstalledModules, typeof(VpwMainEntity), ModuleType.VpwMain);
  170. InitialModuleList(VpwCellItemManager.Instance.InstalledModules, typeof(VpwCellEntity), ModuleType.VPW);
  171. InitialModuleList(SrdItemManager.Instance.InstalledModules, typeof(SRDEntity), ModuleType.SRD);
  172. InitialModuleList(ReservoirItemManager.Instance.InstalledModules, typeof(ReservoirEntity), ModuleType.Reservoir);
  173. InitialModuleList(PlatingCellItemManager.Instance.InstalledModules, typeof(PlatingCellEntity), ModuleType.PlatingCell);
  174. InitialPlatingCellVerticalModuleList();
  175. fsm = new StateMachine<RouteManager>(Name, (int)RtState.Init, 200);
  176. SubscribeOperation();
  177. SubscribeDataVariable();
  178. }
  179. /// <summary>
  180. /// 初始化模块集合
  181. /// </summary>
  182. /// <param name="lst"></param>
  183. /// <param name="entityType"></param>
  184. private void InitialModuleList(List<string> lst,Type entityType,ModuleType moduleType)
  185. {
  186. foreach(string item in lst)
  187. {
  188. InitialModule(item, entityType,moduleType);
  189. }
  190. }
  191. /// <summary>
  192. /// 初始化PlatingCellVertical
  193. /// </summary>
  194. private void InitialPlatingCellVerticalModuleList()
  195. {
  196. List<string> lst = ModuleMatcherManager.Instance.GetAllPlatingCellVertialList();
  197. InitialModuleList(lst,typeof(PlatingCellVerticalEntity),ModuleType.PlatingCellVertical);
  198. }
  199. /// <summary>
  200. /// 初始化模块对象
  201. /// </summary>
  202. /// <param name="item"></param>
  203. /// <param name="moduleType"></param>
  204. private void InitialModule(string item,Type entityType,ModuleType moduleType)
  205. {
  206. ModuleName moduleName = (ModuleName)Enum.Parse(typeof(ModuleName), item);
  207. IModuleEntity moduleEntity= (IModuleEntity)System.Activator.CreateInstance(entityType,moduleName);
  208. moduleEntity.Initialize();
  209. _moduleEntitiesDic[item] = moduleEntity;
  210. List<IModuleEntity> lst = new List<IModuleEntity>();
  211. if(_modultTypeEntitiesDic.ContainsKey(moduleType))
  212. {
  213. lst= _modultTypeEntitiesDic[moduleType];
  214. }
  215. else
  216. {
  217. _modultTypeEntitiesDic[moduleType] = lst;
  218. }
  219. lst.Add(moduleEntity);
  220. }
  221. public bool Check(int msg, out string reason, params object[] args)
  222. {
  223. if (!fsm.FindTransition(fsm.State, msg))
  224. {
  225. reason = String.Format("{0} is in {1} state,can not do {2}", Name, 0, (MSG)msg);
  226. return false;
  227. }
  228. if (msg == (int)MSG.StartCycle)
  229. {
  230. if (!IsAutoMode)
  231. {
  232. reason = String.Format("can not do {0}, isn't auto mode.", msg.ToString());
  233. return false;
  234. }
  235. }
  236. reason = "";
  237. return true;
  238. }
  239. /// <summary>
  240. /// 订阅数据
  241. /// </summary>
  242. void SubscribeDataVariable()
  243. {
  244. DATA.Subscribe("System.SystemControlIp", ()=>_systemControlIp, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  245. DATA.Subscribe("Rt.Status", () => ((RtState)fsm.State).ToString(), SubscriptionAttribute.FLAG.IgnoreSaveDB);
  246. DATA.Subscribe("System.State", () => ((RtState)fsm.State).ToString(), SubscriptionAttribute.FLAG.IgnoreSaveDB);
  247. DATA.Subscribe("System.IsAutoMode", () => IsAutoMode, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  248. DATA.Subscribe("System.IsAutoRunning", () => IsAutoRunning, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  249. DATA.Subscribe("System.IsIdle", () => IsIdle || IsInit, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  250. DATA.Subscribe("System.IsAlarm", () => IsAlarm, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  251. DATA.Subscribe("System.IsBusy", () => IsRunning, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  252. DATA.Subscribe("System.IsConnectedWithHost", () => CheckSecsGemOnline(Singleton<SecGemApplication>.Instance.ControlState),SubscriptionAttribute.FLAG.IgnoreSaveDB);
  253. DATA.Subscribe("System.IsDisconnectWithHost", () => CheckSecsGemOnline(Singleton<SecGemApplication>.Instance.ControlState),SubscriptionAttribute.FLAG.IgnoreSaveDB);
  254. DATA.Subscribe("System.EquipmentMode", () => IsAutoMode ? "Auto":"Manual", SubscriptionAttribute.FLAG.IgnoreSaveDB);
  255. DATA.Subscribe("EquipmentStatus", () =>
  256. {
  257. if (IsInit) return 0;
  258. if (IsIdle) return 1;
  259. if (IsAlarm) return 3;
  260. if (IsPaused) return 4;
  261. return 2;
  262. }, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  263. }
  264. /// <summary>
  265. /// 订阅操作
  266. /// </summary>
  267. void SubscribeOperation()
  268. {
  269. OP.Subscribe("ApplySystemControl", ApplySystemControl);
  270. OP.Subscribe("ReleaseSystemControl", ReleaseSystemControl);
  271. OP.Subscribe("CreateWafer", InvokeCreateWafer);
  272. OP.Subscribe("DeleteWafer", InvokeDeleteWafer);
  273. OP.Subscribe("System.Home", (cmd, args) => CheckToPostMessage((int)MSG.HOME, args));
  274. DATA.Subscribe("SYSTEM.FsmState", () => (((RtState)fsm.State).ToString()), SubscriptionAttribute.FLAG.IgnoreSaveDB);
  275. OP.Subscribe("System.ReturnAllWafer", (string cmd, object[] args) =>
  276. {
  277. return CheckToPostMessage((int)MSG.ReturnAllWafer, args[0], args[1], args[2], args[3]);
  278. });
  279. OP.Subscribe("System.MoveWafer", (string cmd, object[] args) =>
  280. {
  281. if (!Enum.TryParse((string)args[0], out ModuleName source))
  282. {
  283. EV.PostWarningLog(Name, $"Parameter source {(string)args[0]} not valid");
  284. return false;
  285. }
  286. if (!Enum.TryParse((string)args[2], out ModuleName destination))
  287. {
  288. EV.PostWarningLog(Name, $"Parameter destination {(string)args[1]} not valid");
  289. return false;
  290. }
  291. return CheckToPostMessage((int)MSG.MoveWafer,
  292. source, (int)args[1],
  293. destination, (int)args[3],
  294. args[4], args[5],
  295. args[6], args[7], (string)args[8]);
  296. });
  297. OP.Subscribe("System.HomeAll", (string cmd, object[] args) =>
  298. {
  299. return CheckToPostMessage((int)MSG.HOME);
  300. });
  301. OP.Subscribe("System.Abort", (string cmd, object[] args) =>
  302. {
  303. return CheckToPostMessage((int)MSG.ABORT);
  304. });
  305. OP.Subscribe("System.Reset", (string cmd, object[] args) =>
  306. {
  307. return CheckToPostMessage((int)MSG.RESET);
  308. });
  309. OP.Subscribe("System.SetAutoMode", (string cmd, object[] args) =>
  310. {
  311. return CheckToPostMessage((int)MSG.SetAutoMode);
  312. });
  313. OP.Subscribe("System.SetManualMode", (string cmd, object[] args) =>
  314. {
  315. return CheckToPostMessage((int)MSG.SetManualMode);
  316. });
  317. OP.Subscribe("System.CreateJob", (string cmd, object[] args) =>
  318. {
  319. return CheckToPostMessage((int)MSG.CreateJob, args[0]);
  320. });
  321. OP.Subscribe("System.StartJob", (string cmd, object[] args) =>
  322. {
  323. return CheckToPostMessage((int)MSG.StartJob, args[0]);
  324. });
  325. OP.Subscribe("System.PauseJob", (string cmd, object[] args) =>
  326. {
  327. return CheckToPostMessage((int)MSG.PauseJob, args[0]);
  328. });
  329. OP.Subscribe("System.ResumeJob", (string cmd, object[] args) =>
  330. {
  331. return CheckToPostMessage((int)MSG.ResumeJob, args[0]);
  332. });
  333. OP.Subscribe("System.PauseAllJob", (cmd, args) => { return CheckToPostMessage((int)MSG.PauseAllJobs); }) ;
  334. OP.Subscribe("System.ResumeAllJob", (cmd, args) => { return CheckToPostMessage((int)MSG.ResumeAllJobs); });
  335. OP.Subscribe("System.StopJob", (string cmd, object[] args) =>
  336. {
  337. return CheckToPostMessage((int)MSG.StopJob, args[0]);
  338. });
  339. OP.Subscribe("System.AbortJob", (string cmd, object[] args) =>
  340. {
  341. return CheckToPostMessage((int)MSG.AbortJob, args[0]);
  342. });
  343. OP.Subscribe(RtOperation.SetConfig.ToString(), (name, args) =>
  344. {
  345. string sc_key = args[0] as string;
  346. if (!string.IsNullOrWhiteSpace(sc_key) && args.Length > 1)
  347. {
  348. SC.SetItemValue(sc_key, args[1]);
  349. }
  350. return true;
  351. });
  352. OP.Subscribe("System.SetWaferSize", (string cmd, object[] args) =>
  353. {
  354. string module = (string)args[0];
  355. string size = (string)args[1];
  356. switch (size)
  357. {
  358. case "3":
  359. WaferManager.Instance.UpdateWaferSize(ModuleHelper.Converter(module), 0, WaferSize.WS3);
  360. break;
  361. case "4":
  362. WaferManager.Instance.UpdateWaferSize(ModuleHelper.Converter(module), 0, WaferSize.WS4);
  363. break;
  364. case "6":
  365. WaferManager.Instance.UpdateWaferSize(ModuleHelper.Converter(module), 0, WaferSize.WS6);
  366. break;
  367. default:
  368. EV.PostWarningLog("System", $"wafer size {size} not valid");
  369. break;
  370. }
  371. return true;
  372. });
  373. //OP.Subscribe("System.CassetteLeave", (string cmd, object[] args) =>
  374. //{
  375. // return CheckToPostMessage((int)MSG.CassetteLeave);
  376. //});
  377. OP.Subscribe("System.Retry", (string cmd, object[] args) =>
  378. {
  379. return CheckToPostMessage((int)MSG.Retry, args[0]);
  380. });
  381. OP.Subscribe("System.ConfirmComplete", (string cmd, object[] args) =>
  382. {
  383. return CheckToPostMessage((int)MSG.ConfirmComplete, args[0]);
  384. });
  385. OP.Subscribe("WaferHolder.ResetLayoutWafers", (string cmd, object[] args) =>
  386. {
  387. return CheckToPostMessage((int)MSG.ResetWafers, args);
  388. });
  389. }
  390. /// <summary>
  391. /// 申请系统控制权
  392. /// </summary>
  393. /// <param name="cmd"></param>
  394. /// <param name="args"></param>
  395. /// <returns></returns>
  396. private bool ApplySystemControl(string cmd, object[] args)
  397. {
  398. if (args[0].ToString() == "")
  399. {
  400. LOG.WriteLog(eEvent.WARN_ROUTER, "System", $"Current IP does not allow the application of UI control permissions");
  401. return false;
  402. }
  403. string applyIp = args[0].ToString();
  404. if (string.IsNullOrEmpty(_systemControlIp))
  405. {
  406. _systemControlIp = applyIp;
  407. LOG.WriteLog(eEvent.EV_ROUTER, "System", $"{_systemControlIp} apply system control success");
  408. return true;
  409. }
  410. else if(_systemControlIp!=applyIp)
  411. {
  412. LOG.WriteLog(eEvent.WARN_ROUTER, "System", $"{_systemControlIp} already has system control permission");
  413. return false;
  414. }
  415. return false;
  416. }
  417. /// <summary>
  418. /// 释放系统控制权
  419. /// </summary>
  420. /// <param name="cmd"></param>
  421. /// <param name="args"></param>
  422. /// <returns></returns>
  423. private bool ReleaseSystemControl(string cmd, object[] args)
  424. {
  425. string releaseIp = args[0].ToString();
  426. if (_systemControlIp == releaseIp)
  427. {
  428. LOG.WriteLog(eEvent.EV_ROUTER, "System", $"{releaseIp} release system control success");
  429. _systemControlIp = "";
  430. }
  431. else
  432. {
  433. LOG.WriteLog(eEvent.ERR_ROUTER, "System", $"{releaseIp} is not SystemControlIp");
  434. }
  435. return false;
  436. }
  437. /// <summary>
  438. /// 检验Secsgem在线情况
  439. /// </summary>
  440. /// <param name="controlState"></param>
  441. /// <returns></returns>
  442. private bool CheckSecsGemOnline(SecsGem.Core.EnumData.ControlState controlState)
  443. {
  444. if (controlState == SecsGem.Core.EnumData.ControlState.OnlineLocal || controlState == SecsGem.Core.EnumData.ControlState.OnlineRemote)
  445. {
  446. return true;
  447. }
  448. return false;
  449. }
  450. public bool CheckToPostMessage(int msg, params object[] args)
  451. {
  452. if (!fsm.FindTransition(fsm.State, msg))
  453. {
  454. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, $"System is in {(RtState)fsm.State} state,can not do {(MSG)msg}");
  455. return false;
  456. }
  457. Running = true;
  458. fsm.PostMsg(msg, args);
  459. return true;
  460. }
  461. private bool InvokeCreateWafer(string arg1, object[] args)
  462. {
  463. ModuleName chamber = ModuleHelper.Converter(args[0].ToString());
  464. int slot = (int)args[1];
  465. WaferStatus state = WaferStatus.Normal;
  466. if (WaferManager.Instance.IsWaferSlotLocationValid(chamber, slot))
  467. {
  468. if (WaferManager.Instance.CheckHasWafer(chamber, slot))
  469. {
  470. LOG.Write(eEvent.EV_ROUTER, "System", string.Format("{0} slot {1} already has wafer.create wafer is not valid", chamber, slot));
  471. }
  472. else if (WaferManager.Instance.CreateWafer(chamber, slot, state) != null)
  473. {
  474. LOG.Write(eEvent.EV_WAFER_CREATE, ModuleName.System, chamber.ToString(), (slot + 1).ToString(), state.ToString());
  475. }
  476. }
  477. else
  478. {
  479. LOG.Write(eEvent.WARN_ROUTER, "System", string.Format("Invalid position,{0},{1}", chamber.ToString(), slot.ToString()));
  480. return false;
  481. }
  482. return true;
  483. }
  484. private bool InvokeDeleteWafer(string arg1, object[] args)
  485. {
  486. ModuleName chamber = ModuleHelper.Converter(args[0].ToString());
  487. int slot = (int)args[1];
  488. if (WaferManager.Instance.IsWaferSlotLocationValid(chamber, slot))
  489. {
  490. if (WaferManager.Instance.CheckHasWafer(chamber, slot))
  491. {
  492. WaferManager.Instance.DeleteWafer(chamber, slot);
  493. EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferDelete, chamber.ToString(), slot + 1);
  494. }
  495. else
  496. {
  497. LOG.Write(eEvent.EV_ROUTER, "System", string.Format("No wafer at {0} {1}, delete not valid", chamber.ToString(), slot + 1));
  498. }
  499. }
  500. else
  501. {
  502. LOG.Write(eEvent.WARN_ROUTER, "System", string.Format("Invalid position,{0},{1}", chamber.ToString(), slot.ToString()));
  503. return false;
  504. }
  505. return true;
  506. }
  507. protected override bool Init()
  508. {
  509. _jobCycle = new JobDispatcher();
  510. Singleton<FaRemoteManager>.Instance.JobCycle = _jobCycle;
  511. BuildTransitionTable();
  512. return true;
  513. }
  514. private void BuildTransitionTable()
  515. {
  516. //Init sequence
  517. Transition(RtState.Init, MSG.HOME, FsmStartHome, RtState.Initializing);
  518. Transition(RtState.Idle, MSG.HOME, FsmStartHome, RtState.Initializing);
  519. Transition(RtState.Error, MSG.HOME, FsmStartHome, RtState.Initializing);
  520. EnterExitTransition<RtState, FSM_MSG>(RtState.AutoRunning, FsmEnterAutoRunning, FSM_MSG.NONE, FsmExitAutoTransfer);
  521. EnterExitTransition<RtState, FSM_MSG>(RtState.Transfer, null, FSM_MSG.NONE, FsmExitTransfer);
  522. EnterExitTransition<RtState, FSM_MSG>(RtState.ReturnWafer, null, FSM_MSG.NONE, FsmExitReturnWafer);
  523. AnyStateTransition(MSG.ERROR, FsmError, RtState.Error);
  524. Transition(RtState.Idle, FSM_MSG.TIMER, FsmMonitor, RtState.Idle);
  525. Transition(RtState.Init, FSM_MSG.TIMER, FsmMonitor, RtState.Init);
  526. Transition(RtState.Init, MSG.ABORT, FsmAbort, RtState.Init);
  527. Transition(RtState.Error, MSG.ABORT, FsmAbort, RtState.Init);
  528. Transition(RtState.Idle, MSG.ABORT, FsmAbort, RtState.Idle);
  529. Transition(RtState.Initializing, MSG.ABORT, FsmAbort, RtState.Init);
  530. Transition(RtState.Initializing, FSM_MSG.TIMER, FsmMonitorHome, RtState.Idle);
  531. Transition(RtState.Initializing, MSG.ERROR, FsmError, RtState.Error);
  532. //Auto/manual
  533. Transition(RtState.Idle, MSG.SetAutoMode, FsmStartAutoTransfer, RtState.AutoIdle);
  534. Transition(RtState.AutoAborting, FSM_MSG.TIMER, FsmAutoTransfer, RtState.AutoIdle);
  535. Transition(RtState.AutoRunning, FSM_MSG.TIMER, FsmAutoTransfer, RtState.AutoIdle);
  536. Transition(RtState.AutoRunning, MSG.ABORT, FsmAbort, RtState.AutoAborting);
  537. Transition(RtState.AutoAborting, MSG.SetManualMode, FsmStartAbortingSetManualMode, RtState.Idle);
  538. //Transition(RtState.AutoRunning, MSG.SetManualMode, FsmStartSetManualMode, RtState.Idle);
  539. Transition(RtState.AutoRunning, MSG.JobDone, FsmJobDone, RtState.AutoIdle);
  540. //Transition(RtState.AutoRunning, MSG.CassetteLeave, fCassetteLeave, RtState.AutoRunning); //For unload light control off afer job done
  541. Transition(RtState.AutoRunning, MSG.CreateJob, FsmCreateJob, RtState.AutoRunning);
  542. Transition(RtState.AutoRunning, MSG.StartJob, FsmStartJob, RtState.AutoRunning);
  543. Transition(RtState.AutoRunning, MSG.PauseJob, FsmPauseJob, RtState.AutoRunning);
  544. Transition(RtState.AutoRunning, MSG.PauseAllJobs, FsmPauseAllJobs, RtState.AutoRunning);
  545. Transition(RtState.AutoRunning, MSG.ResumeJob, FsmResumeJob, RtState.AutoRunning);
  546. Transition(RtState.AutoRunning, MSG.ResumeAllJobs, FsmResumeAllJobs, RtState.AutoRunning);
  547. Transition(RtState.AutoRunning, MSG.StopJob, FsmStopJob, RtState.AutoRunning);
  548. Transition(RtState.AutoRunning, MSG.Retry, FsmRetry, RtState.AutoRunning);
  549. Transition(RtState.AutoRunning, MSG.ConfirmComplete, FsmConfirmComplete, RtState.AutoRunning);
  550. Transition(RtState.AutoIdle, FSM_MSG.TIMER, FsmMonitorAutoIdle, RtState.AutoIdle);
  551. Transition(RtState.AutoIdle, MSG.SetManualMode, FsmStartSetManualMode, RtState.Idle);
  552. Transition(RtState.AutoIdle, MSG.CreateJob, FsmCreateJob, RtState.AutoIdle);
  553. Transition(RtState.AutoIdle, MSG.StartJob, FsmStartJob, RtState.AutoRunning);
  554. Transition(RtState.AutoIdle, MSG.PauseJob, FsmPauseJob, RtState.AutoIdle);
  555. Transition(RtState.AutoIdle, MSG.PauseAllJobs, FsmPauseAllJobs, RtState.AutoIdle);
  556. Transition(RtState.AutoIdle, MSG.ResumeJob, FsmResumeJob, RtState.AutoIdle);
  557. Transition(RtState.AutoIdle, MSG.ResumeAllJobs, FsmResumeAllJobs, RtState.AutoIdle);
  558. Transition(RtState.AutoIdle, MSG.StopJob, FsmStopJob, RtState.AutoIdle);
  559. Transition(RtState.AutoIdle, MSG.FaStartJob, FsmEnterAutoRunning, RtState.AutoRunning);
  560. Transition(RtState.AutoRunning, MSG.FaStartJob, FsmEnterAutoRunning, RtState.AutoRunning);
  561. }
  562. private bool FsmMonitor(object[] objs)
  563. {
  564. return true;
  565. }
  566. /// <summary>
  567. /// 检验前置条件
  568. /// </summary>
  569. /// <returns></returns>
  570. private bool CheckPreCondition()
  571. {
  572. if (ModuleHelper.IsInstalled(ModuleName.SRD1))
  573. {
  574. SrdCommonDevice srdCommonDevice = DEVICE.GetDevice<SrdCommonDevice>($"{ModuleName.SRD1}.Common");
  575. if (!srdCommonDevice.CommonData.ChuckVacuum)
  576. {
  577. LOG.WriteLog(eEvent.ERR_AXIS, ModuleName.SRD1.ToString(), "Vacuum is on");
  578. return false;
  579. }
  580. }
  581. if (ModuleHelper.IsInstalled(ModuleName.SRD2))
  582. {
  583. SrdCommonDevice srdCommonDevice = DEVICE.GetDevice<SrdCommonDevice>($"{ModuleName.SRD2}.Common");
  584. if (!srdCommonDevice.CommonData.ChuckVacuum)
  585. {
  586. LOG.WriteLog(eEvent.ERR_AXIS, ModuleName.SRD2.ToString(), "Vacuum is on");
  587. return false;
  588. }
  589. }
  590. return true;
  591. }
  592. private bool FsmStartHome(object[] objs)
  593. {
  594. if (!CheckPreCondition())
  595. {
  596. return false;
  597. }
  598. List<string> keys = _moduleEntitiesDic.Keys.ToList();
  599. foreach (string item in keys)
  600. {
  601. if(!Enum.TryParse(item, out ModuleName moduleName))
  602. {
  603. continue;
  604. }
  605. if (!NeedSequenceHome(item))
  606. {
  607. IModuleEntity entity = _moduleEntitiesDic[item];
  608. if (!entity.IsDisable&&!ModuleHelper.IsVPWCell(moduleName))
  609. {
  610. entity.Invoke("HomeAll");
  611. }
  612. }
  613. }
  614. _reservoirCellRoutines.Clear();
  615. foreach (string item in keys)
  616. {
  617. if (Enum.TryParse(item, out ModuleName moduleName))
  618. {
  619. if (ModuleHelper.IsReservoir(moduleName))
  620. {
  621. IModuleEntity moduleEntity = _moduleEntitiesDic[item];
  622. if (!moduleEntity.IsDisable)
  623. {
  624. ReservoirCellHomeRoutine reservoirCellHomeRoutine = new ReservoirCellHomeRoutine(item);
  625. _reservoirCellRoutines.Add(reservoirCellHomeRoutine);
  626. }
  627. }
  628. }
  629. }
  630. foreach (ReservoirCellHomeRoutine item in _reservoirCellRoutines)
  631. {
  632. item.Start();
  633. }
  634. foreach (string item in keys)
  635. {
  636. if (Enum.TryParse(item, out ModuleName moduleName))
  637. {
  638. if (ModuleHelper.IsReservoir(moduleName))
  639. {
  640. IModuleEntity moduleEntity = _moduleEntitiesDic[item];
  641. }
  642. }
  643. }
  644. _homeStopWatch.Restart();
  645. _jobCycle.RemoveAllJob();
  646. return true;
  647. }
  648. /// <summary>
  649. /// 需要按照顺序Home
  650. /// </summary>
  651. /// <returns></returns>
  652. private bool NeedSequenceHome(string item)
  653. {
  654. if(Enum.TryParse(item,out ModuleName moduleName))
  655. {
  656. if (!ModuleHelper.IsPlatingCell(moduleName)&&!ModuleHelper.IsReservoir(moduleName))
  657. {
  658. return false;
  659. }
  660. }
  661. return true;
  662. }
  663. private bool FsmMonitorHome(object[] objs)
  664. {
  665. if (_homeStopWatch.ElapsedMilliseconds <= 500)
  666. {
  667. return false;
  668. }
  669. List<string> keys = LoadInitializeCheckModuleList();
  670. int idleCount = 0;
  671. foreach (string item in keys)
  672. {
  673. IModuleEntity ModuleEntity = _moduleEntitiesDic[item];
  674. if (ModuleEntity.IsError)
  675. {
  676. LOG.Write(eEvent.ERR_ROUTER, ModuleName.System, $"{ModuleEntity.Module} home error");
  677. PostMsg(MSG.ERROR);
  678. return true;
  679. }
  680. else if (ModuleEntity.IsIdle)
  681. {
  682. idleCount++;
  683. }
  684. }
  685. int homeCount = 0;
  686. foreach (ReservoirCellHomeRoutine item in _reservoirCellRoutines)
  687. {
  688. RState ret = item.Monitor();
  689. if (ret != RState.Running)
  690. {
  691. homeCount++;
  692. }
  693. }
  694. if (idleCount == keys.Count)
  695. {
  696. return true;
  697. }
  698. else
  699. {
  700. return false;
  701. }
  702. }
  703. /// <summary>
  704. /// 加载初始化检验模块集合
  705. /// </summary>
  706. /// <returns></returns>
  707. private List<string> LoadInitializeCheckModuleList()
  708. {
  709. string checkModuleList = SC.GetStringValue("System.InitializeCheckModuleList");
  710. List<string> moduleList= checkModuleList.Split(',').ToList();
  711. List<string> modules = new List<string>();
  712. foreach (var item in moduleList)
  713. {
  714. if(Enum.TryParse(item, out ModuleName moduleName))
  715. {
  716. if (ModuleHelper.IsInstalled(moduleName))
  717. {
  718. modules.Add(item);
  719. }
  720. }
  721. }
  722. return modules;
  723. }
  724. private bool FsmEnterAutoRunning(object[] objs)
  725. {
  726. return true;
  727. }
  728. private bool FsmExitAutoTransfer(object[] objs)
  729. {
  730. _jobCycle.Clear();
  731. return true;
  732. }
  733. private bool FsmExitTransfer(object[] objs)
  734. {
  735. return true;
  736. }
  737. private bool FsmExitReturnWafer(object[] objs)
  738. {
  739. return true;
  740. }
  741. private bool FsmError(object[] objs)
  742. {
  743. return true;
  744. }
  745. private bool FsmAbort(object[] objs)
  746. {
  747. //_manualTransfer.Clear();
  748. //_returnWafer.Clear();
  749. //_jobCycle.Clear();
  750. AlarmListManager.Instance.ClearAllAlarm();
  751. return _jobCycle.SystemAbort();
  752. }
  753. private bool FsmStartAutoTransfer(object[] objs)
  754. {
  755. return _jobCycle.Start(objs) == RState.Running;
  756. }
  757. private bool FsmAutoTransfer(object[] objs)
  758. {
  759. if (_jobCycle.CheckJobJustDone(out string jobInfo))
  760. {
  761. //EV.PostPopDialogMessage(EventLevel.InformationNoDelay, "Job complete", jobInfo);
  762. LOG.Write(eEvent.EV_ROUTER, ModuleName.System, $"Job complete,{jobInfo}");
  763. }
  764. if (_jobCycle.CheckAllJobDone())
  765. {
  766. if (!CheckToPostMessage((int)MSG.JobDone))
  767. return false;
  768. }
  769. RState ret = _jobCycle.Monitor();
  770. if (ret == RState.Failed)
  771. {
  772. if (!CheckToPostMessage((int)MSG.ERROR))
  773. return false;
  774. }
  775. return ret == RState.End;
  776. }
  777. private bool FsmAbortAutoTransfer(object[] objs)
  778. {
  779. _jobCycle.Clear();
  780. return true;
  781. }
  782. private bool FsmJobDone(object[] objs)
  783. {
  784. return true;
  785. }
  786. private bool FsmCreateJob(object[] objs)
  787. {
  788. return _jobCycle.CreateJob((Dictionary<string, object>)objs[0],out string reason);
  789. }
  790. private bool FsmStartJob(object[] objs)
  791. {
  792. return _jobCycle.StartJob((string)objs[0],out string reason);
  793. }
  794. private bool FsmPauseJob(object[] objs)
  795. {
  796. return _jobCycle.PauseJob((string)objs[0],out string reason);
  797. }
  798. private bool FsmResumeJob(object[] objs)
  799. {
  800. return _jobCycle.ResumeJob((string)objs[0],out string reason);
  801. }
  802. private bool FsmPauseAllJobs(object[] objs)
  803. {
  804. return _jobCycle.PauseAllJobs();
  805. }
  806. private bool FsmResumeAllJobs(object[] objs)
  807. {
  808. return _jobCycle.ResumeAllJobs();
  809. }
  810. private bool FsmStopJob(object[] objs)
  811. {
  812. return _jobCycle.StopJob((string)objs[0], out string reason);
  813. }
  814. /// <summary>
  815. /// 重试
  816. /// </summary>
  817. /// <param name="objs"></param>
  818. /// <returns></returns>
  819. private bool FsmRetry(object[] objs)
  820. {
  821. string moduleName = objs[0].ToString();
  822. IModuleEntity moduleEntity = GetModule<IModuleEntity>(moduleName);
  823. moduleEntity.Invoke("Retry");
  824. return true;
  825. }
  826. /// <summary>
  827. /// 重试
  828. /// </summary>
  829. /// <param name="objs"></param>
  830. /// <returns></returns>
  831. private bool FsmConfirmComplete(object[] objs)
  832. {
  833. string moduleName = objs[0].ToString();
  834. IModuleEntity moduleEntity = GetModule<IModuleEntity>(moduleName);
  835. moduleEntity.Invoke("ConfirmComplete");
  836. return true;
  837. }
  838. private bool FsmMonitorAutoIdle(object[] objs)
  839. {
  840. RState ret = _jobCycle.Monitor();
  841. return ret == RState.End;
  842. }
  843. private bool FsmStartAbortingSetManualMode(object[] objs)
  844. {
  845. return _jobCycle.RemoveAllJob();
  846. }
  847. private bool FsmStartSetManualMode(object[] objs)
  848. {
  849. if (_jobCycle.HasJobRunning)
  850. {
  851. LOG.Write(eEvent.WARN_ROUTER, "System", "Can not change to manual mode, abort running job first");
  852. return false;
  853. }
  854. return true;
  855. }
  856. /// <summary>
  857. /// 获取模块对象
  858. /// </summary>
  859. /// <typeparam name="T"></typeparam>
  860. /// <param name="name"></param>
  861. /// <returns></returns>
  862. public T GetModule<T>(string name) where T : class, IModuleEntity
  863. {
  864. return _moduleEntitiesDic.ContainsKey(name)?_moduleEntitiesDic[name] as T:default(T);
  865. }
  866. /// <summary>
  867. /// 根据模块类型获取模块集合
  868. /// </summary>
  869. /// <param name="type"></param>
  870. /// <returns></returns>
  871. public List<IModuleEntity> GetModulesByModuleType(ModuleType type)
  872. {
  873. return _modultTypeEntitiesDic.ContainsKey(type) ? _modultTypeEntitiesDic[type] : new List<IModuleEntity>();
  874. }
  875. }
  876. }