EfemEntity.cs 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337
  1. using System;
  2. using System.Diagnostics;
  3. using System.Collections.Generic;
  4. using Aitex.Core.Common;
  5. using Aitex.Core.RT.DataCenter;
  6. using Aitex.Core.RT.Event;
  7. using Aitex.Core.RT.Fsm;
  8. using Aitex.Core.RT.OperationCenter;
  9. using Aitex.Core.RT.SCCore;
  10. using Aitex.Core.Utilities;
  11. using Aitex.Core.Util;
  12. using Aitex.Core.RT.Log;
  13. using Aitex.Sorter.Common;
  14. using MECF.Framework.Common.Equipment;
  15. using MECF.Framework.Common.Schedulers;
  16. using MECF.Framework.Common.SubstrateTrackings;
  17. using CyberX8_Core;
  18. using CyberX8_RT;
  19. using CyberX8_RT.Devices;
  20. using CyberX8_RT.Devices.YASKAWA;
  21. using CyberX8_RT.Devices.EFEM;
  22. using CyberX8_RT.Modules.LPs;
  23. using CyberX8_RT.Modules.EFEM;
  24. using System.Reflection;
  25. using CyberX8_RT.Modules.Transporter;
  26. using MECF.Framework.Common.Alarm;
  27. using MECF.Framework.Common.CommonData;
  28. using CyberX8_RT.Modules.Loader;
  29. namespace CyberX8_RT.Modules
  30. {
  31. class EfemEntity : Entity, IEntity, IModuleEntity
  32. {
  33. //private int _bigWafer = 0;
  34. //private int _midWafer = 0;
  35. //private int _smallWafer = 0;
  36. private bool _isVacuume = false;
  37. public enum STATE
  38. {
  39. Unknown, // 0
  40. Initializing, // 1
  41. Idle, // 2
  42. Error, // 3
  43. Picking, // 4
  44. Placing, // 5
  45. Aligning, // 6
  46. Mapping, // 7
  47. Init, // 8
  48. Orgshing, // 9
  49. Lifting, // 10
  50. InitingAL, // 11
  51. InitingRB, // 12
  52. Extending, // 13
  53. Retracting, // 14
  54. //SettingLamp, // 15
  55. Swapping,
  56. Gotoing,
  57. Gripping,
  58. Ungripping,
  59. Fliping,
  60. Vacuuming,
  61. Retrying,
  62. ConfirmCompleting,
  63. ErrorPicking,
  64. ErrorPlacing,
  65. RobotCycleing
  66. }
  67. public enum MSG
  68. {
  69. HomeAll, // 0
  70. Pick, // 1
  71. Place, // 2
  72. Align, // 3
  73. ActionDone, // 4
  74. MoveCmd, // 6
  75. Recover, // 8
  76. Goto, // 9
  77. Error, // 10
  78. Online, // 11
  79. CommReady, // 12
  80. Lift, // 13
  81. HomeAL, // 14
  82. HomeRB, // 15
  83. Extend, // 16
  84. Retract, // 17
  85. PMLiftPinUp, // 18
  86. PMLiftPinDown, // 19
  87. TurnOffBuzzer,
  88. Abort,
  89. GotoMap,
  90. Map,
  91. ToInit,
  92. Cool,
  93. Swap,
  94. Grip,
  95. Ungrip,
  96. Flip,
  97. LiftActionDone,
  98. Offline,
  99. SetRobotSpeed,
  100. MapDummy,
  101. Vacuum,
  102. CloseBuzzer,
  103. RobotPowerOn,
  104. Retry,
  105. ConfirmComplete,
  106. BackroundCmd=999,
  107. Load,
  108. Unload,
  109. Dock,
  110. Undock,
  111. Clamp,
  112. Unclamp,
  113. ReadCarrierId,
  114. WriteCarrierID,
  115. ReadTagData,
  116. WriteTagData,
  117. RobotCycle
  118. }
  119. public enum EfemType
  120. {
  121. FutureEfem = 1,
  122. SunWayEFEM =2
  123. }
  124. public bool IsIdle
  125. {
  126. get { return fsm.State == (int)STATE.Idle; }
  127. }
  128. public bool IsError
  129. {
  130. get { return fsm.State == (int)STATE.Error; }
  131. }
  132. public bool IsInit
  133. {
  134. get { return fsm.State == (int)STATE.Unknown || fsm.State == (int)STATE.Init; }
  135. }
  136. public bool IsBusy
  137. {
  138. get { return !IsInit && !IsError && !IsIdle; }
  139. }
  140. public bool IsAuto { get; } = true;
  141. /// <summary>
  142. /// 是否为工程模式
  143. /// </summary>
  144. public bool IsEngineering { get; } = false;
  145. /// <summary>
  146. /// 是否为产品模式
  147. /// </summary>
  148. public bool IsProduction { get; } = true;
  149. /// <summary>
  150. /// 模块名称
  151. /// </summary>
  152. public ModuleName Module { get; private set; }
  153. public bool IsHomed
  154. {
  155. get { return _isHomed; }
  156. }
  157. public bool IsOnline { get; internal set; }
  158. public bool IsDisable { get; internal set; }
  159. public RState RobotStatus
  160. {
  161. get
  162. {
  163. if (_efem.Status != RState.Running)
  164. {
  165. if (_robotWatch.ElapsedMilliseconds < 200)
  166. return RState.Running;
  167. else
  168. return _efem.Status;
  169. }
  170. else
  171. return RState.Running;
  172. }
  173. }
  174. public bool Check(int msg, out string reason, params object[] args)
  175. {
  176. throw new NotImplementedException();
  177. }
  178. // Fields
  179. private readonly string Name;
  180. private readonly EfemBase _efem;
  181. private readonly LoadPortModule[] _lpms = new LoadPortModule[3];
  182. private readonly DummyDevice[] _dummies = new DummyDevice[2];
  183. private readonly EfemType _efemType;
  184. public EfemBase EfemDevice => _efem;
  185. public EfemType EFEMType => _efemType;
  186. // routine
  187. private readonly EfemPickRoutine _pickRoutine;
  188. private readonly EfemPlaceRoutine _placeRoutine;
  189. private readonly EfemSwapRoutine _swapRoutine;
  190. private readonly EfemHomeRoutine _homeRoutine;
  191. private readonly EFEMAlignRoutine _alignRoutine;
  192. private readonly EfemMapDummyRoutine _mapDummyRoutine;
  193. private readonly EfemRobotMapRoutine _robotMapRoutine;
  194. private readonly EfemVacuumRoutine _vacuumRoutine;
  195. private readonly CycleRobotCycleNewRoutine _cycleRobotCycleRoutine;
  196. private string LiftMessage;
  197. private Stopwatch _robotWatch = new Stopwatch();
  198. private R_TRIG _robotIdleTrigger = new R_TRIG();
  199. private bool _isHomed = false;
  200. private EfemAutoMessageProcessor _autoMessageProcessor;
  201. private STATE _errorPreState;
  202. private int _currentCycleTimes;
  203. // Constructor
  204. public EfemEntity()
  205. {
  206. Module = ModuleName.EFEM;
  207. Name = ModuleName.EFEM.ToString();
  208. InitFsmMap();
  209. _efemType = (EfemType)SC.GetValue<int>($"EFEM.EfemType");
  210. _efem = new SunWayRobot();
  211. _homeRoutine = new EfemHomeRoutine(_efem);
  212. _pickRoutine = new EfemPickRoutine(_efem);
  213. _placeRoutine = new EfemPlaceRoutine(_efem);
  214. _swapRoutine = new EfemSwapRoutine(_efem);
  215. _alignRoutine = new EFEMAlignRoutine(_efem);
  216. _mapDummyRoutine = new EfemMapDummyRoutine(_efem);
  217. _vacuumRoutine = new EfemVacuumRoutine(_efem);
  218. _cycleRobotCycleRoutine = new CycleRobotCycleNewRoutine(_efem);
  219. _autoMessageProcessor =new EfemAutoMessageProcessor(_efem);
  220. }
  221. public LoadPortModule GetLoadportModule(int lpNumber)
  222. {
  223. if (lpNumber < 0|| _lpms.Length<=lpNumber)
  224. {
  225. return null;
  226. }
  227. return _lpms[lpNumber];
  228. }
  229. public DummyDevice GetDummyDevice(int dummyNumber)
  230. {
  231. if (dummyNumber < 0||_dummies.Length<=dummyNumber)
  232. {
  233. return null;
  234. }
  235. return _dummies[dummyNumber];
  236. }
  237. protected override bool Init()
  238. {
  239. _lpms[0] = new LoadPortModule(ModuleName.LP1, _efem);
  240. _lpms[1] = new LoadPortModule(ModuleName.LP2, _efem);
  241. _lpms[2] = new LoadPortModule(ModuleName.LP3, _efem);
  242. _dummies[0] = new DummyDevice(ModuleName.Dummy1);
  243. _dummies[1] = new DummyDevice(ModuleName.Dummy2);
  244. _lpms[0].Initialize();
  245. _lpms[1].Initialize();
  246. _lpms[2].Initialize();
  247. OP.Subscribe($"{ModuleName.EFEM}.{EfemOperation.Home}", (cmd, args) => { PostMsg(MSG.HomeAll); return true; });
  248. OP.Subscribe($"{ModuleName.EFEM}.{EfemOperation.RobotCycle}", (cmd, args) => {
  249. PostMsg(MSG.RobotCycle,args); return true; });
  250. OP.Subscribe($"{ModuleName.EFEM}.{EfemOperation.ClearError}", (cmd, args) => { PostMsg(MSG.Recover); return true; });
  251. OP.Subscribe($"{ModuleName.EFEM}.{EfemOperation.TurnOffBuzzer}", (cmd, args) => { PostMsg(MSG.CloseBuzzer); return true; });
  252. OP.Subscribe($"{ModuleName.EFEM}.Online", (cmd, args) =>
  253. {
  254. PostMsg(MSG.Online, args[0]); return true;
  255. });
  256. OP.Subscribe($"{ModuleName.EfemRobot}.{EfemOperation.Pick}", (cmd, args) => { CheckToPostMessage<STATE, MSG>(eEvent.ERR_EFEM_COMMON_FAILED,"EFEM",(int)MSG.Pick, args[0]); return true; });
  257. OP.Subscribe($"{ModuleName.EfemRobot}.{EfemOperation.Place}", (cmd, args) => { CheckToPostMessage<STATE, MSG>(eEvent.ERR_EFEM_COMMON_FAILED, "EFEM", (int)MSG.Place, args[0]); return true; });
  258. OP.Subscribe($"{ModuleName.EfemRobot}.{EfemOperation.Swap}", (cmd, args) => { PostMsg(MSG.Swap, args[0]); return true; });
  259. OP.Subscribe($"{ModuleName.EfemRobot}.{EfemOperation.DummyMap}", (cmd, args) => { CheckToPostMessage<STATE, MSG>(eEvent.ERR_EFEM_COMMON_FAILED, "EFEM", (int)MSG.MapDummy); return true; });
  260. OP.Subscribe($"{ModuleName.EfemRobot}.{EfemOperation.Speed}", (cmd, args) => {
  261. return _efem.SetRobotSpeed(ModuleName.EfemRobot, (int)args[0]); });
  262. OP.Subscribe($"{ModuleName.EfemRobot}.{EfemOperation.Vacuum}", (cmd, args) => {
  263. return _efem.Vacuum(ModuleName.EfemRobot, (bool)args[1]); });
  264. OP.Subscribe($"{ModuleName.EfemRobot}.{EfemOperation.PowerOn}", (cmd, args) => {
  265. return _efem.RobotPowerOn(ModuleName.EfemRobot, (bool)args[0]); });
  266. OP.Subscribe($"{ModuleName.EfemRobot}.{EfemOperation.Abort}", (cmd, args) => { PostMsg(MSG.Abort); return true; });
  267. OP.Subscribe($"{ModuleName.EfemRobot}.{EfemOperation.Home}", (cmd, args) => { PostMsg(MSG.HomeRB); return true; });
  268. OP.Subscribe($"{ModuleName.EfemRobot}.{EfemOperation.Grip}", (cmd, args) =>
  269. {
  270. bool isGrip = ((string)args[0]).ToLower() == "on";
  271. PostMsg(isGrip ? MSG.Grip : MSG.Ungrip, args[1]);
  272. return true;
  273. });
  274. //OP.Subscribe($"{ModuleName.EfemRobot}.{EfemOperation.Flip}", (cmd, args) => { PostMsg(MSG.Flip, args[0]); return true; });
  275. OP.Subscribe($"{ModuleName.Aligner1}.{EfemOperation.Home}", (cmd, args) => { PostMsg(MSG.HomeAL, ModuleName.Aligner1); return true; });
  276. OP.Subscribe($"{ModuleName.Aligner1}.{EfemOperation.Align}", (cmd, args) => { CheckToPostMessage<STATE,MSG>(eEvent.ERR_EFEM_COMMON_FAILED,ModuleName.EFEM.ToString(),(int)MSG.Align, ModuleName.Aligner1, args[0], args[1]); return true; });
  277. //OP.Subscribe($"{ModuleName.Aligner1}.{EfemOperation.Vacuum}", (cmd, args) => { CheckToPostMessage<STATE,MSG>(eEvent.ERR_EFEM_COMMON_FAILED,ModuleName.EFEM.ToString(),(int)MSG.Vacuum, args); return true; });
  278. OP.Subscribe($"{ModuleName.Aligner1}.{EfemOperation.Vacuum}", (cmd, args) => { return VacuumAction(args); });
  279. DATA.Subscribe($"{Name}.FsmState", () => ((STATE)fsm.State).ToString(),SubscriptionAttribute.FLAG.IgnoreSaveDB);
  280. DATA.Subscribe($"{Name}.FsmPrevState", () => ((STATE)fsm.PrevState).ToString(), SubscriptionAttribute.FLAG.IgnoreSaveDB);
  281. DATA.Subscribe($"{Name}.FsmLastMessage", GetFsmLastMessage, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  282. DATA.Subscribe($"{Name}.RobotMoveAction", () => (_efem.TMRobotMoveInfo), SubscriptionAttribute.FLAG.IgnoreSaveDB);
  283. DATA.Subscribe($"{Name}.State", () => ((STATE)fsm.State).ToString(), SubscriptionAttribute.FLAG.IgnoreSaveDB);
  284. DATA.Subscribe($"{Name}.IsAlarm", () => IsError, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  285. DATA.Subscribe($"{Name}.IsInit", () => IsInit, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  286. DATA.Subscribe($"{Name}.IsIdle", () => IsIdle, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  287. DATA.Subscribe($"{Name}.IsBusy", () => IsBusy, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  288. DATA.Subscribe($"{Name}.IsOnline", () => IsOnline, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  289. DATA.Subscribe($"{Name}.IsHomed", () => _isHomed, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  290. DATA.Subscribe($"{Name}.RobotSpeed",()=>IsIdle?SC.GetValue<int>("EFEM.DefaultMoveSpeedInPercent"):0);
  291. DATA.Subscribe($"{Name}.CurrentRobotCycleTime",()=>_currentCycleTimes, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  292. _robotWatch.Restart();
  293. return true;
  294. }
  295. private void InitFsmMap()
  296. {
  297. fsm = new StateMachine<EfemEntity>("EFEM", (int)STATE.Unknown, 50);
  298. fsm.EnableRepeatedMsg(true);
  299. AnyStateTransition(FSM_MSG.TIMER, fnMonitor, FSM_STATE.SAME);
  300. AnyStateTransition(MSG.TurnOffBuzzer, fnTurnOffBuzzer, FSM_STATE.SAME);
  301. AnyStateTransition(MSG.Error, fnError, STATE.Error);
  302. AnyStateTransition(MSG.Online, fnOnline, FSM_STATE.SAME);
  303. //AnyStateTransition(MSG.Abort, fnAbortRobot, FSM_STATE.SAME);
  304. AnyStateTransition(MSG.ToInit, fnToInit, STATE.Init);
  305. AnyStateTransition(MSG.BackroundCmd, fnBackroundCommand, FSM_STATE.SAME);
  306. AnyStateTransition(MSG.CloseBuzzer, fnCloseBuzzer, FSM_STATE.SAME);
  307. Transition(STATE.Unknown,MSG.CommReady, fnCommReady, STATE.Init);
  308. //Error
  309. Transition(STATE.Error, MSG.Recover, fnRecover, STATE.Idle);
  310. // Home
  311. Transition(STATE.Unknown, MSG.HomeAll, fnHomeAll, STATE.Initializing);
  312. Transition(STATE.Init, MSG.HomeAll, fnHomeAll, STATE.Initializing);
  313. Transition(STATE.Idle, MSG.HomeAll, fnHomeAll, STATE.Initializing);
  314. Transition(STATE.Error, MSG.HomeAll, fnHomeAll, STATE.Initializing);
  315. Transition(STATE.Initializing, FSM_MSG.TIMER, fnHomingTimeout, STATE.Idle);
  316. // Home Robot
  317. Transition(STATE.Error, MSG.HomeRB, fnHomeRobot, STATE.InitingRB);
  318. Transition(STATE.Idle, MSG.HomeRB, fnHomeRobot, STATE.InitingRB);
  319. Transition(STATE.InitingRB, FSM_MSG.TIMER, fnHomingRobotTimeout, STATE.Idle);
  320. // Home Aligner
  321. Transition(STATE.Idle, MSG.HomeAL, fnHomeAligner, STATE.InitingAL);
  322. Transition(STATE.InitingAL, FSM_MSG.TIMER, fnHomingAlignTimeout, STATE.Idle);
  323. // Pick wafer
  324. Transition(STATE.Idle, MSG.Pick, FnStartPick, STATE.Picking);
  325. Transition(STATE.Picking, FSM_MSG.TIMER, FnPickTimeout, STATE.Idle);
  326. Transition(STATE.Picking, MSG.Abort, FnAbortPick, STATE.Idle);
  327. //Robot Cycle
  328. Transition(STATE.Idle, MSG.RobotCycle, FnStartRobotCycle, STATE.RobotCycleing);
  329. Transition(STATE.RobotCycleing, FSM_MSG.TIMER, FnRobotCycleTimeout, STATE.Idle);
  330. Transition(STATE.RobotCycleing, MSG.Abort, FnAbortRobotCycle, STATE.Idle);
  331. Transition(STATE.Error, MSG.Pick, FnErrorStartPick, STATE.ErrorPicking);
  332. Transition(STATE.ErrorPicking, FSM_MSG.TIMER, FnErrorPickTimeout, STATE.Error);
  333. Transition(STATE.ErrorPicking, MSG.Abort, FnErrorAbortPick, STATE.Error);
  334. // Place wafer
  335. Transition(STATE.Idle, MSG.Place, FnStartPlace, STATE.Placing);
  336. Transition(STATE.Placing, FSM_MSG.TIMER, FnPlaceTimeout, STATE.Idle);
  337. Transition(STATE.Placing, MSG.Abort, FnAbortPlace, STATE.Idle);
  338. Transition(STATE.Error, MSG.Place, FnErrorStartPlace, STATE.ErrorPlacing);
  339. Transition(STATE.ErrorPlacing, FSM_MSG.TIMER, FnErrorPlaceTimeout, STATE.Error);
  340. Transition(STATE.ErrorPlacing, MSG.Abort, FnErrorAbortPlace, STATE.Error);
  341. // Swap wafer with LL sequence
  342. Transition(STATE.Idle, MSG.Swap, FnStartSwap, STATE.Swapping);
  343. Transition(STATE.Swapping, FSM_MSG.TIMER, FnSwapTimeout, STATE.Idle);
  344. Transition(STATE.Swapping, MSG.Abort, FnAbortSwap, STATE.Idle);
  345. // Goto
  346. Transition(STATE.Idle, MSG.Goto, fnGoto, STATE.Gotoing);
  347. Transition(STATE.Gotoing, MSG.ActionDone, fnActionDone, STATE.Idle);
  348. // Map
  349. Transition(STATE.Idle, MSG.Map, fnMap, STATE.Mapping);
  350. Transition(STATE.Mapping, MSG.ActionDone, fnActionDone, STATE.Idle);
  351. // Grip
  352. Transition(STATE.Idle, MSG.Grip, fnGrip, STATE.Gripping);
  353. Transition(STATE.Gripping, MSG.ActionDone, fnActionDone, STATE.Idle);
  354. // Ungrip
  355. Transition(STATE.Idle, MSG.Ungrip, fnUngrip, STATE.Ungripping);
  356. Transition(STATE.Ungripping, MSG.ActionDone, fnActionDone, STATE.Idle);
  357. // Aligner
  358. Transition(STATE.Idle, MSG.Lift, fnLift, STATE.Lifting);
  359. //Transition(STATE.Lifting, MSG.LiftActionDone, fnActionDone, STATE.Idle);
  360. Transition(STATE.Lifting, FSM_MSG.TIMER, fnLiftTimeout, STATE.Idle);
  361. Transition(STATE.Idle, MSG.Align, fnAlign, STATE.Aligning);
  362. Transition(STATE.Aligning, FSM_MSG.TIMER, fnAlignTimeout, STATE.Idle);
  363. Transition(STATE.Aligning, MSG.ActionDone, fnActionDone, STATE.Idle);
  364. //MapDummy
  365. Transition(STATE.Idle, MSG.MapDummy, MapDummy, STATE.Mapping);
  366. Transition(STATE.Mapping, FSM_MSG.TIMER, MapDummyTimeout, STATE.Idle);
  367. //Vacuum
  368. //Transition(STATE.Init, MSG.Vacuum, VacuumAction, STATE.Vacuuming);
  369. //Transition(STATE.Idle, MSG.Vacuum, VacuumAction, STATE.Vacuuming);
  370. //Transition(STATE.Error, MSG.Vacuum, VacuumAction, STATE.Vacuuming);
  371. //Transition(STATE.Vacuuming, FSM_MSG.TIMER, VacuumActionTimeout, STATE.Idle);
  372. //Retry
  373. Transition(STATE.Error, MSG.Retry, NullFunc, STATE.Retrying);
  374. Transition(STATE.Retrying, FSM_MSG.TIMER, EfemRetry, STATE.Retrying);
  375. Transition(STATE.Retrying, MSG.Align, RetryAlign, STATE.Aligning);
  376. Transition(STATE.Retrying, MSG.Pick, RetryPick, STATE.Picking);
  377. Transition(STATE.Retrying, MSG.Place, RetryPlace, STATE.Placing);
  378. //ConfirmComplete
  379. Transition(STATE.Init, MSG.ConfirmComplete, ClearModuleAlarm, STATE.Init);
  380. Transition(STATE.Idle, MSG.ConfirmComplete, ClearModuleAlarm, STATE.Idle);
  381. Transition(STATE.Error, MSG.ConfirmComplete, NullFunc, STATE.ConfirmCompleting);
  382. Transition(STATE.ConfirmCompleting, FSM_MSG.TIMER, ConfirmComplete, STATE.ConfirmCompleting);
  383. Transition(STATE.ConfirmCompleting, MSG.Align, ConfirmAlign, STATE.Idle);
  384. Transition(STATE.ConfirmCompleting, MSG.Pick, ConfirmPickup, STATE.Idle);
  385. Transition(STATE.ConfirmCompleting, MSG.Place, ConfirmPlace, STATE.Idle);
  386. EnumLoop<STATE>.ForEach((item) => { fsm.MapState((int)item, item.ToString()); });
  387. EnumLoop<MSG>.ForEach((item) => { fsm.MapMessage((int)item, item.ToString()); });
  388. Running = true;
  389. }
  390. private bool fnCommReady(object[] param)
  391. {
  392. return true;
  393. }
  394. private bool fnCloseBuzzer(object[] param)
  395. {
  396. return _efem.CloseBuzzer();
  397. }
  398. private bool fnHomeAll(object[] param)
  399. {
  400. _isHomed = false;
  401. return _homeRoutine.Start(ModuleName.EFEM) == RState.Running;
  402. }
  403. private bool fnHomingTimeout(object[] param)
  404. {
  405. RState ret = _homeRoutine.Monitor();
  406. if (ret == RState.Failed || ret == RState.Timeout)
  407. {
  408. PostMsg(MSG.Error);
  409. return false;
  410. }
  411. bool result= ret == RState.End;
  412. if(result)
  413. {
  414. _isHomed= true;
  415. RecoverLPStatus();
  416. }
  417. return result;
  418. }
  419. private void RecoverLPStatus()
  420. {
  421. _lpms[0].PostMsg(LoadPortModule.MSG.EnterIdle);
  422. _lpms[1].PostMsg(LoadPortModule.MSG.EnterIdle);
  423. _lpms[2].PostMsg(LoadPortModule.MSG.EnterIdle);
  424. }
  425. private bool fnHomeRobot(object[] param)
  426. {
  427. if (_isHomed)
  428. {
  429. return _homeRoutine.Start(ModuleName.EfemRobot) == RState.Running;
  430. }
  431. else
  432. {
  433. return false;
  434. }
  435. }
  436. private bool fnHomingRobotTimeout(object[] param)
  437. {
  438. RState ret = _homeRoutine.Monitor();
  439. if (ret == RState.Failed || ret == RState.Timeout)
  440. {
  441. PostMsg(MSG.Error);
  442. return false;
  443. }
  444. bool result = ret == RState.End;
  445. if (result)
  446. {
  447. AlarmListManager.Instance.CheckModuleAlamAndRemove(Module.ToString(), STATE.Idle.ToString());
  448. }
  449. return result;
  450. }
  451. private bool fnHomeAligner(object[] param)
  452. {
  453. // module
  454. ModuleName unit = ModuleName.EFEM;
  455. if (param[0] is string s1)
  456. unit = ModuleNameString.ToEnum(s1);
  457. else if (param[0] is ModuleName mod)
  458. unit = mod;
  459. else
  460. throw new ArgumentException("Argument error");
  461. return _homeRoutine.Start(unit) == RState.Running;
  462. }
  463. private bool fnHomingAlignTimeout(object[] param)
  464. {
  465. RState ret = _homeRoutine.Monitor();
  466. if (ret == RState.Failed || ret == RState.Timeout)
  467. {
  468. PostMsg(MSG.Error);
  469. return false;
  470. }
  471. bool result = ret == RState.End;
  472. if (result)
  473. {
  474. AlarmListManager.Instance.CheckModuleAlamAndRemove(Module.ToString(), STATE.Idle.ToString());
  475. }
  476. return result;
  477. }
  478. private bool fnActionDone(object[] param)
  479. {
  480. return false;
  481. }
  482. public bool CheckToPostMessage(int msg, params object[] args)
  483. {
  484. if (!fsm.FindTransition(fsm.State, msg))
  485. {
  486. LOG.Write(eEvent.WARN_EFEM_COMMON_WARN, ModuleName.EFEM, $"{Name} is in {(STATE)fsm.State} state,can not do {(MSG)msg}");
  487. return false;
  488. }
  489. Running = true;
  490. fsm.PostMsg(msg, args);
  491. return true;
  492. }
  493. private bool fnMonitor(object[] param)
  494. {
  495. if (_isVacuume)
  496. {
  497. VacuumActionTimeout();
  498. _isVacuume = false;
  499. }
  500. // robot idle check
  501. _robotIdleTrigger.CLK = _efem.Status != RState.Running;
  502. if (_robotIdleTrigger.Q)
  503. {
  504. _robotWatch.Restart();
  505. LOG.WriteLog(eEvent.EV_EFEM_ROBOT, Module.ToString(), $"robot status changed to {_efem.Status}");
  506. }
  507. _autoMessageProcessor.Monitor();
  508. return true;
  509. }
  510. private bool fnOnline(object[] param)
  511. {
  512. bool bOnlineFlag = (bool)param[0];
  513. if (_efem is EfemBase efem)
  514. {
  515. efem.SetOnline(bOnlineFlag);
  516. }
  517. IsOnline = bOnlineFlag;
  518. return true;
  519. }
  520. private string GetFsmLastMessage()
  521. {
  522. int msg = fsm.LastMsg;
  523. if (msg >= (int)MSG.HomeAll && msg <= (int)MSG.Error)
  524. return ((MSG)msg).ToString();
  525. if (msg == (int)FSM_MSG.TIMER)
  526. return "Timer";
  527. return msg.ToString();
  528. }
  529. private bool fnError(object[] param)
  530. {
  531. _errorPreState = (STATE)fsm.State;
  532. string error = (param != null && param.Length != 0) ? param[0].ToString() : "";
  533. if (Singleton<RouteManager>.Instance.IsAutoRunning)
  534. {
  535. int msg = 0;
  536. if (_errorPreState == STATE.Picking)
  537. {
  538. msg = (int)MSG.Pick;
  539. }
  540. else if (_errorPreState == STATE.Aligning)
  541. {
  542. msg= (int)MSG.Align;
  543. }
  544. else if (_errorPreState == STATE.Placing)
  545. {
  546. msg = (int)MSG.Place;
  547. }
  548. else
  549. {
  550. error = $"{error}\r\n Plase Home Robot back to idle state";
  551. }
  552. AlarmList alarmList = new AlarmList(Module.ToString(), ((STATE)fsm.State).ToString(), msg,
  553. error, 0, (int)AlarmType.Error);
  554. AlarmListManager.Instance.AddAlarm(alarmList);
  555. }
  556. return true;
  557. }
  558. private bool fnToInit(object[] param)
  559. {
  560. return true;
  561. }
  562. private bool fnRecover(object[] param)
  563. {
  564. bool result=_efem.ClearError();
  565. if (result)
  566. {
  567. PostMsg(MSG.ToInit);
  568. }
  569. return result;
  570. }
  571. private bool fnAbortRobot(object[] param)
  572. {
  573. //_efem.ExecuteAction();
  574. return true;
  575. }
  576. private bool fnBackroundCommand(object[] param)
  577. {
  578. _autoMessageProcessor.SendAutoCommandMessage(param);
  579. return true;
  580. }
  581. private bool fnRobotPowerOn(object[] param)
  582. {
  583. return _efem.RobotPowerOn(ModuleName.EfemRobot, (bool)param[0]);
  584. }
  585. private bool fnSetLED(object[] param)
  586. {
  587. LightType light = (LightType)param[0];
  588. LightStatus st = (LightStatus)param[1];
  589. return _efem.SetLamp(light, st);
  590. }
  591. private bool fnTurnOffBuzzer(object[] param)
  592. {
  593. return false;
  594. }
  595. private bool FnStartPick(object[] param)
  596. {
  597. return _pickRoutine.Start(param) == RState.Running;
  598. }
  599. private bool FnStartRobotCycle(object[] param)
  600. {
  601. return _cycleRobotCycleRoutine.Start(param) == RState.Running;
  602. }
  603. private bool FnErrorStartPick(object[] param)
  604. {
  605. if (!_isHomed)
  606. {
  607. LOG.WriteLog(eEvent.ERR_EFEM_ROBOT, Module.ToString(), "EFEM is not homed");
  608. return false;
  609. }
  610. _efem.Reset();
  611. return _pickRoutine.Start(param) == RState.Running;
  612. }
  613. /// <summary>
  614. /// Retry Pick
  615. /// </summary>
  616. /// <param name="param"></param>
  617. /// <returns></returns>
  618. private bool RetryPick(object[] param)
  619. {
  620. int stepIndex = (int)param[0];
  621. return _pickRoutine.Retry(stepIndex) == RState.Running;
  622. }
  623. private bool FnPickTimeout(object[] param)
  624. {
  625. RState ret = _pickRoutine.Monitor();
  626. if (ret == RState.Failed || ret == RState.Timeout)
  627. {
  628. PostMsg(MSG.Error,_pickRoutine.ErrorMsg);
  629. return false;
  630. }
  631. if (ret == RState.End)
  632. {
  633. AlarmListManager.Instance.CheckModuleAlamAndRemove(Module.ToString(), STATE.Picking.ToString());
  634. }
  635. return ret == RState.End;
  636. }
  637. private bool FnRobotCycleTimeout(object[] param)
  638. {
  639. RState ret = _cycleRobotCycleRoutine.Monitor();
  640. if (ret == RState.Failed || ret == RState.Timeout)
  641. {
  642. PostMsg(MSG.Error);
  643. return false;
  644. }
  645. _currentCycleTimes = _cycleRobotCycleRoutine.GetCurrentCycle();
  646. return ret == RState.End;
  647. }
  648. private bool FnErrorPickTimeout(object[] param)
  649. {
  650. RState ret = _pickRoutine.Monitor();
  651. if (ret == RState.Failed || ret == RState.Timeout)
  652. {
  653. PostMsg(MSG.Error, _pickRoutine.ErrorMsg);
  654. return false;
  655. }
  656. return ret == RState.End;
  657. }
  658. /// <summary>
  659. /// 确认Pick是否完成
  660. /// </summary>
  661. /// <param name="param"></param>
  662. /// <returns></returns>
  663. private bool ConfirmPickup(object[] param)
  664. {
  665. int stepIdex = (int)param[0];
  666. bool result = _pickRoutine.CheckCompleteCondition(stepIdex);
  667. if (!result)
  668. {
  669. PostMsg(MSG.Error,_pickRoutine.ErrorMsg);
  670. }
  671. else
  672. {
  673. if (Singleton<RouteManager>.Instance.IsAutoRunning)
  674. {
  675. AlarmListManager.Instance.CheckModuleAlamAndRemove(Module.ToString(), STATE.Picking.ToString());
  676. }
  677. }
  678. return result;
  679. }
  680. private bool FnAbortPick(object[] param)
  681. {
  682. _pickRoutine.Abort();
  683. return true;
  684. }
  685. private bool FnAbortRobotCycle(object[] param)
  686. {
  687. _cycleRobotCycleRoutine.Abort();
  688. return true;
  689. }
  690. private bool FnErrorAbortPick(object[] param)
  691. {
  692. _pickRoutine.Abort();
  693. return true;
  694. }
  695. private bool FnStartPlace(object[] param)
  696. {
  697. return _placeRoutine.Start(param) == RState.Running;
  698. }
  699. private bool FnErrorStartPlace(object[] param)
  700. {
  701. if(!_isHomed)
  702. {
  703. LOG.WriteLog(eEvent.ERR_EFEM_ROBOT, Module.ToString(), "EFEM is not homed");
  704. return false;
  705. }
  706. _efem.Reset();
  707. return _placeRoutine.Start(param) == RState.Running;
  708. }
  709. /// <summary>
  710. /// Retry Place
  711. /// </summary>
  712. /// <param name="param"></param>
  713. /// <returns></returns>
  714. private bool RetryPlace(object[] param)
  715. {
  716. int stepIndex = (int)param[0];
  717. return _placeRoutine.Retry(stepIndex) == RState.Running;
  718. }
  719. private bool FnPlaceTimeout(object[] param)
  720. {
  721. RState ret = _placeRoutine.Monitor();
  722. if (ret == RState.Failed || ret == RState.Timeout)
  723. {
  724. PostMsg(MSG.Error,_placeRoutine.ErrorMsg);
  725. return false;
  726. }
  727. if (ret == RState.End)
  728. {
  729. AlarmListManager.Instance.CheckModuleAlamAndRemove(Module.ToString(), STATE.Placing.ToString());
  730. }
  731. return ret == RState.End;
  732. }
  733. private bool FnErrorPlaceTimeout(object[] param)
  734. {
  735. RState ret = _placeRoutine.Monitor();
  736. if (ret == RState.Failed || ret == RState.Timeout)
  737. {
  738. PostMsg(MSG.Error, _placeRoutine.ErrorMsg);
  739. return false;
  740. }
  741. return ret == RState.End;
  742. }
  743. /// <summary>
  744. /// 确认Place是否完成
  745. /// </summary>
  746. /// <param name="param"></param>
  747. /// <returns></returns>
  748. private bool ConfirmPlace(object[] param)
  749. {
  750. int stepIdex = (int)param[0];
  751. bool result = _placeRoutine.CheckCompleteCondition(stepIdex);
  752. if (!result)
  753. {
  754. PostMsg(MSG.Error, _placeRoutine.ErrorMsg);
  755. }
  756. else
  757. {
  758. if (Singleton<RouteManager>.Instance.IsAutoRunning)
  759. {
  760. AlarmListManager.Instance.CheckModuleAlamAndRemove(Module.ToString(), STATE.Picking.ToString());
  761. }
  762. }
  763. return result;
  764. }
  765. private bool FnAbortPlace(object[] param)
  766. {
  767. _placeRoutine.Abort();
  768. return true;
  769. }
  770. private bool FnErrorAbortPlace(object[] param)
  771. {
  772. _placeRoutine.Abort();
  773. return true;
  774. }
  775. private bool FnStartSwap(object[] param)
  776. {
  777. return _swapRoutine.Start(param) == RState.Running;
  778. }
  779. private bool FnSwapTimeout(object[] param)
  780. {
  781. RState ret = _swapRoutine.Monitor();
  782. if (ret == RState.Failed || ret == RState.Timeout)
  783. {
  784. PostMsg(MSG.Error);
  785. return false;
  786. }
  787. return ret == RState.End;
  788. }
  789. private bool FnAbortSwap(object[] param)
  790. {
  791. _swapRoutine.Abort();
  792. return true;
  793. }
  794. private bool fnGoto(object[] param)
  795. {
  796. // module
  797. ModuleName unit = ModuleName.EFEM;
  798. if (param[0] is string s1)
  799. unit = ModuleNameString.ToEnum(s1);
  800. else if (param[0] is ModuleName mod)
  801. unit = mod;
  802. else
  803. throw new ArgumentException("Argument error");
  804. _efem.Goto(unit, Hand.Blade1);
  805. return true;
  806. }
  807. private bool fnLift(object[] param)
  808. {
  809. // module
  810. ModuleName unit = ModuleName.EFEM;
  811. if (param[0] is string s1)
  812. unit = ModuleNameString.ToEnum(s1);
  813. else if (param[0] is ModuleName mod)
  814. unit = mod;
  815. else
  816. throw new ArgumentException("Argument error");
  817. bool isUp = true;
  818. if (param.Length > 1)
  819. {
  820. isUp = (bool) param[1];
  821. }
  822. if (isUp)
  823. {
  824. if (!_efem.SetPinUp(unit))
  825. return false;
  826. }
  827. else
  828. {
  829. if (!_efem.SetPinDown(unit))
  830. return false;
  831. }
  832. LiftMessage = isUp ? "Up" : "Down";
  833. return true;
  834. }
  835. private bool fnLiftTimeout(object[] param)
  836. {
  837. if (LiftMessage == "Up")
  838. {
  839. return _efem.LiftIsDown == false && _efem.LiftIsUp == true;
  840. }
  841. else if (LiftMessage == "Down")
  842. {
  843. return _efem.LiftIsDown == true && _efem.LiftIsUp == false;
  844. }
  845. return false;
  846. }
  847. private bool fnAlign(object[] param)
  848. {
  849. return _alignRoutine.Start(param) == RState.Running;
  850. }
  851. private bool fnAlignTimeout(object[] param)
  852. {
  853. RState ret = _alignRoutine.Monitor();
  854. if (ret == RState.Failed || ret == RState.Timeout)
  855. {
  856. PostMsg(MSG.Error,_alignRoutine.ErrorMsg);
  857. return false;
  858. }
  859. if (ret == RState.End)
  860. {
  861. AlarmListManager.Instance.CheckModuleAlamAndRemove(Module.ToString(), STATE.Aligning.ToString());
  862. }
  863. return ret == RState.End;
  864. }
  865. /// <summary>
  866. /// Retry Align
  867. /// </summary>
  868. /// <param name="param"></param>
  869. /// <returns></returns>
  870. private bool RetryAlign(object[] param)
  871. {
  872. int stepIndex = (int)param[0];
  873. return _alignRoutine.Retry(stepIndex) == RState.Running;
  874. }
  875. /// <summary>
  876. /// 确认Align是否完成
  877. /// </summary>
  878. /// <param name="param"></param>
  879. /// <returns></returns>
  880. private bool ConfirmAlign(object[] param)
  881. {
  882. int stepIdex = (int)param[0];
  883. bool result = _alignRoutine.CheckCompleteCondition(stepIdex);
  884. if (!result)
  885. {
  886. PostMsg(MSG.Error, _alignRoutine.ErrorMsg);
  887. }
  888. else
  889. {
  890. if (Singleton<RouteManager>.Instance.IsAutoRunning)
  891. {
  892. AlarmListManager.Instance.CheckModuleAlamAndRemove(Module.ToString(), STATE.Aligning.ToString());
  893. }
  894. }
  895. return result;
  896. }
  897. private bool MapDummyTimeout(object[] param)
  898. {
  899. RState ret = _mapDummyRoutine.Monitor();
  900. if (ret == RState.Failed || ret == RState.Timeout)
  901. {
  902. PostMsg(MSG.Error);
  903. return false;
  904. }
  905. return ret == RState.End;
  906. }
  907. private bool VacuumActionTimeout()
  908. {
  909. RState ret = _vacuumRoutine.Monitor();
  910. if (ret == RState.Failed || ret == RState.Timeout)
  911. {
  912. LOG.Write(eEvent.ERR_EFEM_COMMON_FAILED, ModuleName.EFEM, "Vacuum");
  913. return false;
  914. }
  915. return ret == RState.End;
  916. }
  917. private bool fnMap(object[] param)
  918. {
  919. // module
  920. ModuleName unit = ModuleName.EFEM;
  921. if (param[0] is string s1)
  922. unit = ModuleNameString.ToEnum(s1);
  923. else if (param[0] is ModuleName mod)
  924. unit = mod;
  925. else
  926. throw new ArgumentException("Argument error");
  927. if (!_efem.Map(unit))
  928. return false;
  929. return true;
  930. }
  931. private bool MapDummy(object[] param)
  932. {
  933. return _mapDummyRoutine.Start()==RState.Running;
  934. }
  935. private bool VacuumAction(object[] param)
  936. {
  937. ModuleName vacuumModule = (ModuleName)param[0];
  938. bool vacuum=(bool)param[1];
  939. bool result = _vacuumRoutine.Start(vacuumModule, vacuum) == RState.Running;
  940. if (result)
  941. {
  942. _isVacuume = true;
  943. }
  944. return result;
  945. }
  946. private bool fnGrip(object[] param)
  947. {
  948. Hand arm = (Hand)Enum.Parse(typeof(Hand), (string)param[0]);
  949. if (!_efem.Grip(arm, true))
  950. return false;
  951. return true;
  952. }
  953. public int SendEfemAutoCommand(params object[] args)
  954. {
  955. if (CheckToPostMessage((int)MSG.BackroundCmd, args))
  956. return (int)MSG.BackroundCmd;
  957. return (int)FSM_MSG.NONE;
  958. }
  959. private bool fnUngrip(object[] param)
  960. {
  961. Hand arm = (Hand)Enum.Parse(typeof(Hand), (string)param[0]);
  962. if (!_efem.Grip(arm, false))
  963. return false;
  964. return true;
  965. }
  966. #region EfemRetry
  967. /// <summary>
  968. /// Retry
  969. /// </summary>
  970. /// <param name="param"></param>
  971. /// <returns></returns>
  972. private bool EfemRetry(object[] param)
  973. {
  974. AlarmList alarmList = AlarmListManager.Instance.GetAlarmListByModule(Module.ToString());
  975. if (alarmList != null)
  976. {
  977. CheckToPostMessage<STATE, MSG>(eEvent.ERR_EFEM_ROBOT, Module.ToString(), alarmList.ModuleCmd,
  978. alarmList.ModuleStep);
  979. }
  980. return false;
  981. }
  982. #endregion
  983. #region ConfirmComplete
  984. /// <summary>
  985. /// 确认是否完成
  986. /// </summary>
  987. /// <param name="param"></param>
  988. /// <returns></returns>
  989. private bool ConfirmComplete(object[] param)
  990. {
  991. AlarmList alarmList = AlarmListManager.Instance.GetAlarmListByModule(Module.ToString());
  992. if (alarmList != null)
  993. {
  994. if (alarmList.ModuleState == STATE.Picking.ToString())
  995. {
  996. CheckToPostMessage<STATE, MSG>(eEvent.ERR_EFEM_ROBOT, Module.ToString(), (int)MSG.Pick, alarmList.ModuleStep);
  997. }
  998. else if (alarmList.ModuleState == STATE.Placing.ToString())
  999. {
  1000. CheckToPostMessage<STATE, MSG>(eEvent.ERR_EFEM_ROBOT, Module.ToString(), (int)MSG.Place, alarmList.ModuleStep);
  1001. }
  1002. else if (alarmList.ModuleState == STATE.Aligning.ToString())
  1003. {
  1004. CheckToPostMessage<STATE, MSG>(eEvent.ERR_EFEM_ROBOT, Module.ToString(), (int)MSG.Align, alarmList.ModuleStep);
  1005. }
  1006. else
  1007. {
  1008. PostMsg(PUFSTATE.Error);
  1009. }
  1010. }
  1011. return false;
  1012. }
  1013. /// <summary>
  1014. /// 清除报警
  1015. /// </summary>
  1016. /// <param name="param"></param>
  1017. /// <returns></returns>
  1018. private bool ClearModuleAlarm(object[] param)
  1019. {
  1020. AlarmList alarmList = AlarmListManager.Instance.GetAlarmListByModule(Module.ToString());
  1021. if (alarmList != null)
  1022. {
  1023. AlarmListManager.Instance.CheckModuleAlamAndRemove(Module.ToString(), "");
  1024. }
  1025. return true;
  1026. }
  1027. #endregion
  1028. public int Invoke(string function, params object[] args)
  1029. {
  1030. switch (function)
  1031. {
  1032. case "HomeAll":
  1033. if (IsIdle)
  1034. {
  1035. return (int)FSM_MSG.NONE;
  1036. }
  1037. if (CheckToPostMessage((int)MSG.HomeAll))
  1038. {
  1039. return (int)MSG.HomeAll;
  1040. }
  1041. else
  1042. {
  1043. return (int)FSM_MSG.NONE;
  1044. }
  1045. case "Retry":
  1046. if (CheckToPostMessage<STATE, MSG>(eEvent.ERR_EFEM_ROBOT, Module.ToString(), (int)MSG.Retry, args))
  1047. {
  1048. return (int)MSG.Retry;
  1049. }
  1050. else
  1051. {
  1052. return (int)FSM_MSG.NONE;
  1053. }
  1054. case "ConfirmComplete":
  1055. if (CheckToPostMessage<STATE, MSG>(eEvent.ERR_EFEM_ROBOT, Module.ToString(), (int)MSG.ConfirmComplete, args))
  1056. {
  1057. return (int)MSG.ConfirmComplete;
  1058. }
  1059. else
  1060. {
  1061. return (int)FSM_MSG.NONE;
  1062. }
  1063. }
  1064. return (int)FSM_MSG.NONE;
  1065. }
  1066. public bool CheckAcked(int msg)
  1067. {
  1068. return fsm.CheckExecuted(msg);
  1069. }
  1070. internal void InvokeReset()
  1071. {
  1072. if (fsm.State == (int) STATE.Error)
  1073. {
  1074. PostMsg((int)MSG.Recover);
  1075. }
  1076. }
  1077. public int InvokeAlign(string module, int reserv, float time)
  1078. {
  1079. if (CheckToPostMessage((int)MSG.Align, module, reserv, time))
  1080. return (int)MSG.Align;
  1081. return (int)FSM_MSG.NONE;
  1082. }
  1083. public int InvokeLiftDown(string module)
  1084. {
  1085. if (CheckToPostMessage((int)MSG.Lift, module, false))
  1086. return (int)MSG.Lift;
  1087. return (int)FSM_MSG.NONE;
  1088. }
  1089. public int InvokePick(ModuleName source, int slot, Hand hand, WaferSize size)
  1090. {
  1091. if (CheckToPostMessage((int)MSG.Pick, source, slot, hand, size))
  1092. return (int)MSG.Pick;
  1093. return (int)FSM_MSG.NONE;
  1094. }
  1095. public int InvokeGoto(ModuleName source, int slot)
  1096. {
  1097. if (CheckToPostMessage((int)MSG.Goto, source, slot))
  1098. return (int)MSG.Goto;
  1099. return (int)FSM_MSG.NONE;
  1100. }
  1101. public int InvokePlace(ModuleName target, int slot, Hand hand, WaferSize size)
  1102. {
  1103. if (CheckToPostMessage((int)MSG.Place, target, slot, hand, size))
  1104. return (int)MSG.Place;
  1105. return (int)FSM_MSG.NONE;
  1106. }
  1107. public int InvokePickAndPlace(ModuleName targetModule, Hand pickHand, int pickSlot, Hand placeHand, int placeSlot, WaferSize size)
  1108. {
  1109. if (CheckToPostMessage((int)MSG.Swap, targetModule, pickSlot, pickHand, placeHand, placeSlot, size))
  1110. return (int)MSG.Swap;
  1111. return (int)FSM_MSG.NONE;
  1112. }
  1113. public int InvokeMap(string target )
  1114. {
  1115. if (CheckToPostMessage((int)MSG.Map, target ))
  1116. return (int)MSG.Map;
  1117. return (int)FSM_MSG.NONE;
  1118. }
  1119. public int InvokeFlip(Hand hand)
  1120. {
  1121. if (CheckToPostMessage((int)MSG.Flip, hand))
  1122. return (int)MSG.Flip;
  1123. return (int)FSM_MSG.NONE;
  1124. }
  1125. public bool IsPrepareTransferReady(ModuleName module, EnumTransferType type, int slot)
  1126. {
  1127. //if (type == EnumTransferType.Pick)
  1128. //{
  1129. // //需要补充:判断LP 放好了,而且已经map过。
  1130. // return _efem[module].HasCassette && _efem[module].IsMapped;
  1131. //}
  1132. //else if (type == EnumTransferType.Place)
  1133. //{
  1134. // //需要补充:判断LP 放好了,而且已经map过。
  1135. // return _efem[module].HasCassette && _efem[module].IsMapped;
  1136. //}
  1137. return false;
  1138. }
  1139. internal bool CheckReadyRunNewJob(ModuleName module)
  1140. {
  1141. //???
  1142. return true;
  1143. }
  1144. internal bool CheckReadyTransfer(ModuleName module)
  1145. {
  1146. //return _efem[module].HasCassette && _efem[module].IsMapped;
  1147. return true;
  1148. }
  1149. internal bool CheckPlaced(ModuleName module)
  1150. {
  1151. //return _efem[module].HasCassette;
  1152. return true;
  1153. }
  1154. internal void NoteJobStart(ModuleName module)
  1155. {
  1156. //_efem[module].NoteJobStart();
  1157. }
  1158. internal void NoteJobComplete(ModuleName module)
  1159. {
  1160. //_efem[module].NoteJobComplete();
  1161. }
  1162. }
  1163. }