EfemEntity.cs 51 KB

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