EfemEntity.cs 55 KB

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