EfemEntity.cs 55 KB

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