EfemEntity.cs 51 KB

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