EfemEntity.cs 48 KB

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