EfemEntity.cs 50 KB

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