EfemEntity.cs 51 KB

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