EfemEntity.cs 54 KB

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