EfemEntity.cs 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336
  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 CycleRobotCycleRoutine _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 CycleRobotCycleRoutine(_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) => { PostMsg(MSG.RobotCycle,args); return true; });
  249. OP.Subscribe($"{ModuleName.EFEM}.{EfemOperation.ClearError}", (cmd, args) => { PostMsg(MSG.Recover); return true; });
  250. OP.Subscribe($"{ModuleName.EFEM}.{EfemOperation.TurnOffBuzzer}", (cmd, args) => { PostMsg(MSG.CloseBuzzer); return true; });
  251. OP.Subscribe($"{ModuleName.EFEM}.Online", (cmd, args) =>
  252. {
  253. PostMsg(MSG.Online, args[0]); return true;
  254. });
  255. OP.Subscribe($"{ModuleName.EfemRobot}.{EfemOperation.Pick}", (cmd, args) => { CheckToPostMessage<STATE, MSG>(eEvent.ERR_EFEM_COMMON_FAILED,"EFEM",(int)MSG.Pick, args[0]); return true; });
  256. OP.Subscribe($"{ModuleName.EfemRobot}.{EfemOperation.Place}", (cmd, args) => { CheckToPostMessage<STATE, MSG>(eEvent.ERR_EFEM_COMMON_FAILED, "EFEM", (int)MSG.Place, args[0]); return true; });
  257. OP.Subscribe($"{ModuleName.EfemRobot}.{EfemOperation.Swap}", (cmd, args) => { PostMsg(MSG.Swap, args[0]); return true; });
  258. OP.Subscribe($"{ModuleName.EfemRobot}.{EfemOperation.DummyMap}", (cmd, args) => { CheckToPostMessage<STATE, MSG>(eEvent.ERR_EFEM_COMMON_FAILED, "EFEM", (int)MSG.MapDummy); return true; });
  259. OP.Subscribe($"{ModuleName.EfemRobot}.{EfemOperation.Speed}", (cmd, args) => {
  260. return _efem.SetRobotSpeed(ModuleName.EfemRobot, (int)args[0]); });
  261. OP.Subscribe($"{ModuleName.EfemRobot}.{EfemOperation.Vacuum}", (cmd, args) => {
  262. return _efem.Vacuum(ModuleName.EfemRobot, (bool)args[1]); });
  263. OP.Subscribe($"{ModuleName.EfemRobot}.{EfemOperation.PowerOn}", (cmd, args) => {
  264. return _efem.RobotPowerOn(ModuleName.EfemRobot, (bool)args[0]); });
  265. OP.Subscribe($"{ModuleName.EfemRobot}.{EfemOperation.Abort}", (cmd, args) => { PostMsg(MSG.Abort); return true; });
  266. OP.Subscribe($"{ModuleName.EfemRobot}.{EfemOperation.Home}", (cmd, args) => { PostMsg(MSG.HomeRB); return true; });
  267. OP.Subscribe($"{ModuleName.EfemRobot}.{EfemOperation.Grip}", (cmd, args) =>
  268. {
  269. bool isGrip = ((string)args[0]).ToLower() == "on";
  270. PostMsg(isGrip ? MSG.Grip : MSG.Ungrip, args[1]);
  271. return true;
  272. });
  273. //OP.Subscribe($"{ModuleName.EfemRobot}.{EfemOperation.Flip}", (cmd, args) => { PostMsg(MSG.Flip, args[0]); return true; });
  274. OP.Subscribe($"{ModuleName.Aligner1}.{EfemOperation.Home}", (cmd, args) => { PostMsg(MSG.HomeAL, ModuleName.Aligner1); return true; });
  275. 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; });
  276. //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; });
  277. OP.Subscribe($"{ModuleName.Aligner1}.{EfemOperation.Vacuum}", (cmd, args) => { return VacuumAction(args); });
  278. DATA.Subscribe($"{Name}.FsmState", () => ((STATE)fsm.State).ToString(),SubscriptionAttribute.FLAG.IgnoreSaveDB);
  279. DATA.Subscribe($"{Name}.FsmPrevState", () => ((STATE)fsm.PrevState).ToString(), SubscriptionAttribute.FLAG.IgnoreSaveDB);
  280. DATA.Subscribe($"{Name}.FsmLastMessage", GetFsmLastMessage, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  281. DATA.Subscribe($"{Name}.RobotMoveAction", () => (_efem.TMRobotMoveInfo), SubscriptionAttribute.FLAG.IgnoreSaveDB);
  282. DATA.Subscribe($"{Name}.State", () => ((STATE)fsm.State).ToString(), SubscriptionAttribute.FLAG.IgnoreSaveDB);
  283. DATA.Subscribe($"{Name}.IsAlarm", () => IsError, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  284. DATA.Subscribe($"{Name}.IsInit", () => IsInit, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  285. DATA.Subscribe($"{Name}.IsIdle", () => IsIdle, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  286. DATA.Subscribe($"{Name}.IsBusy", () => IsBusy, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  287. DATA.Subscribe($"{Name}.IsOnline", () => IsOnline, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  288. DATA.Subscribe($"{Name}.IsHomed", () => _isHomed, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  289. DATA.Subscribe($"{Name}.RobotSpeed",()=>IsIdle?SC.GetValue<int>("EFEM.DefaultMoveSpeedInPercent"):0);
  290. DATA.Subscribe($"{Name}.CurrentRobotCycleTime",()=>_currentCycleTimes, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  291. _robotWatch.Restart();
  292. return true;
  293. }
  294. private void InitFsmMap()
  295. {
  296. fsm = new StateMachine<EfemEntity>("EFEM", (int)STATE.Unknown, 50);
  297. fsm.EnableRepeatedMsg(true);
  298. AnyStateTransition(FSM_MSG.TIMER, fnMonitor, FSM_STATE.SAME);
  299. AnyStateTransition(MSG.TurnOffBuzzer, fnTurnOffBuzzer, FSM_STATE.SAME);
  300. AnyStateTransition(MSG.Error, fnError, STATE.Error);
  301. AnyStateTransition(MSG.Online, fnOnline, FSM_STATE.SAME);
  302. //AnyStateTransition(MSG.Abort, fnAbortRobot, FSM_STATE.SAME);
  303. AnyStateTransition(MSG.ToInit, fnToInit, STATE.Init);
  304. AnyStateTransition(MSG.BackroundCmd, fnBackroundCommand, FSM_STATE.SAME);
  305. AnyStateTransition(MSG.CloseBuzzer, fnCloseBuzzer, FSM_STATE.SAME);
  306. Transition(STATE.Unknown,MSG.CommReady, fnCommReady, STATE.Init);
  307. //Error
  308. Transition(STATE.Error, MSG.Recover, fnRecover, STATE.Idle);
  309. // Home
  310. Transition(STATE.Unknown, MSG.HomeAll, fnHomeAll, STATE.Initializing);
  311. Transition(STATE.Init, MSG.HomeAll, fnHomeAll, STATE.Initializing);
  312. Transition(STATE.Idle, MSG.HomeAll, fnHomeAll, STATE.Initializing);
  313. Transition(STATE.Error, MSG.HomeAll, fnHomeAll, STATE.Initializing);
  314. Transition(STATE.Initializing, FSM_MSG.TIMER, fnHomingTimeout, STATE.Idle);
  315. // Home Robot
  316. Transition(STATE.Error, MSG.HomeRB, fnHomeRobot, STATE.InitingRB);
  317. Transition(STATE.Idle, MSG.HomeRB, fnHomeRobot, STATE.InitingRB);
  318. Transition(STATE.InitingRB, FSM_MSG.TIMER, fnHomingRobotTimeout, STATE.Idle);
  319. // Home Aligner
  320. Transition(STATE.Idle, MSG.HomeAL, fnHomeAligner, STATE.InitingAL);
  321. Transition(STATE.InitingAL, FSM_MSG.TIMER, fnHomingAlignTimeout, STATE.Idle);
  322. // Pick wafer
  323. Transition(STATE.Idle, MSG.Pick, FnStartPick, STATE.Picking);
  324. Transition(STATE.Picking, FSM_MSG.TIMER, FnPickTimeout, STATE.Idle);
  325. Transition(STATE.Picking, MSG.Abort, FnAbortPick, STATE.Idle);
  326. //Robot Cycle
  327. Transition(STATE.Idle, MSG.RobotCycle, FnStartRobotCycle, STATE.RobotCycleing);
  328. Transition(STATE.RobotCycleing, FSM_MSG.TIMER, FnRobotCycleTimeout, STATE.Idle);
  329. Transition(STATE.RobotCycleing, MSG.Abort, FnAbortRobotCycle, STATE.Idle);
  330. Transition(STATE.Error, MSG.Pick, FnErrorStartPick, STATE.ErrorPicking);
  331. Transition(STATE.ErrorPicking, FSM_MSG.TIMER, FnErrorPickTimeout, STATE.Error);
  332. Transition(STATE.ErrorPicking, MSG.Abort, FnErrorAbortPick, STATE.Error);
  333. // Place wafer
  334. Transition(STATE.Idle, MSG.Place, FnStartPlace, STATE.Placing);
  335. Transition(STATE.Placing, FSM_MSG.TIMER, FnPlaceTimeout, STATE.Idle);
  336. Transition(STATE.Placing, MSG.Abort, FnAbortPlace, STATE.Idle);
  337. Transition(STATE.Error, MSG.Place, FnErrorStartPlace, STATE.ErrorPlacing);
  338. Transition(STATE.ErrorPlacing, FSM_MSG.TIMER, FnErrorPlaceTimeout, STATE.Error);
  339. Transition(STATE.ErrorPlacing, MSG.Abort, FnErrorAbortPlace, STATE.Error);
  340. // Swap wafer with LL sequence
  341. Transition(STATE.Idle, MSG.Swap, FnStartSwap, STATE.Swapping);
  342. Transition(STATE.Swapping, FSM_MSG.TIMER, FnSwapTimeout, STATE.Idle);
  343. Transition(STATE.Swapping, MSG.Abort, FnAbortSwap, STATE.Idle);
  344. // Goto
  345. Transition(STATE.Idle, MSG.Goto, fnGoto, STATE.Gotoing);
  346. Transition(STATE.Gotoing, MSG.ActionDone, fnActionDone, STATE.Idle);
  347. // Map
  348. Transition(STATE.Idle, MSG.Map, fnMap, STATE.Mapping);
  349. Transition(STATE.Mapping, MSG.ActionDone, fnActionDone, STATE.Idle);
  350. // Grip
  351. Transition(STATE.Idle, MSG.Grip, fnGrip, STATE.Gripping);
  352. Transition(STATE.Gripping, MSG.ActionDone, fnActionDone, STATE.Idle);
  353. // Ungrip
  354. Transition(STATE.Idle, MSG.Ungrip, fnUngrip, STATE.Ungripping);
  355. Transition(STATE.Ungripping, MSG.ActionDone, fnActionDone, STATE.Idle);
  356. // Aligner
  357. Transition(STATE.Idle, MSG.Lift, fnLift, STATE.Lifting);
  358. //Transition(STATE.Lifting, MSG.LiftActionDone, fnActionDone, STATE.Idle);
  359. Transition(STATE.Lifting, FSM_MSG.TIMER, fnLiftTimeout, STATE.Idle);
  360. Transition(STATE.Idle, MSG.Align, fnAlign, STATE.Aligning);
  361. Transition(STATE.Aligning, FSM_MSG.TIMER, fnAlignTimeout, STATE.Idle);
  362. Transition(STATE.Aligning, MSG.ActionDone, fnActionDone, STATE.Idle);
  363. //MapDummy
  364. Transition(STATE.Idle, MSG.MapDummy, MapDummy, STATE.Mapping);
  365. Transition(STATE.Mapping, FSM_MSG.TIMER, MapDummyTimeout, STATE.Idle);
  366. //Vacuum
  367. //Transition(STATE.Init, MSG.Vacuum, VacuumAction, STATE.Vacuuming);
  368. //Transition(STATE.Idle, MSG.Vacuum, VacuumAction, STATE.Vacuuming);
  369. //Transition(STATE.Error, MSG.Vacuum, VacuumAction, STATE.Vacuuming);
  370. //Transition(STATE.Vacuuming, FSM_MSG.TIMER, VacuumActionTimeout, STATE.Idle);
  371. //Retry
  372. Transition(STATE.Error, MSG.Retry, NullFunc, STATE.Retrying);
  373. Transition(STATE.Retrying, FSM_MSG.TIMER, EfemRetry, STATE.Retrying);
  374. Transition(STATE.Retrying, MSG.Align, RetryAlign, STATE.Aligning);
  375. Transition(STATE.Retrying, MSG.Pick, RetryPick, STATE.Picking);
  376. Transition(STATE.Retrying, MSG.Place, RetryPlace, STATE.Placing);
  377. //ConfirmComplete
  378. Transition(STATE.Init, MSG.ConfirmComplete, ClearModuleAlarm, STATE.Init);
  379. Transition(STATE.Idle, MSG.ConfirmComplete, ClearModuleAlarm, STATE.Idle);
  380. Transition(STATE.Error, MSG.ConfirmComplete, NullFunc, STATE.ConfirmCompleting);
  381. Transition(STATE.ConfirmCompleting, FSM_MSG.TIMER, ConfirmComplete, STATE.ConfirmCompleting);
  382. Transition(STATE.ConfirmCompleting, MSG.Align, ConfirmAlign, STATE.Idle);
  383. Transition(STATE.ConfirmCompleting, MSG.Pick, ConfirmPickup, STATE.Idle);
  384. Transition(STATE.ConfirmCompleting, MSG.Place, ConfirmPlace, STATE.Idle);
  385. EnumLoop<STATE>.ForEach((item) => { fsm.MapState((int)item, item.ToString()); });
  386. EnumLoop<MSG>.ForEach((item) => { fsm.MapMessage((int)item, item.ToString()); });
  387. Running = true;
  388. }
  389. private bool fnCommReady(object[] param)
  390. {
  391. return true;
  392. }
  393. private bool fnCloseBuzzer(object[] param)
  394. {
  395. return _efem.CloseBuzzer();
  396. }
  397. private bool fnHomeAll(object[] param)
  398. {
  399. _isHomed = false;
  400. return _homeRoutine.Start(ModuleName.EFEM) == RState.Running;
  401. }
  402. private bool fnHomingTimeout(object[] param)
  403. {
  404. RState ret = _homeRoutine.Monitor();
  405. if (ret == RState.Failed || ret == RState.Timeout)
  406. {
  407. PostMsg(MSG.Error);
  408. return false;
  409. }
  410. bool result= ret == RState.End;
  411. if(result)
  412. {
  413. _isHomed= true;
  414. RecoverLPStatus();
  415. }
  416. return result;
  417. }
  418. private void RecoverLPStatus()
  419. {
  420. _lpms[0].PostMsg(LoadPortModule.MSG.EnterIdle);
  421. _lpms[1].PostMsg(LoadPortModule.MSG.EnterIdle);
  422. _lpms[2].PostMsg(LoadPortModule.MSG.EnterIdle);
  423. }
  424. private bool fnHomeRobot(object[] param)
  425. {
  426. if (_isHomed)
  427. {
  428. return _homeRoutine.Start(ModuleName.EfemRobot) == RState.Running;
  429. }
  430. else
  431. {
  432. return false;
  433. }
  434. }
  435. private bool fnHomingRobotTimeout(object[] param)
  436. {
  437. RState ret = _homeRoutine.Monitor();
  438. if (ret == RState.Failed || ret == RState.Timeout)
  439. {
  440. PostMsg(MSG.Error);
  441. return false;
  442. }
  443. bool result = ret == RState.End;
  444. if (result)
  445. {
  446. AlarmListManager.Instance.CheckModuleAlamAndRemove(Module.ToString(), STATE.Idle.ToString());
  447. }
  448. return result;
  449. }
  450. private bool fnHomeAligner(object[] param)
  451. {
  452. // module
  453. ModuleName unit = ModuleName.EFEM;
  454. if (param[0] is string s1)
  455. unit = ModuleNameString.ToEnum(s1);
  456. else if (param[0] is ModuleName mod)
  457. unit = mod;
  458. else
  459. throw new ArgumentException("Argument error");
  460. return _homeRoutine.Start(unit) == RState.Running;
  461. }
  462. private bool fnHomingAlignTimeout(object[] param)
  463. {
  464. RState ret = _homeRoutine.Monitor();
  465. if (ret == RState.Failed || ret == RState.Timeout)
  466. {
  467. PostMsg(MSG.Error);
  468. return false;
  469. }
  470. bool result = ret == RState.End;
  471. if (result)
  472. {
  473. AlarmListManager.Instance.CheckModuleAlamAndRemove(Module.ToString(), STATE.Idle.ToString());
  474. }
  475. return result;
  476. }
  477. private bool fnActionDone(object[] param)
  478. {
  479. return false;
  480. }
  481. public bool CheckToPostMessage(int msg, params object[] args)
  482. {
  483. if (!fsm.FindTransition(fsm.State, msg))
  484. {
  485. LOG.Write(eEvent.WARN_EFEM_COMMON_WARN, ModuleName.EFEM, $"{Name} is in {(STATE)fsm.State} state,can not do {(MSG)msg}");
  486. return false;
  487. }
  488. Running = true;
  489. fsm.PostMsg(msg, args);
  490. return true;
  491. }
  492. private bool fnMonitor(object[] param)
  493. {
  494. if (_isVacuume)
  495. {
  496. VacuumActionTimeout();
  497. _isVacuume = false;
  498. }
  499. // robot idle check
  500. _robotIdleTrigger.CLK = _efem.Status != RState.Running;
  501. if (_robotIdleTrigger.Q)
  502. {
  503. _robotWatch.Restart();
  504. LOG.WriteLog(eEvent.EV_EFEM_ROBOT, Module.ToString(), $"robot status changed to {_efem.Status}");
  505. }
  506. _autoMessageProcessor.Monitor();
  507. return true;
  508. }
  509. private bool fnOnline(object[] param)
  510. {
  511. bool bOnlineFlag = (bool)param[0];
  512. if (_efem is EfemBase efem)
  513. {
  514. efem.SetOnline(bOnlineFlag);
  515. }
  516. IsOnline = bOnlineFlag;
  517. return true;
  518. }
  519. private string GetFsmLastMessage()
  520. {
  521. int msg = fsm.LastMsg;
  522. if (msg >= (int)MSG.HomeAll && msg <= (int)MSG.Error)
  523. return ((MSG)msg).ToString();
  524. if (msg == (int)FSM_MSG.TIMER)
  525. return "Timer";
  526. return msg.ToString();
  527. }
  528. private bool fnError(object[] param)
  529. {
  530. _errorPreState = (STATE)fsm.State;
  531. string error = (param != null && param.Length != 0) ? param[0].ToString() : "";
  532. if (Singleton<RouteManager>.Instance.IsAutoRunning)
  533. {
  534. int msg = 0;
  535. if (_errorPreState == STATE.Picking)
  536. {
  537. msg = (int)MSG.Pick;
  538. }
  539. else if (_errorPreState == STATE.Aligning)
  540. {
  541. msg= (int)MSG.Align;
  542. }
  543. else if (_errorPreState == STATE.Placing)
  544. {
  545. msg = (int)MSG.Place;
  546. }
  547. else
  548. {
  549. error = $"{error}\r\n Plase Home Robot back to idle state";
  550. }
  551. AlarmList alarmList = new AlarmList(Module.ToString(), ((STATE)fsm.State).ToString(), msg,
  552. error, 0, (int)AlarmType.Error);
  553. AlarmListManager.Instance.AddAlarm(alarmList);
  554. }
  555. return true;
  556. }
  557. private bool fnToInit(object[] param)
  558. {
  559. return true;
  560. }
  561. private bool fnRecover(object[] param)
  562. {
  563. bool result=_efem.ClearError();
  564. if (result)
  565. {
  566. PostMsg(MSG.ToInit);
  567. }
  568. return result;
  569. }
  570. private bool fnAbortRobot(object[] param)
  571. {
  572. //_efem.ExecuteAction();
  573. return true;
  574. }
  575. private bool fnBackroundCommand(object[] param)
  576. {
  577. _autoMessageProcessor.SendAutoCommandMessage(param);
  578. return true;
  579. }
  580. private bool fnRobotPowerOn(object[] param)
  581. {
  582. return _efem.RobotPowerOn(ModuleName.EfemRobot, (bool)param[0]);
  583. }
  584. private bool fnSetLED(object[] param)
  585. {
  586. LightType light = (LightType)param[0];
  587. LightStatus st = (LightStatus)param[1];
  588. return _efem.SetLamp(light, st);
  589. }
  590. private bool fnTurnOffBuzzer(object[] param)
  591. {
  592. return false;
  593. }
  594. private bool FnStartPick(object[] param)
  595. {
  596. return _pickRoutine.Start(param) == RState.Running;
  597. }
  598. private bool FnStartRobotCycle(object[] param)
  599. {
  600. return _cycleRobotCycleRoutine.Start(param) == RState.Running;
  601. }
  602. private bool FnErrorStartPick(object[] param)
  603. {
  604. if (!_isHomed)
  605. {
  606. LOG.WriteLog(eEvent.ERR_EFEM_ROBOT, Module.ToString(), "EFEM is not homed");
  607. return false;
  608. }
  609. _efem.Reset();
  610. return _pickRoutine.Start(param) == RState.Running;
  611. }
  612. /// <summary>
  613. /// Retry Pick
  614. /// </summary>
  615. /// <param name="param"></param>
  616. /// <returns></returns>
  617. private bool RetryPick(object[] param)
  618. {
  619. int stepIndex = (int)param[0];
  620. return _pickRoutine.Retry(stepIndex) == RState.Running;
  621. }
  622. private bool FnPickTimeout(object[] param)
  623. {
  624. RState ret = _pickRoutine.Monitor();
  625. if (ret == RState.Failed || ret == RState.Timeout)
  626. {
  627. PostMsg(MSG.Error,_pickRoutine.ErrorMsg);
  628. return false;
  629. }
  630. if (ret == RState.End)
  631. {
  632. AlarmListManager.Instance.CheckModuleAlamAndRemove(Module.ToString(), STATE.Picking.ToString());
  633. }
  634. return ret == RState.End;
  635. }
  636. private bool FnRobotCycleTimeout(object[] param)
  637. {
  638. RState ret = _cycleRobotCycleRoutine.Monitor();
  639. if (ret == RState.Failed || ret == RState.Timeout)
  640. {
  641. PostMsg(MSG.Error);
  642. return false;
  643. }
  644. _currentCycleTimes = _cycleRobotCycleRoutine.GetCurrentCycle();
  645. return ret == RState.End;
  646. }
  647. private bool FnErrorPickTimeout(object[] param)
  648. {
  649. RState ret = _pickRoutine.Monitor();
  650. if (ret == RState.Failed || ret == RState.Timeout)
  651. {
  652. PostMsg(MSG.Error, _pickRoutine.ErrorMsg);
  653. return false;
  654. }
  655. return ret == RState.End;
  656. }
  657. /// <summary>
  658. /// 确认Pick是否完成
  659. /// </summary>
  660. /// <param name="param"></param>
  661. /// <returns></returns>
  662. private bool ConfirmPickup(object[] param)
  663. {
  664. int stepIdex = (int)param[0];
  665. bool result = _pickRoutine.CheckCompleteCondition(stepIdex);
  666. if (!result)
  667. {
  668. PostMsg(MSG.Error,_pickRoutine.ErrorMsg);
  669. }
  670. else
  671. {
  672. if (Singleton<RouteManager>.Instance.IsAutoRunning)
  673. {
  674. AlarmListManager.Instance.CheckModuleAlamAndRemove(Module.ToString(), STATE.Picking.ToString());
  675. }
  676. }
  677. return result;
  678. }
  679. private bool FnAbortPick(object[] param)
  680. {
  681. _pickRoutine.Abort();
  682. return true;
  683. }
  684. private bool FnAbortRobotCycle(object[] param)
  685. {
  686. _cycleRobotCycleRoutine.Abort();
  687. return true;
  688. }
  689. private bool FnErrorAbortPick(object[] param)
  690. {
  691. _pickRoutine.Abort();
  692. return true;
  693. }
  694. private bool FnStartPlace(object[] param)
  695. {
  696. return _placeRoutine.Start(param) == RState.Running;
  697. }
  698. private bool FnErrorStartPlace(object[] param)
  699. {
  700. if(!_isHomed)
  701. {
  702. LOG.WriteLog(eEvent.ERR_EFEM_ROBOT, Module.ToString(), "EFEM is not homed");
  703. return false;
  704. }
  705. _efem.Reset();
  706. return _placeRoutine.Start(param) == RState.Running;
  707. }
  708. /// <summary>
  709. /// Retry Place
  710. /// </summary>
  711. /// <param name="param"></param>
  712. /// <returns></returns>
  713. private bool RetryPlace(object[] param)
  714. {
  715. int stepIndex = (int)param[0];
  716. return _placeRoutine.Retry(stepIndex) == RState.Running;
  717. }
  718. private bool FnPlaceTimeout(object[] param)
  719. {
  720. RState ret = _placeRoutine.Monitor();
  721. if (ret == RState.Failed || ret == RState.Timeout)
  722. {
  723. PostMsg(MSG.Error,_placeRoutine.ErrorMsg);
  724. return false;
  725. }
  726. if (ret == RState.End)
  727. {
  728. AlarmListManager.Instance.CheckModuleAlamAndRemove(Module.ToString(), STATE.Placing.ToString());
  729. }
  730. return ret == RState.End;
  731. }
  732. private bool FnErrorPlaceTimeout(object[] param)
  733. {
  734. RState ret = _placeRoutine.Monitor();
  735. if (ret == RState.Failed || ret == RState.Timeout)
  736. {
  737. PostMsg(MSG.Error, _placeRoutine.ErrorMsg);
  738. return false;
  739. }
  740. return ret == RState.End;
  741. }
  742. /// <summary>
  743. /// 确认Place是否完成
  744. /// </summary>
  745. /// <param name="param"></param>
  746. /// <returns></returns>
  747. private bool ConfirmPlace(object[] param)
  748. {
  749. int stepIdex = (int)param[0];
  750. bool result = _placeRoutine.CheckCompleteCondition(stepIdex);
  751. if (!result)
  752. {
  753. PostMsg(MSG.Error, _placeRoutine.ErrorMsg);
  754. }
  755. else
  756. {
  757. if (Singleton<RouteManager>.Instance.IsAutoRunning)
  758. {
  759. AlarmListManager.Instance.CheckModuleAlamAndRemove(Module.ToString(), STATE.Picking.ToString());
  760. }
  761. }
  762. return result;
  763. }
  764. private bool FnAbortPlace(object[] param)
  765. {
  766. _placeRoutine.Abort();
  767. return true;
  768. }
  769. private bool FnErrorAbortPlace(object[] param)
  770. {
  771. _placeRoutine.Abort();
  772. return true;
  773. }
  774. private bool FnStartSwap(object[] param)
  775. {
  776. return _swapRoutine.Start(param) == RState.Running;
  777. }
  778. private bool FnSwapTimeout(object[] param)
  779. {
  780. RState ret = _swapRoutine.Monitor();
  781. if (ret == RState.Failed || ret == RState.Timeout)
  782. {
  783. PostMsg(MSG.Error);
  784. return false;
  785. }
  786. return ret == RState.End;
  787. }
  788. private bool FnAbortSwap(object[] param)
  789. {
  790. _swapRoutine.Abort();
  791. return true;
  792. }
  793. private bool fnGoto(object[] param)
  794. {
  795. // module
  796. ModuleName unit = ModuleName.EFEM;
  797. if (param[0] is string s1)
  798. unit = ModuleNameString.ToEnum(s1);
  799. else if (param[0] is ModuleName mod)
  800. unit = mod;
  801. else
  802. throw new ArgumentException("Argument error");
  803. _efem.Goto(unit, Hand.Blade1);
  804. return true;
  805. }
  806. private bool fnLift(object[] param)
  807. {
  808. // module
  809. ModuleName unit = ModuleName.EFEM;
  810. if (param[0] is string s1)
  811. unit = ModuleNameString.ToEnum(s1);
  812. else if (param[0] is ModuleName mod)
  813. unit = mod;
  814. else
  815. throw new ArgumentException("Argument error");
  816. bool isUp = true;
  817. if (param.Length > 1)
  818. {
  819. isUp = (bool) param[1];
  820. }
  821. if (isUp)
  822. {
  823. if (!_efem.SetPinUp(unit))
  824. return false;
  825. }
  826. else
  827. {
  828. if (!_efem.SetPinDown(unit))
  829. return false;
  830. }
  831. LiftMessage = isUp ? "Up" : "Down";
  832. return true;
  833. }
  834. private bool fnLiftTimeout(object[] param)
  835. {
  836. if (LiftMessage == "Up")
  837. {
  838. return _efem.LiftIsDown == false && _efem.LiftIsUp == true;
  839. }
  840. else if (LiftMessage == "Down")
  841. {
  842. return _efem.LiftIsDown == true && _efem.LiftIsUp == false;
  843. }
  844. return false;
  845. }
  846. private bool fnAlign(object[] param)
  847. {
  848. return _alignRoutine.Start(param) == RState.Running;
  849. }
  850. private bool fnAlignTimeout(object[] param)
  851. {
  852. RState ret = _alignRoutine.Monitor();
  853. if (ret == RState.Failed || ret == RState.Timeout)
  854. {
  855. PostMsg(MSG.Error,_alignRoutine.ErrorMsg);
  856. return false;
  857. }
  858. if (ret == RState.End)
  859. {
  860. AlarmListManager.Instance.CheckModuleAlamAndRemove(Module.ToString(), STATE.Aligning.ToString());
  861. }
  862. return ret == RState.End;
  863. }
  864. /// <summary>
  865. /// Retry Align
  866. /// </summary>
  867. /// <param name="param"></param>
  868. /// <returns></returns>
  869. private bool RetryAlign(object[] param)
  870. {
  871. int stepIndex = (int)param[0];
  872. return _alignRoutine.Retry(stepIndex) == RState.Running;
  873. }
  874. /// <summary>
  875. /// 确认Align是否完成
  876. /// </summary>
  877. /// <param name="param"></param>
  878. /// <returns></returns>
  879. private bool ConfirmAlign(object[] param)
  880. {
  881. int stepIdex = (int)param[0];
  882. bool result = _alignRoutine.CheckCompleteCondition(stepIdex);
  883. if (!result)
  884. {
  885. PostMsg(MSG.Error, _alignRoutine.ErrorMsg);
  886. }
  887. else
  888. {
  889. if (Singleton<RouteManager>.Instance.IsAutoRunning)
  890. {
  891. AlarmListManager.Instance.CheckModuleAlamAndRemove(Module.ToString(), STATE.Aligning.ToString());
  892. }
  893. }
  894. return result;
  895. }
  896. private bool MapDummyTimeout(object[] param)
  897. {
  898. RState ret = _mapDummyRoutine.Monitor();
  899. if (ret == RState.Failed || ret == RState.Timeout)
  900. {
  901. PostMsg(MSG.Error);
  902. return false;
  903. }
  904. return ret == RState.End;
  905. }
  906. private bool VacuumActionTimeout()
  907. {
  908. RState ret = _vacuumRoutine.Monitor();
  909. if (ret == RState.Failed || ret == RState.Timeout)
  910. {
  911. LOG.Write(eEvent.ERR_EFEM_COMMON_FAILED, ModuleName.EFEM, "Vacuum");
  912. return false;
  913. }
  914. return ret == RState.End;
  915. }
  916. private bool fnMap(object[] param)
  917. {
  918. // module
  919. ModuleName unit = ModuleName.EFEM;
  920. if (param[0] is string s1)
  921. unit = ModuleNameString.ToEnum(s1);
  922. else if (param[0] is ModuleName mod)
  923. unit = mod;
  924. else
  925. throw new ArgumentException("Argument error");
  926. if (!_efem.Map(unit))
  927. return false;
  928. return true;
  929. }
  930. private bool MapDummy(object[] param)
  931. {
  932. return _mapDummyRoutine.Start()==RState.Running;
  933. }
  934. private bool VacuumAction(object[] param)
  935. {
  936. ModuleName vacuumModule = (ModuleName)param[0];
  937. bool vacuum=(bool)param[1];
  938. bool result = _vacuumRoutine.Start(vacuumModule, vacuum) == RState.Running;
  939. if (result)
  940. {
  941. _isVacuume = true;
  942. }
  943. return result;
  944. }
  945. private bool fnGrip(object[] param)
  946. {
  947. Hand arm = (Hand)Enum.Parse(typeof(Hand), (string)param[0]);
  948. if (!_efem.Grip(arm, true))
  949. return false;
  950. return true;
  951. }
  952. public int SendEfemAutoCommand(params object[] args)
  953. {
  954. if (CheckToPostMessage((int)MSG.BackroundCmd, args))
  955. return (int)MSG.BackroundCmd;
  956. return (int)FSM_MSG.NONE;
  957. }
  958. private bool fnUngrip(object[] param)
  959. {
  960. Hand arm = (Hand)Enum.Parse(typeof(Hand), (string)param[0]);
  961. if (!_efem.Grip(arm, false))
  962. return false;
  963. return true;
  964. }
  965. #region EfemRetry
  966. /// <summary>
  967. /// Retry
  968. /// </summary>
  969. /// <param name="param"></param>
  970. /// <returns></returns>
  971. private bool EfemRetry(object[] param)
  972. {
  973. AlarmList alarmList = AlarmListManager.Instance.GetAlarmListByModule(Module.ToString());
  974. if (alarmList != null)
  975. {
  976. CheckToPostMessage<STATE, MSG>(eEvent.ERR_EFEM_ROBOT, Module.ToString(), alarmList.ModuleCmd,
  977. alarmList.ModuleStep);
  978. }
  979. return false;
  980. }
  981. #endregion
  982. #region ConfirmComplete
  983. /// <summary>
  984. /// 确认是否完成
  985. /// </summary>
  986. /// <param name="param"></param>
  987. /// <returns></returns>
  988. private bool ConfirmComplete(object[] param)
  989. {
  990. AlarmList alarmList = AlarmListManager.Instance.GetAlarmListByModule(Module.ToString());
  991. if (alarmList != null)
  992. {
  993. if (alarmList.ModuleState == STATE.Picking.ToString())
  994. {
  995. CheckToPostMessage<STATE, MSG>(eEvent.ERR_EFEM_ROBOT, Module.ToString(), (int)MSG.Pick, alarmList.ModuleStep);
  996. }
  997. else if (alarmList.ModuleState == STATE.Placing.ToString())
  998. {
  999. CheckToPostMessage<STATE, MSG>(eEvent.ERR_EFEM_ROBOT, Module.ToString(), (int)MSG.Place, alarmList.ModuleStep);
  1000. }
  1001. else if (alarmList.ModuleState == STATE.Aligning.ToString())
  1002. {
  1003. CheckToPostMessage<STATE, MSG>(eEvent.ERR_EFEM_ROBOT, Module.ToString(), (int)MSG.Align, alarmList.ModuleStep);
  1004. }
  1005. else
  1006. {
  1007. PostMsg(PUFSTATE.Error);
  1008. }
  1009. }
  1010. return false;
  1011. }
  1012. /// <summary>
  1013. /// 清除报警
  1014. /// </summary>
  1015. /// <param name="param"></param>
  1016. /// <returns></returns>
  1017. private bool ClearModuleAlarm(object[] param)
  1018. {
  1019. AlarmList alarmList = AlarmListManager.Instance.GetAlarmListByModule(Module.ToString());
  1020. if (alarmList != null)
  1021. {
  1022. AlarmListManager.Instance.CheckModuleAlamAndRemove(Module.ToString(), "");
  1023. }
  1024. return true;
  1025. }
  1026. #endregion
  1027. public int Invoke(string function, params object[] args)
  1028. {
  1029. switch (function)
  1030. {
  1031. case "HomeAll":
  1032. if (IsIdle)
  1033. {
  1034. return (int)FSM_MSG.NONE;
  1035. }
  1036. if (CheckToPostMessage((int)MSG.HomeAll))
  1037. {
  1038. return (int)MSG.HomeAll;
  1039. }
  1040. else
  1041. {
  1042. return (int)FSM_MSG.NONE;
  1043. }
  1044. case "Retry":
  1045. if (CheckToPostMessage<STATE, MSG>(eEvent.ERR_EFEM_ROBOT, Module.ToString(), (int)MSG.Retry, args))
  1046. {
  1047. return (int)MSG.Retry;
  1048. }
  1049. else
  1050. {
  1051. return (int)FSM_MSG.NONE;
  1052. }
  1053. case "ConfirmComplete":
  1054. if (CheckToPostMessage<STATE, MSG>(eEvent.ERR_EFEM_ROBOT, Module.ToString(), (int)MSG.ConfirmComplete, args))
  1055. {
  1056. return (int)MSG.ConfirmComplete;
  1057. }
  1058. else
  1059. {
  1060. return (int)FSM_MSG.NONE;
  1061. }
  1062. }
  1063. return (int)FSM_MSG.NONE;
  1064. }
  1065. public bool CheckAcked(int msg)
  1066. {
  1067. return fsm.CheckExecuted(msg);
  1068. }
  1069. internal void InvokeReset()
  1070. {
  1071. if (fsm.State == (int) STATE.Error)
  1072. {
  1073. PostMsg((int)MSG.Recover);
  1074. }
  1075. }
  1076. public int InvokeAlign(string module, int reserv, float time)
  1077. {
  1078. if (CheckToPostMessage((int)MSG.Align, module, reserv, time))
  1079. return (int)MSG.Align;
  1080. return (int)FSM_MSG.NONE;
  1081. }
  1082. public int InvokeLiftDown(string module)
  1083. {
  1084. if (CheckToPostMessage((int)MSG.Lift, module, false))
  1085. return (int)MSG.Lift;
  1086. return (int)FSM_MSG.NONE;
  1087. }
  1088. public int InvokePick(ModuleName source, int slot, Hand hand, WaferSize size)
  1089. {
  1090. if (CheckToPostMessage((int)MSG.Pick, source, slot, hand, size))
  1091. return (int)MSG.Pick;
  1092. return (int)FSM_MSG.NONE;
  1093. }
  1094. public int InvokeGoto(ModuleName source, int slot)
  1095. {
  1096. if (CheckToPostMessage((int)MSG.Goto, source, slot))
  1097. return (int)MSG.Goto;
  1098. return (int)FSM_MSG.NONE;
  1099. }
  1100. public int InvokePlace(ModuleName target, int slot, Hand hand, WaferSize size)
  1101. {
  1102. if (CheckToPostMessage((int)MSG.Place, target, slot, hand, size))
  1103. return (int)MSG.Place;
  1104. return (int)FSM_MSG.NONE;
  1105. }
  1106. public int InvokePickAndPlace(ModuleName targetModule, Hand pickHand, int pickSlot, Hand placeHand, int placeSlot, WaferSize size)
  1107. {
  1108. if (CheckToPostMessage((int)MSG.Swap, targetModule, pickSlot, pickHand, placeHand, placeSlot, size))
  1109. return (int)MSG.Swap;
  1110. return (int)FSM_MSG.NONE;
  1111. }
  1112. public int InvokeMap(string target )
  1113. {
  1114. if (CheckToPostMessage((int)MSG.Map, target ))
  1115. return (int)MSG.Map;
  1116. return (int)FSM_MSG.NONE;
  1117. }
  1118. public int InvokeFlip(Hand hand)
  1119. {
  1120. if (CheckToPostMessage((int)MSG.Flip, hand))
  1121. return (int)MSG.Flip;
  1122. return (int)FSM_MSG.NONE;
  1123. }
  1124. public bool IsPrepareTransferReady(ModuleName module, EnumTransferType type, int slot)
  1125. {
  1126. //if (type == EnumTransferType.Pick)
  1127. //{
  1128. // //需要补充:判断LP 放好了,而且已经map过。
  1129. // return _efem[module].HasCassette && _efem[module].IsMapped;
  1130. //}
  1131. //else if (type == EnumTransferType.Place)
  1132. //{
  1133. // //需要补充:判断LP 放好了,而且已经map过。
  1134. // return _efem[module].HasCassette && _efem[module].IsMapped;
  1135. //}
  1136. return false;
  1137. }
  1138. internal bool CheckReadyRunNewJob(ModuleName module)
  1139. {
  1140. //???
  1141. return true;
  1142. }
  1143. internal bool CheckReadyTransfer(ModuleName module)
  1144. {
  1145. //return _efem[module].HasCassette && _efem[module].IsMapped;
  1146. return true;
  1147. }
  1148. internal bool CheckPlaced(ModuleName module)
  1149. {
  1150. //return _efem[module].HasCassette;
  1151. return true;
  1152. }
  1153. internal void NoteJobStart(ModuleName module)
  1154. {
  1155. //_efem[module].NoteJobStart();
  1156. }
  1157. internal void NoteJobComplete(ModuleName module)
  1158. {
  1159. //_efem[module].NoteJobComplete();
  1160. }
  1161. }
  1162. }