EfemEntity.cs 51 KB

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