EfemEntity.cs 55 KB

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