EfemEntity.cs 52 KB

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