EfemEntity.cs 47 KB

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