EfemEntity.cs 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523
  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. DATA.Subscribe($"{Name}.FsmState", () => ((STATE)fsm.State).ToString(),SubscriptionAttribute.FLAG.IgnoreSaveDB);
  320. DATA.Subscribe($"{Name}.FsmPrevState", () => ((STATE)fsm.PrevState).ToString(), SubscriptionAttribute.FLAG.IgnoreSaveDB);
  321. DATA.Subscribe($"{Name}.FsmLastMessage", GetFsmLastMessage, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  322. DATA.Subscribe($"{Name}.RobotMoveAction", () => (_efem.TMRobotMoveInfo), SubscriptionAttribute.FLAG.IgnoreSaveDB);
  323. DATA.Subscribe($"{Name}.State", () => ((STATE)fsm.State).ToString(), SubscriptionAttribute.FLAG.IgnoreSaveDB);
  324. DATA.Subscribe($"{Name}.IsAlarm", () => IsError, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  325. DATA.Subscribe($"{Name}.IsInit", () => IsInit, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  326. DATA.Subscribe($"{Name}.IsIdle", () => IsIdle, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  327. DATA.Subscribe($"{Name}.IsBusy", () => IsBusy, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  328. DATA.Subscribe($"{Name}.IsOnline", () => IsOnline, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  329. DATA.Subscribe($"{Name}.IsHomed", () => _isHomed, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  330. DATA.Subscribe($"{Name}.RobotSpeed",()=>IsIdle?SC.GetValue<int>("EFEM.DefaultMoveSpeedInPercent"):0);
  331. DATA.Subscribe($"{Name}.CurrentRobotCycleTime",()=>_currentCycleTimes, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  332. DATA.Subscribe($"{Name}.VacuumValue",()=>_vacuumValue, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  333. DATA.Subscribe($"{Name}.DoorUnlock", () => _doorUnlock, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  334. DATA.Subscribe($"{Name}.DoorLocked", () => _doorLocked, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  335. _robotWatch.Restart();
  336. return true;
  337. }
  338. /// <summary>
  339. /// 订阅IO变量
  340. /// </summary>
  341. /// <param name="variable"></param>
  342. private void BeckhoffIoSubscribeUpdateVariable(string variable)
  343. {
  344. _variableInitializeDic[variable] = false;
  345. IOModuleManager.Instance.SubscribeModuleVariable($"{Module}", variable, UpdateVariableValue);
  346. }
  347. /// 更新变量数值
  348. /// </summary>
  349. /// <param name="variable"></param>
  350. /// <param name="value"></param>
  351. private void UpdateVariableValue(string variable, object value)
  352. {
  353. _variableInitializeDic[variable] = true;
  354. if (variable == VACUUM_VALUE)
  355. {
  356. _vacuumValue = (double)value;
  357. }
  358. else if (variable == DOOR_UNLOCK)
  359. {
  360. _doorUnlock = (bool)value;
  361. }
  362. else if (variable == DOOR_LOCKED)
  363. {
  364. _doorLocked = (bool)value;
  365. }
  366. }
  367. private void InitFsmMap()
  368. {
  369. fsm = new StateMachine<EfemEntity>("EFEM", (int)STATE.Unknown, 50);
  370. fsm.EnableRepeatedMsg(true);
  371. AnyStateTransition(FSM_MSG.TIMER, fnMonitor, FSM_STATE.SAME);
  372. AnyStateTransition(MSG.TurnOffBuzzer, fnTurnOffBuzzer, FSM_STATE.SAME);
  373. AnyStateTransition(MSG.Error, fnError, STATE.Error);
  374. AnyStateTransition(MSG.Online, fnOnline, FSM_STATE.SAME);
  375. AnyStateTransition(MSG.Abort, fnAbortRobot, FSM_STATE.SAME);
  376. AnyStateTransition(MSG.ToInit, fnToInit, STATE.Init);
  377. AnyStateTransition(MSG.BackroundCmd, fnBackroundCommand, FSM_STATE.SAME);
  378. AnyStateTransition(MSG.CloseBuzzer, fnCloseBuzzer, FSM_STATE.SAME);
  379. AnyStateTransition(MSG.CloseBuzzer, fnCloseBuzzer, FSM_STATE.SAME);
  380. AnyStateTransition(MSG.Pause, EnterPause, STATE.Pause);
  381. //Resume
  382. Transition(STATE.Pause, MSG.Resume, EnterResume, STATE.Resumeing);
  383. Transition(STATE.Resumeing, FSM_MSG.TIMER, fnResumeTimeout, STATE.Init);
  384. Transition(STATE.Unknown,MSG.CommReady, fnCommReady, STATE.Init);
  385. //Error
  386. Transition(STATE.Error, MSG.Recover, fnRecover, STATE.Idle);
  387. // Home
  388. Transition(STATE.Unknown, MSG.HomeAll, fnHomeAll, STATE.Initializing);
  389. Transition(STATE.Init, MSG.HomeAll, fnHomeAll, STATE.Initializing);
  390. Transition(STATE.Idle, MSG.HomeAll, fnHomeAll, STATE.Initializing);
  391. Transition(STATE.Error, MSG.HomeAll, fnHomeAll, STATE.Initializing);
  392. Transition(STATE.Initializing, FSM_MSG.TIMER, fnHomingTimeout, STATE.Idle);
  393. // Home Robot
  394. Transition(STATE.Error, MSG.HomeRB, fnHomeRobot, STATE.InitingRB);
  395. Transition(STATE.Idle, MSG.HomeRB, fnHomeRobot, STATE.InitingRB);
  396. Transition(STATE.InitingRB, FSM_MSG.TIMER, fnHomingRobotTimeout, STATE.Idle);
  397. // Home Aligner
  398. Transition(STATE.Idle, MSG.HomeAL, fnHomeAligner, STATE.InitingAL);
  399. Transition(STATE.InitingAL, FSM_MSG.TIMER, fnHomingAlignTimeout, STATE.Idle);
  400. Transition(STATE.Error, MSG.HomeAL, fnHomeAligner, STATE.ErrorInitingAL);
  401. Transition(STATE.ErrorInitingAL, FSM_MSG.TIMER, fnHomingAlignTimeout, STATE.Error);
  402. // Pick wafer
  403. Transition(STATE.Idle, MSG.Pick, FnStartPick, STATE.Picking);
  404. Transition(STATE.Picking, FSM_MSG.TIMER, FnPickTimeout, STATE.Idle);
  405. Transition(STATE.Picking, MSG.Abort, FnAbortPick, STATE.Idle);
  406. //Robot Cycle
  407. Transition(STATE.Idle, MSG.RobotCycle, FnStartRobotCycle, STATE.RobotCycleing);
  408. Transition(STATE.RobotCycleing, FSM_MSG.TIMER, FnRobotCycleTimeout, STATE.Idle);
  409. Transition(STATE.RobotCycleing, MSG.Abort, FnAbortRobotCycle, STATE.Idle);
  410. Transition(STATE.Error, MSG.Pick, FnErrorStartPick, STATE.ErrorPicking);
  411. Transition(STATE.ErrorPicking, FSM_MSG.TIMER, FnErrorPickTimeout, STATE.Error);
  412. Transition(STATE.ErrorPicking, MSG.Abort, FnErrorAbortPick, STATE.Error);
  413. // Place wafer
  414. Transition(STATE.Idle, MSG.Place, FnStartPlace, STATE.Placing);
  415. Transition(STATE.Placing, FSM_MSG.TIMER, FnPlaceTimeout, STATE.Idle);
  416. Transition(STATE.Placing, MSG.Abort, FnAbortPlace, STATE.Idle);
  417. Transition(STATE.Error, MSG.Place, FnErrorStartPlace, STATE.ErrorPlacing);
  418. Transition(STATE.ErrorPlacing, FSM_MSG.TIMER, FnErrorPlaceTimeout, STATE.Error);
  419. Transition(STATE.ErrorPlacing, MSG.Abort, FnErrorAbortPlace, STATE.Error);
  420. // Swap wafer with LL sequence
  421. Transition(STATE.Idle, MSG.Swap, FnStartSwap, STATE.Swapping);
  422. Transition(STATE.Swapping, FSM_MSG.TIMER, FnSwapTimeout, STATE.Idle);
  423. Transition(STATE.Swapping, MSG.Abort, FnAbortSwap, STATE.Idle);
  424. // Goto
  425. Transition(STATE.Idle, MSG.Goto, fnGoto, STATE.Gotoing);
  426. Transition(STATE.Gotoing, MSG.ActionDone, fnActionDone, STATE.Idle);
  427. // Map
  428. Transition(STATE.Idle, MSG.Map, fnMap, STATE.Mapping);
  429. Transition(STATE.Mapping, MSG.ActionDone, fnActionDone, STATE.Idle);
  430. // Grip
  431. Transition(STATE.Idle, MSG.Grip, fnGrip, STATE.Gripping);
  432. Transition(STATE.Gripping, MSG.ActionDone, fnActionDone, STATE.Idle);
  433. // Ungrip
  434. Transition(STATE.Idle, MSG.Ungrip, fnUngrip, STATE.Ungripping);
  435. Transition(STATE.Ungripping, MSG.ActionDone, fnActionDone, STATE.Idle);
  436. Transition(STATE.Idle, MSG.Lift, fnLift, STATE.Lifting);
  437. //Transition(STATE.Lifting, MSG.LiftActionDone, fnActionDone, STATE.Idle);
  438. Transition(STATE.Lifting, FSM_MSG.TIMER, fnLiftTimeout, STATE.Idle);
  439. Transition(STATE.Idle, MSG.Align, fnAlign, STATE.Aligning);
  440. Transition(STATE.Aligning, FSM_MSG.TIMER, fnAlignTimeout, STATE.Idle);
  441. Transition(STATE.Aligning, MSG.ActionDone, fnActionDone, STATE.Idle);
  442. //MapDummy
  443. Transition(STATE.Idle, MSG.MapDummy, MapDummy, STATE.Mapping);
  444. Transition(STATE.Mapping, FSM_MSG.TIMER, MapDummyTimeout, STATE.Idle);
  445. //Resume
  446. Transition(STATE.Idle, MSG.MapDummy, MapDummy, STATE.Mapping);
  447. //Vacuum
  448. //Transition(STATE.Init, MSG.Vacuum, VacuumAction, STATE.Vacuuming);
  449. //Transition(STATE.Idle, MSG.Vacuum, VacuumAction, STATE.Vacuuming);
  450. //Transition(STATE.Error, MSG.Vacuum, VacuumAction, STATE.Vacuuming);
  451. //Transition(STATE.Vacuuming, FSM_MSG.TIMER, VacuumActionTimeout, STATE.Idle);
  452. //Retry
  453. Transition(STATE.Error, MSG.Retry, NullFunc, STATE.Retrying);
  454. Transition(STATE.Retrying, FSM_MSG.TIMER, EfemRetry, STATE.Retrying);
  455. Transition(STATE.Retrying, MSG.Align, RetryAlign, STATE.Aligning);
  456. Transition(STATE.Retrying, MSG.Pick, RetryPick, STATE.Picking);
  457. Transition(STATE.Retrying, MSG.Place, RetryPlace, STATE.Placing);
  458. //ConfirmComplete
  459. Transition(STATE.Init, MSG.ConfirmComplete, ClearModuleAlarm, STATE.Init);
  460. Transition(STATE.Idle, MSG.ConfirmComplete, ClearModuleAlarm, STATE.Idle);
  461. Transition(STATE.Error, MSG.ConfirmComplete, NullFunc, STATE.ConfirmCompleting);
  462. Transition(STATE.ConfirmCompleting, FSM_MSG.TIMER, ConfirmComplete, STATE.ConfirmCompleting);
  463. Transition(STATE.ConfirmCompleting, MSG.Align, ConfirmAlign, STATE.Idle);
  464. Transition(STATE.ConfirmCompleting, MSG.Pick, ConfirmPickup, STATE.Idle);
  465. Transition(STATE.ConfirmCompleting, MSG.Place, ConfirmPlace, STATE.Idle);
  466. EnumLoop<STATE>.ForEach((item) => { fsm.MapState((int)item, item.ToString()); });
  467. EnumLoop<MSG>.ForEach((item) => { fsm.MapMessage((int)item, item.ToString()); });
  468. Running = true;
  469. }
  470. private bool fnCommReady(object[] param)
  471. {
  472. return true;
  473. }
  474. private bool fnCloseBuzzer(object[] param)
  475. {
  476. return _efem.CloseBuzzer();
  477. }
  478. /// <summary>
  479. ///
  480. /// </summary>
  481. /// <param name="param"></param>
  482. /// <returns></returns>
  483. private bool EnterPause(object[] param)
  484. {
  485. return true;
  486. }
  487. private bool EnterResume(object[] param)
  488. {
  489. return true;
  490. }
  491. private bool fnResumeTimeout(object[] param)
  492. {
  493. _currentRoutine = _efemSafeCloseRoutine;
  494. RState ret = _efemSafeCloseRoutine.Monitor();
  495. if (ret == RState.Failed || ret == RState.Timeout)
  496. {
  497. _currentRoutine = null;
  498. PostMsg(MSG.Error);
  499. return false;
  500. }
  501. bool result = ret == RState.End;
  502. if (result)
  503. {
  504. _currentRoutine = null;
  505. }
  506. return result;
  507. }
  508. private bool fnHomeAll(object[] param)
  509. {
  510. _isHomed = false;
  511. return _homeRoutine.Start(ModuleName.EFEM) == RState.Running;
  512. }
  513. private bool fnHomingTimeout(object[] param)
  514. {
  515. _currentRoutine = _homeRoutine;
  516. RState ret = _homeRoutine.Monitor();
  517. if (ret == RState.Failed || ret == RState.Timeout)
  518. {
  519. _currentRoutine = null;
  520. PostMsg(MSG.Error);
  521. return false;
  522. }
  523. bool result= ret == RState.End;
  524. if(result)
  525. {
  526. _isHomed= true;
  527. RecoverLPStatus();
  528. _currentRoutine = null;
  529. }
  530. return result;
  531. }
  532. private void RecoverLPStatus()
  533. {
  534. _lpms[0].PostMsg(LoadPortModule.MSG.EnterIdle);
  535. _lpms[1].PostMsg(LoadPortModule.MSG.EnterIdle);
  536. _lpms[2].PostMsg(LoadPortModule.MSG.EnterIdle);
  537. }
  538. private bool fnHomeRobot(object[] param)
  539. {
  540. return _homeRoutine.Start(ModuleName.EfemRobot) == RState.Running;
  541. }
  542. private bool fnHomingRobotTimeout(object[] param)
  543. {
  544. _currentRoutine = _homeRoutine;
  545. RState ret = _homeRoutine.Monitor();
  546. if (ret == RState.Failed || ret == RState.Timeout)
  547. {
  548. PostMsg(MSG.Error);
  549. _currentRoutine = _homeRoutine;
  550. return false;
  551. }
  552. bool result = ret == RState.End;
  553. if (result)
  554. {
  555. _currentRoutine = null;
  556. AlarmListManager.Instance.CheckModuleAlamAndRemove(Module.ToString(), STATE.Idle.ToString());
  557. }
  558. return result;
  559. }
  560. private bool fnHomeAligner(object[] param)
  561. {
  562. // module
  563. ModuleName unit = ModuleName.EFEM;
  564. if (param[0] is string s1)
  565. unit = ModuleNameString.ToEnum(s1);
  566. else if (param[0] is ModuleName mod)
  567. unit = mod;
  568. else
  569. throw new ArgumentException("Argument error");
  570. return _homeRoutine.Start(unit) == RState.Running;
  571. }
  572. private bool fnHomingAlignTimeout(object[] param)
  573. {
  574. _currentRoutine = _homeRoutine;
  575. RState ret = _homeRoutine.Monitor();
  576. if (ret == RState.Failed || ret == RState.Timeout)
  577. {
  578. _currentRoutine = null;
  579. PostMsg(MSG.Error);
  580. return false;
  581. }
  582. bool result = ret == RState.End;
  583. if (result)
  584. {
  585. _currentRoutine = null;
  586. AlarmListManager.Instance.CheckModuleAlamAndRemove(Module.ToString(), STATE.Idle.ToString());
  587. }
  588. return result;
  589. }
  590. private bool fnActionDone(object[] param)
  591. {
  592. return false;
  593. }
  594. public bool CheckToPostMessage(int msg, params object[] args)
  595. {
  596. if (!fsm.FindTransition(fsm.State, msg))
  597. {
  598. LOG.Write(eEvent.WARN_EFEM_COMMON_WARN, ModuleName.EFEM, $"{Name} is in {(STATE)fsm.State} state,can not do {(MSG)msg}");
  599. return false;
  600. }
  601. Running = true;
  602. fsm.PostMsg(msg, args);
  603. return true;
  604. }
  605. private bool fnMonitor(object[] param)
  606. {
  607. if (_isVacuume)
  608. {
  609. bool result = VacuumActionTimeout();
  610. if (result)
  611. {
  612. _isVacuume = false;
  613. }
  614. }
  615. if (_isPause)
  616. {
  617. bool result = SafeOpenActionTimeout();
  618. if (result)
  619. {
  620. _isPause = false;
  621. }
  622. }
  623. // robot idle check
  624. _robotIdleTrigger.CLK = _efem.Status != RState.Running;
  625. if (_robotIdleTrigger.Q)
  626. {
  627. _robotWatch.Restart();
  628. LOG.WriteLog(eEvent.EV_EFEM_ROBOT, Module.ToString(), $"robot status changed to {_efem.Status}");
  629. }
  630. _autoMessageProcessor.Monitor();
  631. return true;
  632. }
  633. private bool fnOnline(object[] param)
  634. {
  635. bool bOnlineFlag = (bool)param[0];
  636. if (_efem is EfemBase efem)
  637. {
  638. efem.SetOnline(bOnlineFlag);
  639. }
  640. IsOnline = bOnlineFlag;
  641. return true;
  642. }
  643. private string GetFsmLastMessage()
  644. {
  645. int msg = fsm.LastMsg;
  646. if (msg >= (int)MSG.HomeAll && msg <= (int)MSG.Error)
  647. return ((MSG)msg).ToString();
  648. if (msg == (int)FSM_MSG.TIMER)
  649. return "Timer";
  650. return msg.ToString();
  651. }
  652. private bool fnError(object[] param)
  653. {
  654. _errorPreState = (STATE)fsm.State;
  655. string error = (param != null && param.Length != 0) ? param[0].ToString() : "";
  656. if (Singleton<RouteManager>.Instance.IsAutoMode)
  657. {
  658. int msg = 0;
  659. if (_errorPreState == STATE.Picking)
  660. {
  661. msg = (int)MSG.Pick;
  662. }
  663. else if (_errorPreState == STATE.Aligning)
  664. {
  665. msg = (int)MSG.Align;
  666. }
  667. else if (_errorPreState == STATE.Placing)
  668. {
  669. msg = (int)MSG.Place;
  670. }
  671. else
  672. {
  673. error = $"{error}\r\n Plase Home Robot back to idle state";
  674. return true;
  675. }
  676. AlarmList alarmList = new AlarmList(Module.ToString(), ((STATE)fsm.State).ToString(), msg,
  677. error, 0, (int)AlarmType.Error);
  678. AlarmListManager.Instance.AddAlarm(alarmList);
  679. }
  680. return true;
  681. }
  682. private bool fnToInit(object[] param)
  683. {
  684. return true;
  685. }
  686. private bool fnRecover(object[] param)
  687. {
  688. bool result=_efem.ClearError();
  689. if (result)
  690. {
  691. PostMsg(MSG.ToInit);
  692. }
  693. return result;
  694. }
  695. private bool fnAbortRobot(object[] param)
  696. {
  697. //_efem.ExecuteAction();
  698. if (_currentRoutine != null)
  699. {
  700. _currentRoutine.Abort();
  701. }
  702. _efem.Halt();
  703. return true;
  704. }
  705. private bool fnBackroundCommand(object[] param)
  706. {
  707. _autoMessageProcessor.SendAutoCommandMessage(param);
  708. return true;
  709. }
  710. private bool fnRobotPowerOn(object[] param)
  711. {
  712. return _efem.RobotPowerOn(ModuleName.EfemRobot, (bool)param[0]);
  713. }
  714. private bool fnSetLED(object[] param)
  715. {
  716. LightType light = (LightType)param[0];
  717. LightStatus st = (LightStatus)param[1];
  718. return _efem.SetLamp(light, st);
  719. }
  720. private bool fnTurnOffBuzzer(object[] param)
  721. {
  722. return false;
  723. }
  724. private bool FnStartPick(object[] param)
  725. {
  726. return _pickRoutine.Start(param) == RState.Running;
  727. }
  728. private bool FnStartRobotCycle(object[] param)
  729. {
  730. return _cycleRobotCycleRoutine.Start(param) == RState.Running;
  731. }
  732. private bool FnErrorStartPick(object[] param)
  733. {
  734. if (!_isHomed)
  735. {
  736. LOG.WriteLog(eEvent.ERR_EFEM_ROBOT, Module.ToString(), "EFEM is not homed");
  737. return false;
  738. }
  739. _efem.Reset();
  740. return _pickRoutine.Start(param) == RState.Running;
  741. }
  742. /// <summary>
  743. /// Retry Pick
  744. /// </summary>
  745. /// <param name="param"></param>
  746. /// <returns></returns>
  747. private bool RetryPick(object[] param)
  748. {
  749. int stepIndex = (int)param[0];
  750. return _pickRoutine.Retry(stepIndex) == RState.Running;
  751. }
  752. private bool FnPickTimeout(object[] param)
  753. {
  754. _currentRoutine = _pickRoutine;
  755. RState ret = _pickRoutine.Monitor();
  756. if (ret == RState.Failed || ret == RState.Timeout)
  757. {
  758. PostMsg(MSG.Error,_pickRoutine.ErrorMsg);
  759. _currentRoutine = null;
  760. return false;
  761. }
  762. if (ret == RState.End)
  763. {
  764. _currentRoutine = null;
  765. AlarmListManager.Instance.CheckModuleAlamAndRemove(Module.ToString(), STATE.Picking.ToString());
  766. }
  767. return ret == RState.End;
  768. }
  769. private bool FnRobotCycleTimeout(object[] param)
  770. {
  771. RState ret = _cycleRobotCycleRoutine.Monitor();
  772. if (ret == RState.Failed || ret == RState.Timeout)
  773. {
  774. PostMsg(MSG.Error);
  775. return false;
  776. }
  777. _currentCycleTimes = _cycleRobotCycleRoutine.GetCurrentCycle();
  778. return ret == RState.End;
  779. }
  780. private bool FnErrorPickTimeout(object[] param)
  781. {
  782. RState ret = _pickRoutine.Monitor();
  783. if (ret == RState.Failed || ret == RState.Timeout)
  784. {
  785. PostMsg(MSG.Error, _pickRoutine.ErrorMsg);
  786. return false;
  787. }
  788. return ret == RState.End;
  789. }
  790. /// <summary>
  791. /// 确认Pick是否完成
  792. /// </summary>
  793. /// <param name="param"></param>
  794. /// <returns></returns>
  795. private bool ConfirmPickup(object[] param)
  796. {
  797. int stepIdex = (int)param[0];
  798. bool result = _pickRoutine.CheckCompleteCondition(stepIdex);
  799. if (!result)
  800. {
  801. PostMsg(MSG.Error,_pickRoutine.ErrorMsg);
  802. }
  803. else
  804. {
  805. if (Singleton<RouteManager>.Instance.IsAutoRunning)
  806. {
  807. AlarmListManager.Instance.CheckModuleAlamAndRemove(Module.ToString(), STATE.Picking.ToString());
  808. }
  809. }
  810. return result;
  811. }
  812. private bool FnAbortPick(object[] param)
  813. {
  814. _pickRoutine.Abort();
  815. return true;
  816. }
  817. private bool FnAbortRobotCycle(object[] param)
  818. {
  819. _cycleRobotCycleRoutine.Abort();
  820. return true;
  821. }
  822. private bool FnErrorAbortPick(object[] param)
  823. {
  824. _pickRoutine.Abort();
  825. return true;
  826. }
  827. private bool FnStartPlace(object[] param)
  828. {
  829. return _placeRoutine.Start(param) == RState.Running;
  830. }
  831. private bool FnErrorStartPlace(object[] param)
  832. {
  833. if(!_isHomed)
  834. {
  835. LOG.WriteLog(eEvent.ERR_EFEM_ROBOT, Module.ToString(), "EFEM is not homed");
  836. return false;
  837. }
  838. _efem.Reset();
  839. return _placeRoutine.Start(param) == RState.Running;
  840. }
  841. /// <summary>
  842. /// Retry Place
  843. /// </summary>
  844. /// <param name="param"></param>
  845. /// <returns></returns>
  846. private bool RetryPlace(object[] param)
  847. {
  848. int stepIndex = (int)param[0];
  849. return _placeRoutine.Retry(stepIndex) == RState.Running;
  850. }
  851. private bool FnPlaceTimeout(object[] param)
  852. {
  853. _currentRoutine = _placeRoutine;
  854. RState ret = _placeRoutine.Monitor();
  855. if (ret == RState.Failed || ret == RState.Timeout)
  856. {
  857. _currentRoutine = null;
  858. PostMsg(MSG.Error,_placeRoutine.ErrorMsg);
  859. return false;
  860. }
  861. if (ret == RState.End)
  862. {
  863. _currentRoutine = null;
  864. AlarmListManager.Instance.CheckModuleAlamAndRemove(Module.ToString(), STATE.Placing.ToString());
  865. }
  866. return ret == RState.End;
  867. }
  868. private bool FnErrorPlaceTimeout(object[] param)
  869. {
  870. RState ret = _placeRoutine.Monitor();
  871. if (ret == RState.Failed || ret == RState.Timeout)
  872. {
  873. PostMsg(MSG.Error, _placeRoutine.ErrorMsg);
  874. return false;
  875. }
  876. return ret == RState.End;
  877. }
  878. /// <summary>
  879. /// 确认Place是否完成
  880. /// </summary>
  881. /// <param name="param"></param>
  882. /// <returns></returns>
  883. private bool ConfirmPlace(object[] param)
  884. {
  885. int stepIdex = (int)param[0];
  886. bool result = _placeRoutine.CheckCompleteCondition(stepIdex);
  887. if (!result)
  888. {
  889. PostMsg(MSG.Error, _placeRoutine.ErrorMsg);
  890. }
  891. else
  892. {
  893. if (Singleton<RouteManager>.Instance.IsAutoRunning)
  894. {
  895. AlarmListManager.Instance.CheckModuleAlamAndRemove(Module.ToString(), STATE.Picking.ToString());
  896. }
  897. }
  898. return result;
  899. }
  900. private bool FnAbortPlace(object[] param)
  901. {
  902. _placeRoutine.Abort();
  903. return true;
  904. }
  905. private bool FnErrorAbortPlace(object[] param)
  906. {
  907. _placeRoutine.Abort();
  908. return true;
  909. }
  910. private bool FnStartSwap(object[] param)
  911. {
  912. return _swapRoutine.Start(param) == RState.Running;
  913. }
  914. private bool FnSwapTimeout(object[] param)
  915. {
  916. RState ret = _swapRoutine.Monitor();
  917. if (ret == RState.Failed || ret == RState.Timeout)
  918. {
  919. PostMsg(MSG.Error);
  920. return false;
  921. }
  922. return ret == RState.End;
  923. }
  924. private bool FnAbortSwap(object[] param)
  925. {
  926. _swapRoutine.Abort();
  927. return true;
  928. }
  929. private bool fnGoto(object[] param)
  930. {
  931. // module
  932. ModuleName unit = ModuleName.EFEM;
  933. if (param[0] is string s1)
  934. unit = ModuleNameString.ToEnum(s1);
  935. else if (param[0] is ModuleName mod)
  936. unit = mod;
  937. else
  938. throw new ArgumentException("Argument error");
  939. _efem.Goto(unit, Hand.Blade1);
  940. return true;
  941. }
  942. private bool fnLift(object[] param)
  943. {
  944. // module
  945. ModuleName unit = ModuleName.EFEM;
  946. if (param[0] is string s1)
  947. unit = ModuleNameString.ToEnum(s1);
  948. else if (param[0] is ModuleName mod)
  949. unit = mod;
  950. else
  951. throw new ArgumentException("Argument error");
  952. bool isUp = true;
  953. if (param.Length > 1)
  954. {
  955. isUp = (bool) param[1];
  956. }
  957. if (isUp)
  958. {
  959. if (!_efem.SetPinUp(unit))
  960. return false;
  961. }
  962. else
  963. {
  964. if (!_efem.SetPinDown(unit))
  965. return false;
  966. }
  967. LiftMessage = isUp ? "Up" : "Down";
  968. return true;
  969. }
  970. private bool fnLiftTimeout(object[] param)
  971. {
  972. if (LiftMessage == "Up")
  973. {
  974. return _efem.LiftIsDown == false && _efem.LiftIsUp == true;
  975. }
  976. else if (LiftMessage == "Down")
  977. {
  978. return _efem.LiftIsDown == true && _efem.LiftIsUp == false;
  979. }
  980. return false;
  981. }
  982. private bool fnAlign(object[] param)
  983. {
  984. return _alignRoutine.Start(param) == RState.Running;
  985. }
  986. private bool fnAlignTimeout(object[] param)
  987. {
  988. _currentRoutine = _alignRoutine;
  989. RState ret = _alignRoutine.Monitor();
  990. if (ret == RState.Failed || ret == RState.Timeout)
  991. {
  992. _currentRoutine = null;
  993. PostMsg(MSG.Error,_alignRoutine.ErrorMsg);
  994. return false;
  995. }
  996. if (ret == RState.End)
  997. {
  998. _currentRoutine = null;
  999. AlarmListManager.Instance.CheckModuleAlamAndRemove(Module.ToString(), STATE.Aligning.ToString());
  1000. }
  1001. return ret == RState.End;
  1002. }
  1003. /// <summary>
  1004. /// Retry Align
  1005. /// </summary>
  1006. /// <param name="param"></param>
  1007. /// <returns></returns>
  1008. private bool RetryAlign(object[] param)
  1009. {
  1010. int stepIndex = (int)param[0];
  1011. return _alignRoutine.Retry(stepIndex) == RState.Running;
  1012. }
  1013. /// <summary>
  1014. /// 确认Align是否完成
  1015. /// </summary>
  1016. /// <param name="param"></param>
  1017. /// <returns></returns>
  1018. private bool ConfirmAlign(object[] param)
  1019. {
  1020. int stepIdex = (int)param[0];
  1021. bool result = _alignRoutine.CheckCompleteCondition(stepIdex);
  1022. if (!result)
  1023. {
  1024. PostMsg(MSG.Error, _alignRoutine.ErrorMsg);
  1025. }
  1026. else
  1027. {
  1028. if (Singleton<RouteManager>.Instance.IsAutoRunning)
  1029. {
  1030. AlarmListManager.Instance.CheckModuleAlamAndRemove(Module.ToString(), STATE.Aligning.ToString());
  1031. }
  1032. }
  1033. return result;
  1034. }
  1035. private bool MapDummyTimeout(object[] param)
  1036. {
  1037. RState ret = _mapDummyRoutine.Monitor();
  1038. if (ret == RState.Failed || ret == RState.Timeout)
  1039. {
  1040. PostMsg(MSG.Error);
  1041. return false;
  1042. }
  1043. return ret == RState.End;
  1044. }
  1045. private bool VacuumActionTimeout()
  1046. {
  1047. RState ret = _vacuumRoutine.Monitor();
  1048. if (ret == RState.Failed || ret == RState.Timeout)
  1049. {
  1050. LOG.Write(eEvent.ERR_EFEM_COMMON_FAILED, ModuleName.EFEM, "Vacuum");
  1051. return false;
  1052. }
  1053. return ret == RState.End;
  1054. }
  1055. private bool SafeOpenActionTimeout()
  1056. {
  1057. RState ret = _efemSafeOpenRoutine.Monitor();
  1058. if (ret == RState.Failed || ret == RState.Timeout)
  1059. {
  1060. LOG.Write(eEvent.ERR_EFEM_COMMON_FAILED, ModuleName.EFEM, "SafeOpen");
  1061. return false;
  1062. }
  1063. return ret == RState.End;
  1064. }
  1065. private bool fnMap(object[] param)
  1066. {
  1067. // module
  1068. ModuleName unit = ModuleName.EFEM;
  1069. if (param[0] is string s1)
  1070. unit = ModuleNameString.ToEnum(s1);
  1071. else if (param[0] is ModuleName mod)
  1072. unit = mod;
  1073. else
  1074. throw new ArgumentException("Argument error");
  1075. if (!_efem.Map(unit))
  1076. return false;
  1077. return true;
  1078. }
  1079. private bool MapDummy(object[] param)
  1080. {
  1081. return _mapDummyRoutine.Start()==RState.Running;
  1082. }
  1083. private bool VacuumAction(object[] param)
  1084. {
  1085. ModuleName vacuumModule = (ModuleName)param[0];
  1086. bool vacuum=(bool)param[1];
  1087. bool result = _vacuumRoutine.Start(vacuumModule, vacuum) == RState.Running;
  1088. if (result)
  1089. {
  1090. _isVacuume = true;
  1091. }
  1092. return result;
  1093. }
  1094. private bool SafeOpenAction(object[] param)
  1095. {
  1096. PostMsg(MSG.Pause);
  1097. bool result = _efemSafeOpenRoutine.Start() == RState.Running;
  1098. if (result)
  1099. {
  1100. _isPause = true;
  1101. }
  1102. return result;
  1103. }
  1104. private bool SafeCloseAction(object[] param)
  1105. {
  1106. CheckToPostMessage<STATE, MSG>(eEvent.ERR_EFEM_COMMON_FAILED, "EFEM", (int)MSG.Resume);
  1107. return _efemSafeCloseRoutine.Start() == RState.Running;
  1108. }
  1109. public bool DoorUnlock(object[] param)
  1110. {
  1111. bool unlock = (bool)param[0];
  1112. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{DOOR_UNLOCK}");
  1113. if (!string.IsNullOrEmpty(ioName))
  1114. {
  1115. return IOModuleManager.Instance.WriteIoValue(ioName, unlock);
  1116. }
  1117. return true;
  1118. }
  1119. private bool fnGrip(object[] param)
  1120. {
  1121. Hand arm = (Hand)Enum.Parse(typeof(Hand), (string)param[0]);
  1122. if (!_efem.Grip(arm, true))
  1123. return false;
  1124. return true;
  1125. }
  1126. public int SendEfemAutoCommand(params object[] args)
  1127. {
  1128. if (CheckToPostMessage((int)MSG.BackroundCmd, args))
  1129. return (int)MSG.BackroundCmd;
  1130. return (int)FSM_MSG.NONE;
  1131. }
  1132. private bool fnUngrip(object[] param)
  1133. {
  1134. Hand arm = (Hand)Enum.Parse(typeof(Hand), (string)param[0]);
  1135. if (!_efem.Grip(arm, false))
  1136. return false;
  1137. return true;
  1138. }
  1139. #region EfemRetry
  1140. /// <summary>
  1141. /// Retry
  1142. /// </summary>
  1143. /// <param name="param"></param>
  1144. /// <returns></returns>
  1145. private bool EfemRetry(object[] param)
  1146. {
  1147. AlarmList alarmList = AlarmListManager.Instance.GetAlarmListByModule(Module.ToString());
  1148. if (alarmList != null)
  1149. {
  1150. CheckToPostMessage<STATE, MSG>(eEvent.ERR_EFEM_ROBOT, Module.ToString(), alarmList.ModuleCmd,
  1151. alarmList.ModuleStep);
  1152. }
  1153. return false;
  1154. }
  1155. #endregion
  1156. #region ConfirmComplete
  1157. /// <summary>
  1158. /// 确认是否完成
  1159. /// </summary>
  1160. /// <param name="param"></param>
  1161. /// <returns></returns>
  1162. private bool ConfirmComplete(object[] param)
  1163. {
  1164. AlarmList alarmList = AlarmListManager.Instance.GetAlarmListByModule(Module.ToString());
  1165. if (alarmList != null)
  1166. {
  1167. if (alarmList.ModuleState == STATE.Picking.ToString())
  1168. {
  1169. CheckToPostMessage<STATE, MSG>(eEvent.ERR_EFEM_ROBOT, Module.ToString(), (int)MSG.Pick, alarmList.ModuleStep);
  1170. }
  1171. else if (alarmList.ModuleState == STATE.Placing.ToString())
  1172. {
  1173. CheckToPostMessage<STATE, MSG>(eEvent.ERR_EFEM_ROBOT, Module.ToString(), (int)MSG.Place, alarmList.ModuleStep);
  1174. }
  1175. else if (alarmList.ModuleState == STATE.Aligning.ToString())
  1176. {
  1177. CheckToPostMessage<STATE, MSG>(eEvent.ERR_EFEM_ROBOT, Module.ToString(), (int)MSG.Align, alarmList.ModuleStep);
  1178. }
  1179. else
  1180. {
  1181. PostMsg(PUFSTATE.Error);
  1182. }
  1183. }
  1184. return false;
  1185. }
  1186. /// <summary>
  1187. /// 清除报警
  1188. /// </summary>
  1189. /// <param name="param"></param>
  1190. /// <returns></returns>
  1191. private bool ClearModuleAlarm(object[] param)
  1192. {
  1193. AlarmList alarmList = AlarmListManager.Instance.GetAlarmListByModule(Module.ToString());
  1194. if (alarmList != null)
  1195. {
  1196. AlarmListManager.Instance.CheckModuleAlamAndRemove(Module.ToString(), "");
  1197. }
  1198. return true;
  1199. }
  1200. #endregion
  1201. public int Invoke(string function, params object[] args)
  1202. {
  1203. switch (function)
  1204. {
  1205. case "HomeAll":
  1206. if (IsIdle)
  1207. {
  1208. return (int)FSM_MSG.NONE;
  1209. }
  1210. if (CheckToPostMessage((int)MSG.HomeAll))
  1211. {
  1212. return (int)MSG.HomeAll;
  1213. }
  1214. else
  1215. {
  1216. return (int)FSM_MSG.NONE;
  1217. }
  1218. case "Retry":
  1219. if (CheckToPostMessage<STATE, MSG>(eEvent.ERR_EFEM_ROBOT, Module.ToString(), (int)MSG.Retry, args))
  1220. {
  1221. return (int)MSG.Retry;
  1222. }
  1223. else
  1224. {
  1225. return (int)FSM_MSG.NONE;
  1226. }
  1227. case "ConfirmComplete":
  1228. if (CheckToPostMessage<STATE, MSG>(eEvent.ERR_EFEM_ROBOT, Module.ToString(), (int)MSG.ConfirmComplete, args))
  1229. {
  1230. return (int)MSG.ConfirmComplete;
  1231. }
  1232. else
  1233. {
  1234. return (int)FSM_MSG.NONE;
  1235. }
  1236. }
  1237. return (int)FSM_MSG.NONE;
  1238. }
  1239. public bool CheckAcked(int msg)
  1240. {
  1241. return fsm.CheckExecuted(msg);
  1242. }
  1243. internal void InvokeReset()
  1244. {
  1245. if (fsm.State == (int) STATE.Error)
  1246. {
  1247. PostMsg((int)MSG.Recover);
  1248. }
  1249. }
  1250. public int InvokeAlign(string module, int reserv, float time)
  1251. {
  1252. if (CheckToPostMessage((int)MSG.Align, module, reserv, time))
  1253. return (int)MSG.Align;
  1254. return (int)FSM_MSG.NONE;
  1255. }
  1256. public int InvokeLiftDown(string module)
  1257. {
  1258. if (CheckToPostMessage((int)MSG.Lift, module, false))
  1259. return (int)MSG.Lift;
  1260. return (int)FSM_MSG.NONE;
  1261. }
  1262. public int InvokePick(ModuleName source, int slot, Hand hand, WaferSize size)
  1263. {
  1264. if (CheckToPostMessage((int)MSG.Pick, source, slot, hand, size))
  1265. return (int)MSG.Pick;
  1266. return (int)FSM_MSG.NONE;
  1267. }
  1268. public int InvokeGoto(ModuleName source, int slot)
  1269. {
  1270. if (CheckToPostMessage((int)MSG.Goto, source, slot))
  1271. return (int)MSG.Goto;
  1272. return (int)FSM_MSG.NONE;
  1273. }
  1274. public int InvokePlace(ModuleName target, int slot, Hand hand, WaferSize size)
  1275. {
  1276. if (CheckToPostMessage((int)MSG.Place, target, slot, hand, size))
  1277. return (int)MSG.Place;
  1278. return (int)FSM_MSG.NONE;
  1279. }
  1280. public int InvokePickAndPlace(ModuleName targetModule, Hand pickHand, int pickSlot, Hand placeHand, int placeSlot, WaferSize size)
  1281. {
  1282. if (CheckToPostMessage((int)MSG.Swap, targetModule, pickSlot, pickHand, placeHand, placeSlot, size))
  1283. return (int)MSG.Swap;
  1284. return (int)FSM_MSG.NONE;
  1285. }
  1286. public int InvokeMap(string target )
  1287. {
  1288. if (CheckToPostMessage((int)MSG.Map, target ))
  1289. return (int)MSG.Map;
  1290. return (int)FSM_MSG.NONE;
  1291. }
  1292. public int InvokeFlip(Hand hand)
  1293. {
  1294. if (CheckToPostMessage((int)MSG.Flip, hand))
  1295. return (int)MSG.Flip;
  1296. return (int)FSM_MSG.NONE;
  1297. }
  1298. public bool IsPrepareTransferReady(ModuleName module, EnumTransferType type, int slot)
  1299. {
  1300. //if (type == EnumTransferType.Pick)
  1301. //{
  1302. // //需要补充:判断LP 放好了,而且已经map过。
  1303. // return _efem[module].HasCassette && _efem[module].IsMapped;
  1304. //}
  1305. //else if (type == EnumTransferType.Place)
  1306. //{
  1307. // //需要补充:判断LP 放好了,而且已经map过。
  1308. // return _efem[module].HasCassette && _efem[module].IsMapped;
  1309. //}
  1310. return false;
  1311. }
  1312. internal bool CheckReadyRunNewJob(ModuleName module)
  1313. {
  1314. //???
  1315. return true;
  1316. }
  1317. internal bool CheckReadyTransfer(ModuleName module)
  1318. {
  1319. //return _efem[module].HasCassette && _efem[module].IsMapped;
  1320. return true;
  1321. }
  1322. internal bool CheckPlaced(ModuleName module)
  1323. {
  1324. //return _efem[module].HasCassette;
  1325. return true;
  1326. }
  1327. internal void NoteJobStart(ModuleName module)
  1328. {
  1329. //_efem[module].NoteJobStart();
  1330. }
  1331. internal void NoteJobComplete(ModuleName module)
  1332. {
  1333. //_efem[module].NoteJobComplete();
  1334. }
  1335. }
  1336. }