EfemEntity.cs 50 KB

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