EfemEntity.cs 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046
  1. using Aitex.Core.Common;
  2. using Aitex.Core.RT.DataCenter;
  3. using Aitex.Core.RT.Event;
  4. using Aitex.Core.RT.Fsm;
  5. using Aitex.Core.RT.Log;
  6. using Aitex.Core.RT.OperationCenter;
  7. using Aitex.Core.RT.SCCore;
  8. using Aitex.Core.Utilities;
  9. using Aitex.Sorter.Common;
  10. using MECF.Framework.Common.Equipment;
  11. using MECF.Framework.Common.Schedulers;
  12. using MECF.Framework.Common.SubstrateTrackings;
  13. using System;
  14. using VirgoCommon;
  15. using VirgoRT.Device;
  16. using VirgoRT.Device.YASKAWA;
  17. using VirgoRT.Devices.EFEM;
  18. using VirgoRT.Modules.LPs;
  19. namespace VirgoRT.Modules
  20. {
  21. class EfemEntity : Entity, IEntity, IModuleEntity
  22. {
  23. private int _bigWafer = 0;
  24. private int _midWafer = 0;
  25. private int _smallWafer = 0;
  26. public bool LiftDone { get; set; }
  27. public enum STATE
  28. {
  29. Unknown, // 0
  30. Initializing, // 1
  31. Idle, // 2
  32. Error, // 3
  33. Picking, // 4
  34. Placing, // 5
  35. Aligning, // 6
  36. Mapping, // 7
  37. Init, // 8
  38. Orgshing, // 9
  39. Lifting, // 10
  40. InitingAL, // 11
  41. InitingRB, // 12
  42. Extending, // 13
  43. Retracting, // 14
  44. //SettingLamp, // 15
  45. Swapping,
  46. Gotoing,
  47. Gripping,
  48. Ungripping,
  49. }
  50. public enum MSG
  51. {
  52. HomeAll, // 0
  53. Pick, // 1
  54. Place, // 2
  55. Align, // 3
  56. ActionDone, // 4
  57. RecHwMsg, // 5
  58. MoveCmd, // 6
  59. //LED, // 7
  60. Recover, // 8
  61. Goto, // 9
  62. Error, // 10
  63. Online, // 11
  64. CommReady, // 12
  65. Lift, // 13
  66. HomeAL, // 14
  67. HomeRB, // 15
  68. Extend, // 16
  69. Retract, // 17
  70. PMLiftPinUp, // 18
  71. PMLiftPinDown, // 19
  72. TurnOffBuzzer,
  73. //SwitchOnBuzzerAndRed,
  74. Abort,
  75. Map,
  76. ToInit,
  77. Cool,
  78. PickAndPlace,
  79. Grip,
  80. Ungrip,
  81. PMSlitDoorOpened, //
  82. PMSlitDoorClosed, //
  83. LiftActionDone,
  84. }
  85. public bool Check(int msg, out string reason, params object[] args)
  86. {
  87. throw new NotImplementedException();
  88. }
  89. // Fields
  90. //
  91. private readonly string Name;
  92. private readonly Efem _efem;
  93. private readonly LoadPortModule[] _lpms = new LoadPortModule[2];
  94. public Efem EfemDevice => _efem;
  95. public LoadPortModule[] LPEntity
  96. {
  97. get { return _lpms; }
  98. }
  99. // Constructor
  100. //
  101. public EfemEntity()
  102. {
  103. _smallWafer = SC.GetValue<int>($"System.SmallWafer");
  104. _midWafer = SC.GetValue<int>($"System.MidWafer");
  105. _bigWafer = SC.GetValue<int>($"System.BigWafer");
  106. _efem = new Efem();
  107. LiftDone = true;
  108. Name = ModuleName.EFEM.ToString();
  109. InitFsmMap();
  110. }
  111. public void NotifyLP(ModuleName mod, LoadPortModule.MSG msg)
  112. {
  113. _lpms[mod - ModuleName.LP1].PostMsg(msg);
  114. }
  115. public void NotifyLPError(ModuleName mod )
  116. {
  117. _lpms[mod - ModuleName.LP1].PostMsg(LoadPortModule.MSG.ActionDone);
  118. _lpms[mod - ModuleName.LP1].LPDevice.OnError();
  119. }
  120. protected override bool Init()
  121. {
  122. _lpms[0] = new LoadPortModule(ModuleName.LP1, _efem);
  123. _lpms[1] = new LoadPortModule(ModuleName.LP2, _efem);
  124. _lpms[0].Initialize();
  125. _lpms[1].Initialize();
  126. OP.Subscribe($"{ModuleName.EFEM}.{EfemOperation.Home}", (cmd, args) => { PostMsg(MSG.HomeAll); return true; });
  127. OP.Subscribe($"{ModuleName.EFEM}.{EfemOperation.ClearError}", (cmd, args) => { PostMsg(MSG.Recover); return true; });
  128. OP.Subscribe($"{ModuleName.EFEM}.{EfemOperation.TurnOffBuzzer}", (cmd, args) => { PostMsg(MSG.TurnOffBuzzer); return true; });
  129. //OP.Subscribe($"{ModuleName.EFEM}.{EfemOperation.SwitchOnBuzzerAndRed}", (cmd, args) => { PostMsg(MSG.SwitchOnBuzzerAndRed); return true; });
  130. OP.Subscribe($"{ModuleName.EFEM}.Online", (cmd, args) => { PostMsg(MSG.Online); return true; });
  131. OP.Subscribe($"{ModuleName.EfemRobot}.{EfemOperation.Pick}", (cmd, args) => { PostMsg(MSG.Pick, args[0], args[1], args[3], args[2]); return true; });
  132. OP.Subscribe($"{ModuleName.EfemRobot}.{EfemOperation.Place}", (cmd, args) => { PostMsg(MSG.Place, args[0], args[1], args[3], args[2]); return true; });
  133. OP.Subscribe($"{ModuleName.EfemRobot}.{EfemOperation.Extend}", (cmd, args) => { PostMsg(MSG.Extend, args[0], args[1], args[2]); return true; });
  134. OP.Subscribe($"{ModuleName.EfemRobot}.{EfemOperation.Retract}", (cmd, args) => { PostMsg(MSG.Retract, args[0], args[1]); return true; });
  135. OP.Subscribe($"{ModuleName.EfemRobot}.{EfemOperation.Abort}", (cmd, args) => { PostMsg(MSG.Abort); return true; });
  136. OP.Subscribe($"{ModuleName.EfemRobot}.{EfemOperation.Home}", (cmd, args) => { PostMsg(MSG.HomeRB); return true; });
  137. OP.Subscribe($"{ModuleName.EfemRobot}.{EfemOperation.Grip}", (cmd, args) =>
  138. {
  139. bool isGrip = ((string)args[0]).ToLower() == "on";
  140. PostMsg(isGrip ? MSG.Grip : MSG.Ungrip, args[1]);
  141. return true;
  142. });
  143. OP.Subscribe($"{ModuleName.Aligner1}.{EfemOperation.Home}", (cmd, args) => { PostMsg(MSG.HomeAL, ModuleName.Aligner1); return true; });
  144. OP.Subscribe($"{ModuleName.Aligner2}.{EfemOperation.Home}", (cmd, args) => { PostMsg(MSG.HomeAL, ModuleName.Aligner2); return true; });
  145. OP.Subscribe($"{ModuleName.Cooling1}.{EfemOperation.Home}", (cmd, args) => { PostMsg(MSG.HomeAL, ModuleName.Cooling1); return true; });
  146. OP.Subscribe($"{ModuleName.Cooling2}.{EfemOperation.Home}", (cmd, args) => { PostMsg(MSG.HomeAL, ModuleName.Cooling2); return true; });
  147. OP.Subscribe($"{ModuleName.Aligner1}.{EfemOperation.Align}", (cmd, args) => { PostMsg(MSG.Align, ModuleName.Aligner1, args[0]); return true; });
  148. OP.Subscribe($"{ModuleName.Aligner2}.{EfemOperation.Align}", (cmd, args) => { PostMsg(MSG.Align, ModuleName.Aligner2, args[0]); return true; });
  149. OP.Subscribe($"{ModuleName.Cooling1}.{EfemOperation.Align}", (cmd, args) => { PostMsg(MSG.Align, ModuleName.Cooling1, args[0]); return true; });
  150. OP.Subscribe($"{ModuleName.Cooling2}.{EfemOperation.Align}", (cmd, args) => { PostMsg(MSG.Align, ModuleName.Cooling2, args[0]); return true; });
  151. OP.Subscribe($"{ModuleName.Aligner1}.{EfemOperation.Lift}", (cmd, args) => { PostMsg(MSG.Lift, ModuleName.Aligner1, args[0]); return true; });
  152. OP.Subscribe($"{ModuleName.Aligner2}.{EfemOperation.Lift}", (cmd, args) => { PostMsg(MSG.Lift, ModuleName.Aligner2, args[0]); return true; });
  153. OP.Subscribe($"{ModuleName.Cooling1}.{EfemOperation.Lift}", (cmd, args) => { PostMsg(MSG.Lift, ModuleName.Cooling1, args[0]); return true; });
  154. OP.Subscribe($"{ModuleName.Cooling2}.{EfemOperation.Lift}", (cmd, args) => { PostMsg(MSG.Lift, ModuleName.Cooling2, args[0]); return true; });
  155. DATA.Subscribe($"{Name}.FsmState", () => ((STATE)fsm.State).ToString());
  156. DATA.Subscribe($"{Name}.FsmPrevState", () => ((STATE)fsm.PrevState).ToString());
  157. DATA.Subscribe($"{Name}.FsmLastMessage", GetFsmLastMessage);
  158. DATA.Subscribe($"{Name}.SmallWafer", () => _smallWafer);
  159. DATA.Subscribe($"{Name}.BigWafer", () => _bigWafer);
  160. DATA.Subscribe($"{Name}.MidWafer", () => _midWafer);
  161. return true;
  162. }
  163. private void InitFsmMap()
  164. {
  165. fsm = new StateMachine<EfemEntity>("EFEM", (int)STATE.Unknown, 50);
  166. fsm.EnableRepeatedMsg(true);
  167. AnyStateTransition(FSM_MSG.TIMER, fnMonitor, FSM_STATE.SAME);
  168. AnyStateTransition(MSG.RecHwMsg, fnRecMsg, FSM_STATE.SAME);
  169. //AnyStateTransition(MSG.LED, fnSetLED, STATE.SettingLamp);
  170. AnyStateTransition(MSG.TurnOffBuzzer, fnTurnOffBuzzer, FSM_STATE.SAME);
  171. //AnyStateTransition(MSG.SwitchOnBuzzerAndRed, fnSwitchOnBuzzerAndRed, FSM_STATE.SAME);
  172. AnyStateTransition(MSG.Recover, fnRecover, STATE.Idle);
  173. AnyStateTransition(MSG.Error, fnError, STATE.Error);
  174. AnyStateTransition(MSG.Online, fnOnline, FSM_STATE.SAME);
  175. AnyStateTransition(MSG.Abort, fnAbortRobot, STATE.Idle);
  176. AnyStateTransition(MSG.ToInit, fnToInit, STATE.Init);
  177. EnterExitTransition<STATE, FSM_MSG>(STATE.Initializing, fnEnterExecute, FSM_MSG.NONE, fnExitExecute);
  178. EnterExitTransition<STATE, FSM_MSG>(STATE.InitingRB, fnEnterExecute, FSM_MSG.NONE, null);
  179. EnterExitTransition<STATE, FSM_MSG>(STATE.InitingAL, fnEnterExecute, FSM_MSG.NONE, null);
  180. EnterExitTransition<STATE, FSM_MSG>(STATE.Picking, fnEnterExecute, FSM_MSG.NONE, fnExitExecute);
  181. EnterExitTransition<STATE, FSM_MSG>(STATE.Gotoing, fnEnterExecute, FSM_MSG.NONE, fnExitExecute);
  182. EnterExitTransition<STATE, FSM_MSG>(STATE.Placing, fnEnterExecute, FSM_MSG.NONE, fnExitExecute);
  183. EnterExitTransition<STATE, FSM_MSG>(STATE.Swapping, fnEnterExecute, FSM_MSG.NONE, fnExitExecute);
  184. EnterExitTransition<STATE, FSM_MSG>(STATE.Extending, fnEnterExecute, FSM_MSG.NONE, fnExitExecute);
  185. EnterExitTransition<STATE, FSM_MSG>(STATE.Retracting, fnEnterExecute, FSM_MSG.NONE, fnExitExecute);
  186. EnterExitTransition<STATE, FSM_MSG>(STATE.Lifting, fnEnterExecute, FSM_MSG.NONE, null);
  187. EnterExitTransition<STATE, FSM_MSG>(STATE.Aligning, fnEnterExecute, FSM_MSG.NONE, null);
  188. //EnterExitTransition<STATE, FSM_MSG>(STATE.SettingLamp, fnEnterExecute, FSM_MSG.NONE, null);
  189. EnterExitTransition<STATE, FSM_MSG>(STATE.Mapping, fnEnterExecute, FSM_MSG.NONE, fnExitExecute);
  190. EnterExitTransition<STATE, FSM_MSG>(STATE.Gripping, fnEnterExecute, FSM_MSG.NONE, null);
  191. EnterExitTransition<STATE, FSM_MSG>(STATE.Ungripping, fnEnterExecute, FSM_MSG.NONE, null);
  192. Transition(STATE.Unknown, MSG.CommReady, null, STATE.Init);
  193. // Home
  194. Transition(STATE.Init, MSG.HomeAll, fnHomeAll, STATE.Initializing);
  195. Transition(STATE.Idle, MSG.HomeAll, fnHomeAll, STATE.Initializing); // 暂时加,出错的时候做 HOME
  196. Transition(STATE.Initializing, MSG.ActionDone, null, STATE.Orgshing);
  197. Transition(STATE.Orgshing, MSG.ActionDone, fnActionDone, STATE.Idle);
  198. Transition(STATE.Idle, MSG.HomeRB, fnHomeRobot, STATE.InitingRB);
  199. Transition(STATE.InitingRB, MSG.ActionDone, null, STATE.Idle);
  200. //Transition(STATE.SettingLamp, MSG.ActionDone, fnSetLampDone, STATE.Idle);
  201. // Pick
  202. Transition(STATE.Idle, MSG.Pick, fnPick, STATE.Picking);
  203. Transition(STATE.Picking, MSG.ActionDone, fnActionDone, STATE.Idle);
  204. Transition(STATE.Picking, MSG.PMLiftPinUp, fnPmPinUp, STATE.Idle);
  205. Transition(STATE.Picking, MSG.PMLiftPinDown, fnPmPinDown, STATE.Idle);
  206. Transition(STATE.Picking, MSG.PMSlitDoorOpened, fnPmSlitDoorOpened, STATE.Idle);
  207. // Place
  208. Transition(STATE.Idle, MSG.Place, fnPlace, STATE.Placing);
  209. Transition(STATE.Placing, MSG.ActionDone, fnActionDone, STATE.Idle);
  210. Transition(STATE.Placing, MSG.PMLiftPinUp, fnPmPinUp, STATE.Idle);
  211. Transition(STATE.Placing, MSG.PMLiftPinDown, fnPmPinDown, STATE.Idle);
  212. Transition(STATE.Placing, MSG.PMSlitDoorOpened, fnPmSlitDoorOpened, STATE.Idle);
  213. // PickAndPlace
  214. Transition(STATE.Idle, MSG.PickAndPlace, fnSwap, STATE.Swapping);
  215. Transition(STATE.Swapping, MSG.ActionDone, fnActionDone, STATE.Idle);
  216. Transition(STATE.Swapping, MSG.PMLiftPinUp, fnPmPinUp, STATE.Idle);
  217. Transition(STATE.Swapping, MSG.PMLiftPinDown, fnPmPinDown, STATE.Idle);
  218. Transition(STATE.Swapping, MSG.PMSlitDoorOpened, fnPmSlitDoorOpened, STATE.Idle);
  219. // Goto
  220. Transition(STATE.Idle, MSG.Goto, fnGoto, STATE.Gotoing);
  221. Transition(STATE.Gotoing, MSG.ActionDone, fnActionDone, STATE.Idle);
  222. // Extend
  223. Transition(STATE.Idle, MSG.Extend, fnExtend, STATE.Extending);
  224. Transition(STATE.Extending, MSG.ActionDone, fnActionDone, STATE.Idle);
  225. // Retract
  226. Transition(STATE.Idle, MSG.Retract, fnRetract, STATE.Retracting);
  227. Transition(STATE.Retracting, MSG.ActionDone, fnActionDone, STATE.Idle);
  228. // Map
  229. Transition(STATE.Idle, MSG.Map, fnMap, STATE.Mapping);
  230. Transition(STATE.Mapping, MSG.ActionDone, fnActionDone, STATE.Idle);
  231. // Grip
  232. Transition(STATE.Idle, MSG.Grip, fnGrip, STATE.Gripping);
  233. Transition(STATE.Gripping, MSG.ActionDone, fnActionDone, STATE.Idle);
  234. // Ungrip
  235. Transition(STATE.Idle, MSG.Ungrip, fnUngrip, STATE.Ungripping);
  236. Transition(STATE.Ungripping, MSG.ActionDone, fnActionDone, STATE.Idle);
  237. // Aligner
  238. Transition(STATE.Idle, MSG.HomeAL, fnHomeAligner, STATE.InitingAL);
  239. Transition(STATE.InitingAL, MSG.ActionDone, fnActionDone, STATE.Idle);
  240. Transition(STATE.Idle, MSG.Lift, fnLift, STATE.Lifting);
  241. Transition(STATE.Lifting, MSG.LiftActionDone, fnActionDone, STATE.Idle);
  242. Transition(STATE.Idle, MSG.Align, fnAlign, STATE.Aligning);
  243. Transition(STATE.Aligning, MSG.ActionDone, fnActionDone, STATE.Idle);
  244. EnumLoop<STATE>.ForEach((item) => { fsm.MapState((int)item, item.ToString()); });
  245. EnumLoop<MSG>.ForEach((item) => { fsm.MapMessage((int)item, item.ToString()); });
  246. }
  247. private bool fnHomeAll(object[] param)
  248. {
  249. _efem.ClearActions();
  250. _efem.HomeAll();
  251. return true;
  252. }
  253. private bool fnHomeRobot(object[] param)
  254. {
  255. _efem.Home(ModuleName.EfemRobot);
  256. return true;
  257. }
  258. private bool fnHomeAligner(object[] param)
  259. {
  260. // module
  261. ModuleName unit = ModuleName.EFEM;
  262. if (param[0] is string s1)
  263. unit = ModuleNameString.ToEnum(s1);
  264. else if (param[0] is ModuleName mod)
  265. unit = mod;
  266. else
  267. throw new ArgumentException("Argument error");
  268. _efem.Home(unit);
  269. return true;
  270. }
  271. private bool fnEnterExecute(object[] param)
  272. {
  273. _efem.ExecuteAction();
  274. return false;
  275. }
  276. private bool fnExitExecute(object[] param)
  277. {
  278. _efem.ExecuteAction();
  279. return false;
  280. }
  281. private bool fnActionDone(object[] param)
  282. {
  283. try
  284. {
  285. EfemOperation actionType = (EfemOperation)param[0];
  286. if (actionType == EfemOperation.Orgsh)
  287. {
  288. if (_efem.HasActions)
  289. {
  290. _efem.ExecuteAction();
  291. return false;
  292. }
  293. }
  294. if (actionType == EfemOperation.Extend)
  295. {
  296. if (fsm.State == (int)STATE.Placing)
  297. {
  298. _efem.ExecuteAction();
  299. return false;
  300. }
  301. else if (fsm.State == (int)STATE.Picking)
  302. {
  303. if (_efem.HasActions)
  304. {
  305. _efem.ExecuteAction();
  306. return false;
  307. }
  308. else
  309. {
  310. return true;
  311. }
  312. }
  313. else if (fsm.State == (int)STATE.Swapping)
  314. {
  315. if (_efem.HasActions)
  316. {
  317. _efem.ExecuteAction();
  318. return false;
  319. }
  320. else
  321. {
  322. return true;
  323. }
  324. }
  325. }
  326. return true;
  327. }
  328. catch (Exception ex)
  329. {
  330. EV.PostAlarmLog(ModuleName.EFEM.ToString(), ex.Message);
  331. return true;
  332. }
  333. }
  334. public bool CheckToPostMessage(int msg, params object[] args)
  335. {
  336. if (!fsm.FindTransition(fsm.State, msg))
  337. {
  338. EV.PostWarningLog(Name, $"{Name} is in {(STATE)fsm.State} state,can not do {(MSG)msg}");
  339. return false;
  340. }
  341. Running = true;
  342. fsm.PostMsg(msg, args);
  343. return true;
  344. }
  345. private bool fnRecMsg(object[] param)
  346. {
  347. if (param == null) return false;
  348. string strHwMsg = param[0] as string;
  349. if (_efem is EfemBase device)
  350. {
  351. device.ReceiveMessage(strHwMsg);
  352. return true;
  353. }
  354. return false;
  355. }
  356. private bool fnMonitor(object[] param)
  357. {
  358. STATE curSt = (STATE)fsm.State;
  359. if (curSt == STATE.Initializing || curSt == STATE.Mapping || curSt == STATE.Picking || curSt == STATE.Placing
  360. || curSt == STATE.Orgshing || curSt == STATE.Lifting || curSt == STATE.Extending || curSt == STATE.Retracting
  361. || curSt == STATE.InitingAL || curSt == STATE.InitingRB)
  362. {
  363. int time = SC.GetValue<int>("EFEM.MotionTimeout");
  364. if (fsm.ElapsedTime > time * 1000)
  365. {
  366. EV.PostAlarmLog("EFEM", $"Can not complete motion {curSt} in {time} seconds. ");
  367. PostMsg(MSG.Error);
  368. }
  369. }
  370. if (curSt == STATE.Aligning)
  371. {
  372. int time = SC.GetValue<int>("EFEM.AlignTimeout");
  373. if (fsm.ElapsedTime > time * 1000)
  374. {
  375. EV.PostAlarmLog(ModuleName.Aligner.ToString(), "Align timeout");
  376. PostMsg(MSG.ActionDone, "alignment timeout");
  377. }
  378. }
  379. return true;
  380. }
  381. private bool fnOnline(object[] param)
  382. {
  383. bool bOnlineFlag = (bool)param[0];
  384. if (_efem is EfemBase efem)
  385. {
  386. efem.SetOnline(bOnlineFlag);
  387. }
  388. return true;
  389. }
  390. private string GetFsmLastMessage()
  391. {
  392. int msg = fsm.LastMsg;
  393. if (msg >= (int)MSG.HomeAll && msg <= (int)MSG.Error)
  394. return ((MSG)msg).ToString();
  395. if (msg == (int)FSM_MSG.TIMER)
  396. return "Timer";
  397. return msg.ToString();
  398. }
  399. private bool fnError(object[] param)
  400. {
  401. return true;
  402. }
  403. private bool fnToInit(object[] param)
  404. {
  405. return true;
  406. }
  407. private bool fnRecover(object[] param)
  408. {
  409. _efem.ClearActions();
  410. _efem.ClearError();
  411. //_efem.ExecuteAction();
  412. if (!_efem.Comm.IsConnected)
  413. {
  414. _efem.Comm.Reconnect();
  415. }
  416. return true;
  417. }
  418. private bool fnAbortRobot(object[] param)
  419. {
  420. _efem.ClearActions();
  421. _efem.AbortRobot();
  422. //_efem.ExecuteAction();
  423. return true;
  424. }
  425. private bool fnSetLED(object[] param)
  426. {
  427. LightType light = (LightType)param[0];
  428. LightStatus st = (LightStatus)param[1];
  429. _efem.SetLamp(light, st);
  430. return true;
  431. }
  432. private bool fnTurnOffBuzzer(object[] param)
  433. {
  434. _efem.TurnOffBuzzer();
  435. return false;
  436. }
  437. //private bool fnSwitchOnBuzzerAndRed(object[] param)
  438. //{
  439. // _efem.SwitchOnBuzzerAndRed();
  440. // return false;
  441. //}
  442. //
  443. private bool fnSetLampDone(object[] param)
  444. {
  445. if (_efem.HasActions)
  446. {
  447. _efem.ExecuteAction();
  448. return false;
  449. }
  450. else
  451. {
  452. return true;
  453. }
  454. }
  455. private bool fnPick(object[] param)
  456. {
  457. // module
  458. ModuleName unit = ModuleName.EFEM;
  459. if (param[0] is string s1)
  460. unit = ModuleNameString.ToEnum(s1);
  461. else if (param[0] is ModuleName mod)
  462. unit = mod;
  463. else
  464. throw new ArgumentException("Argument error");
  465. // slot
  466. byte slot = (byte)(int)param[1];
  467. // hand
  468. Hand arm = (Hand)Enum.Parse(typeof(Hand), param[2].ToString());
  469. // wafer size
  470. WaferSize ws1 = WaferSize.WS0;
  471. if (param[3] is string s2)
  472. {
  473. if (Enum.TryParse(s2, out WaferSize p5))
  474. ws1 = p5;
  475. }
  476. else if (param[3] is WaferSize p6)
  477. {
  478. ws1 = p6;
  479. }
  480. MoveParam mp = new MoveParam(unit, slot, ModuleName.EfemRobot, (byte)arm, arm, ws1);
  481. if (!_efem.Pick(mp))
  482. return false;
  483. return true;
  484. }
  485. private bool fnPlace(object[] param)
  486. {
  487. // module
  488. ModuleName unit = ModuleName.EFEM;
  489. if (param[0] is string s1)
  490. unit = ModuleNameString.ToEnum(s1);
  491. else if (param[0] is ModuleName mod)
  492. unit = mod;
  493. else
  494. throw new ArgumentException("Argument error");
  495. // slot
  496. byte slot = (byte)(int)param[1];
  497. // hand
  498. Hand arm = (Hand)Enum.Parse(typeof(Hand), param[2].ToString());
  499. // wafer size
  500. WaferSize ws1 = WaferSize.WS0;
  501. if (param[3] is string s2)
  502. {
  503. if (Enum.TryParse(s2, out WaferSize p5))
  504. ws1 = p5;
  505. }
  506. else if (param[3] is WaferSize p6)
  507. {
  508. ws1 = p6;
  509. }
  510. MoveParam mp = new MoveParam(ModuleName.EfemRobot, (byte)arm, unit, slot, arm, ws1);
  511. if (!_efem.Place(mp))
  512. return false;
  513. return true;
  514. }
  515. private bool fnGoto(object[] param)
  516. {
  517. // module
  518. ModuleName unit = ModuleName.EFEM;
  519. if (param[0] is string s1)
  520. unit = ModuleNameString.ToEnum(s1);
  521. else if (param[0] is ModuleName mod)
  522. unit = mod;
  523. else
  524. throw new ArgumentException("Argument error");
  525. // slot
  526. byte slot = (byte)(int)param[1];
  527. Hand arm = Hand.Blade1;
  528. WaferSize ws = WaferSize.WS6;
  529. if (WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 0))
  530. {
  531. arm = Hand.Blade1;
  532. ws = WaferManager.Instance.GetWafer(ModuleName.EfemRobot, 0).Size;
  533. }
  534. else if (WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 1))
  535. {
  536. arm = Hand.Blade2;
  537. ws = WaferManager.Instance.GetWafer(ModuleName.EfemRobot, 1).Size;
  538. }
  539. MoveParam mp = new MoveParam(unit, slot, unit, slot, arm, ws);
  540. _efem.Goto(mp);
  541. return true;
  542. }
  543. private bool fnSwap(object[] param)
  544. {
  545. // module
  546. ModuleName unit = ModuleName.EFEM;
  547. if (param[0] is string s1)
  548. unit = ModuleNameString.ToEnum(s1);
  549. else if (param[0] is ModuleName mod)
  550. unit = mod;
  551. else
  552. throw new ArgumentException("Argument error");
  553. // pickSlot
  554. byte pickSlot = (byte)(int)param[1];
  555. // pick hand
  556. Hand pickArm = (Hand)Enum.Parse(typeof(Hand), param[2].ToString());
  557. // wafer size
  558. WaferSize ws1 = WaferSize.WS0;
  559. if (param[5] is string s2)
  560. {
  561. if (Enum.TryParse(s2, out WaferSize p5))
  562. ws1 = p5;
  563. }
  564. else if (param[5] is WaferSize p6)
  565. {
  566. ws1 = p6;
  567. }
  568. MoveParam pickParam = new MoveParam(unit, pickSlot, ModuleName.EfemRobot, (byte)pickArm, pickArm, ws1);
  569. // place slot
  570. byte placeSlot = (byte)(int)param[4];
  571. // hand
  572. Hand placeArm = (Hand)Enum.Parse(typeof(Hand), param[3].ToString());
  573. MoveParam placeParam = new MoveParam(ModuleName.EfemRobot, (byte)placeArm, unit, placeSlot, placeArm, ws1);
  574. _efem.PickAndPlace(pickParam, placeParam);
  575. return true;
  576. }
  577. private bool fnExtend(object[] param)
  578. {
  579. // module
  580. ModuleName unit = ModuleName.EFEM;
  581. if (param[0] is string s1)
  582. unit = ModuleNameString.ToEnum(s1);
  583. else if (param[0] is ModuleName mod)
  584. unit = mod;
  585. else
  586. throw new ArgumentException("Argument error");
  587. Hand arm = (Hand)Enum.Parse(typeof(Hand), (string)param[2]);
  588. ExtendParam mp = new ExtendParam
  589. {
  590. Module = unit,
  591. Arm = arm,
  592. Pos = (ExtendPos)Enum.Parse(typeof(ExtendPos), param[1] as string),
  593. ws = (WaferSize)param[2]
  594. };
  595. if (!_efem.Extend(mp))
  596. return false;
  597. return true;
  598. }
  599. private bool fnRetract(object[] param)
  600. {
  601. // module
  602. ModuleName unit = ModuleName.EFEM;
  603. if (param[0] is string s1)
  604. unit = ModuleNameString.ToEnum(s1);
  605. else if (param[0] is ModuleName mod)
  606. unit = mod;
  607. else
  608. throw new ArgumentException("Argument error");
  609. Hand arm = (Hand)Enum.Parse(typeof(Hand), (string)param[2]);
  610. ExtendParam mp = new ExtendParam
  611. {
  612. Module = unit,
  613. Arm = arm,
  614. Pos = (ExtendPos)Enum.Parse(typeof(ExtendPos), param[1] as string)
  615. };
  616. if (!_efem.Retract(mp))
  617. return false;
  618. return true;
  619. }
  620. private bool fnPmPinUp(object[] param)
  621. {
  622. _efem.UpdateStatus((ushort)param[0], ActionStatus.Completed);
  623. if (_efem.HasActions)
  624. {
  625. _efem.ExecuteAction();
  626. return false;
  627. }
  628. else
  629. {
  630. return true;
  631. }
  632. }
  633. private bool fnPmPinDown(object[] param)
  634. {
  635. _efem.UpdateStatus((ushort)param[0], ActionStatus.Completed);
  636. if (_efem.HasActions)
  637. {
  638. _efem.ExecuteAction();
  639. return false;
  640. }
  641. else
  642. {
  643. return true;
  644. }
  645. }
  646. private bool fnPmSlitDoorOpened(object[] param)
  647. {
  648. _efem.UpdateStatus((ushort)param[0], ActionStatus.Completed);
  649. if (_efem.HasActions)
  650. {
  651. _efem.ExecuteAction();
  652. return false;
  653. }
  654. else
  655. {
  656. return true;
  657. }
  658. }
  659. private bool fnLift(object[] param)
  660. {
  661. // module
  662. ModuleName unit = ModuleName.EFEM;
  663. if (param[0] is string s1)
  664. unit = ModuleNameString.ToEnum(s1);
  665. else if (param[0] is ModuleName mod)
  666. unit = mod;
  667. else
  668. throw new ArgumentException("Argument error");
  669. bool isUp = true;
  670. if (param.Length > 1)
  671. {
  672. isUp = (bool) param[1];
  673. }
  674. if (isUp)
  675. {
  676. if (!_efem.SetPinUp(unit))
  677. return false;
  678. }
  679. else
  680. {
  681. if (!_efem.SetPinDown(unit))
  682. return false;
  683. }
  684. return true;
  685. }
  686. private bool fnAlign(object[] param)
  687. {
  688. // module
  689. ModuleName unit = ModuleName.EFEM;
  690. if (param[0] is string s1)
  691. unit = ModuleNameString.ToEnum(s1);
  692. else if (param[0] is ModuleName mod)
  693. unit = mod;
  694. else
  695. throw new ArgumentException("Argument error");
  696. // wafer size
  697. WaferSize ws1 = WaferSize.WS0;
  698. if (param[1] is string s2)
  699. {
  700. if (Enum.TryParse(s2, out WaferSize p5))
  701. ws1 = p5;
  702. }
  703. else if (param[1] is WaferSize p6)
  704. {
  705. ws1 = p6;
  706. }
  707. if (!_efem.Align(unit, 1000, ws1))
  708. return false;
  709. return true;
  710. }
  711. private bool fnMap(object[] param)
  712. {
  713. // module
  714. ModuleName unit = ModuleName.EFEM;
  715. if (param[0] is string s1)
  716. unit = ModuleNameString.ToEnum(s1);
  717. else if (param[0] is ModuleName mod)
  718. unit = mod;
  719. else
  720. throw new ArgumentException("Argument error");
  721. if (!_efem.Map(unit))
  722. return false;
  723. return true;
  724. }
  725. private bool fnGrip(object[] param)
  726. {
  727. Hand arm = (Hand)Enum.Parse(typeof(Hand), (string)param[0]);
  728. if (!_efem.Grip(arm, true))
  729. return false;
  730. return true;
  731. }
  732. private bool fnUngrip(object[] param)
  733. {
  734. Hand arm = (Hand)Enum.Parse(typeof(Hand), (string)param[0]);
  735. if (!_efem.Grip(arm, false))
  736. return false;
  737. return true;
  738. }
  739. public bool IsIdle
  740. {
  741. get { return fsm.State == (int)STATE.Idle; }
  742. }
  743. public bool IsError
  744. {
  745. get { return fsm.State == (int)STATE.Error; }
  746. }
  747. public bool IsInit
  748. {
  749. get { return fsm.State == (int)STATE.Unknown || fsm.State == (int)STATE.Init; }
  750. }
  751. public bool IsBusy
  752. {
  753. get { return !IsInit && !IsError && !IsIdle; }
  754. }
  755. public bool IsOnline { get; internal set; }
  756. public int Invoke(string function, params object[] args)
  757. {
  758. switch (function)
  759. {
  760. case "Home":
  761. CheckToPostMessage((int)MSG.HomeAll);
  762. return (int)MSG.HomeAll;
  763. }
  764. return (int)FSM_MSG.NONE;
  765. }
  766. public bool CheckAcked(int msg)
  767. {
  768. return fsm.CheckExecuted(msg);
  769. }
  770. internal void InvokeReset()
  771. {
  772. if (fsm.State == (int)STATE.Error)
  773. {
  774. PostMsg((int)MSG.Recover);
  775. }
  776. LiftDone = true;
  777. foreach (var loadportEntity in _lpms)
  778. {
  779. if (loadportEntity.IsError)
  780. loadportEntity.PostMsg(LoadPortModule.MSG.Reset);
  781. }
  782. }
  783. public int InvokeAlign(string module, float time)
  784. {
  785. if (CheckToPostMessage((int)MSG.Align, module, time))
  786. return (int)MSG.Align;
  787. return (int)FSM_MSG.NONE;
  788. }
  789. public int InvokeLiftDown(string module)
  790. {
  791. if (CheckToPostMessage((int)MSG.Lift, module, false))
  792. return (int)MSG.Lift;
  793. return (int)FSM_MSG.NONE;
  794. }
  795. public void SetLiftDown(ModuleName module)
  796. {
  797. LOG.Info($"{module},Cooling,Lift down action");
  798. LiftDone = false;
  799. _efem.SetPinDown(module);
  800. }
  801. public void SetLiftDownDone()
  802. {
  803. LOG.Info("Cooling,Lift down action complete");
  804. LiftDone = true;
  805. }
  806. public int InvokePick(ModuleName source, int slot, Hand hand, WaferSize size)
  807. {
  808. if (CheckToPostMessage((int)MSG.Pick, source, slot, hand, size))
  809. return (int)MSG.Pick;
  810. return (int)FSM_MSG.NONE;
  811. }
  812. public int InvokeGoto(ModuleName source, int slot)
  813. {
  814. if (CheckToPostMessage((int)MSG.Goto, source, slot))
  815. return (int)MSG.Goto;
  816. return (int)FSM_MSG.NONE;
  817. }
  818. public int InvokePlace(ModuleName target, int slot, Hand hand, WaferSize size)
  819. {
  820. if (CheckToPostMessage((int)MSG.Place, target, slot, hand, size))
  821. return (int)MSG.Place;
  822. return (int)FSM_MSG.NONE;
  823. }
  824. public int InvokePickAndPlace(ModuleName targetModule, Hand pickHand, int pickSlot, Hand placeHand, int placeSlot, WaferSize size)
  825. {
  826. if (CheckToPostMessage((int)MSG.PickAndPlace, targetModule, pickSlot, pickHand, placeHand, placeSlot, size))
  827. return (int)MSG.PickAndPlace;
  828. return (int)FSM_MSG.NONE;
  829. }
  830. public int InvokeMap(string target)
  831. {
  832. if (CheckToPostMessage((int)MSG.Map, target))
  833. return (int)MSG.Map;
  834. return (int)FSM_MSG.NONE;
  835. }
  836. public bool IsPrepareTransferReady(ModuleName module, EnumTransferType type, int slot)
  837. {
  838. if (type == EnumTransferType.Pick)
  839. {
  840. //需要补充:判断LP 放好了,而且已经map过。
  841. return _efem[module].HasCassette && _efem[module].IsMapped;
  842. }
  843. else if (type == EnumTransferType.Place)
  844. {
  845. //需要补充:判断LP 放好了,而且已经map过。
  846. return _efem[module].HasCassette && _efem[module].IsMapped;
  847. }
  848. return false;
  849. }
  850. internal bool CheckReadyRunNewJob(ModuleName module)
  851. {
  852. //???
  853. return true;
  854. }
  855. internal bool CheckReadyTransfer(ModuleName module)
  856. {
  857. return _efem[module].HasCassette && _efem[module].IsMapped;
  858. }
  859. internal bool CheckPlaced(ModuleName module)
  860. {
  861. return _efem[module].HasCassette;
  862. }
  863. internal void NoteJobStart(ModuleName module)
  864. {
  865. _efem[module].NoteJobStart();
  866. }
  867. internal void NoteJobComplete(ModuleName module)
  868. {
  869. _efem[module].NoteJobComplete();
  870. }
  871. }
  872. }