CarrierUnload.cs 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716
  1. using Aitex.Core.RT.Routine;
  2. using Aitex.Core.RT.SCCore;
  3. using Aitex.Core.Util;
  4. using Aitex.Sorter.Common;
  5. using MECF.Framework.Common.Equipment;
  6. using MECF.Framework.Common.Schedulers;
  7. using MECF.Framework.Common.SubstrateTrackings;
  8. using MECF.Framework.RT.EquipmentLibrary.LogicUnits;
  9. using System;
  10. using System.Collections.Generic;
  11. using FurnaceRT.Equipments.FIMSs;
  12. using FurnaceRT.Equipments.LPs;
  13. using FurnaceRT.Equipments.Stockers;
  14. using FurnaceRT.Equipments.Systems;
  15. using static FurnaceRT.Equipments.FIMSs.FIMSModule;
  16. using Aitex.Core.RT.Event;
  17. using FabConnect.SecsGemInterface.Common;
  18. using MECF.Framework.Common.FAServices;
  19. using FurnaceRT.Equipments.PMs;
  20. namespace FurnaceRT.Equipments.CarrierRobots
  21. {
  22. public class CarrierUnload : ModuleRoutine, IRoutine
  23. {
  24. enum RoutineStep
  25. {
  26. SetLPLoad,
  27. SetLPUnload,
  28. Place,
  29. DoorOpen,
  30. DoorClose,
  31. RobotRequestCassettePresent,
  32. CheckCassetteInfoByRobotSensor,
  33. SetStageLock,
  34. SetStageUnlock,
  35. CheckBeforePlace,
  36. SetRobotActionCommand,
  37. Goto,
  38. CheckGotoFinish,
  39. Delay,
  40. }
  41. private CarrierRobotModule _cassetteRobotModule;
  42. private ModuleName _destination;
  43. private int _destinationSlot;
  44. private Hand _blade;
  45. private int _timeout = 0;
  46. private RD_TRIG _holdTrig = new RD_TRIG();
  47. private R_TRIG _emergencyStopTrig = new R_TRIG();
  48. private R_TRIG _pauseTrig = new R_TRIG();
  49. private R_TRIG _resumeTrig = new R_TRIG();
  50. private RoutineStep _routineStep;
  51. private double _durationTime = 0;
  52. private bool _isHasAlarm = false;
  53. private bool _needStartCheck = true;
  54. public CarrierUnload(CarrierRobotModule cassetteModule)
  55. {
  56. _cassetteRobotModule = cassetteModule;
  57. Module = cassetteModule.Module;
  58. Name = "Unload";
  59. }
  60. public void Init(ModuleName destination, int destinationSlot, Hand blade, bool isHasAlarm)
  61. {
  62. _destination = destination;
  63. _destinationSlot = destinationSlot;
  64. _blade = blade;
  65. var para = new List<object> { _destination, _destinationSlot, _blade, true };
  66. _cassetteRobotModule.PlaceCassetteFailAlarm.RetryMessage = (int)CarrierRobotModule.MSG.UnloadRetry;
  67. _cassetteRobotModule.PlaceCassetteFailAlarm.RetryMessageParas = para.ToArray();
  68. _cassetteRobotModule.PlaceCassetteTimeoutAlarm.RetryMessage = (int)CarrierRobotModule.MSG.UnloadRetry;
  69. _cassetteRobotModule.PlaceCassetteTimeoutAlarm.RetryMessageParas = para.ToArray();
  70. _cassetteRobotModule.RequestCassettePresentFailAlarm.RetryMessage = (int)CarrierRobotModule.MSG.UnloadRetry;
  71. _cassetteRobotModule.RequestCassettePresentFailAlarm.RetryMessageParas = para.ToArray();
  72. _cassetteRobotModule.RequestCassettePresentTimeoutAlarm.RetryMessage = (int)CarrierRobotModule.MSG.UnloadRetry;
  73. _cassetteRobotModule.RequestCassettePresentTimeoutAlarm.RetryMessageParas = para.ToArray();
  74. _cassetteRobotModule.RobotHasError.RetryMessage = (int)CarrierRobotModule.MSG.UnloadRetry;
  75. _cassetteRobotModule.RobotHasError.RetryMessageParas = para.ToArray();
  76. _cassetteRobotModule.ShutterOpenTimeoutAlarm.RetryMessage = (int)CarrierRobotModule.MSG.UnloadRetry;
  77. _cassetteRobotModule.ShutterOpenTimeoutAlarm.RetryMessageParas = para.ToArray();
  78. _cassetteRobotModule.ShutterCloseTimeoutAlarm.RetryMessage = (int)CarrierRobotModule.MSG.UnloadRetry;
  79. _cassetteRobotModule.ShutterCloseTimeoutAlarm.RetryMessageParas = para.ToArray();
  80. _isHasAlarm = isHasAlarm;
  81. if (!_isHasAlarm)
  82. _needStartCheck = true;
  83. }
  84. public Result Start(params object[] objs)
  85. {
  86. // 抛出过alarm就不reset
  87. if (!_isHasAlarm)
  88. {
  89. Reset();
  90. }
  91. else
  92. {
  93. _historySteps.Remove((int)_routineStep);
  94. _isHasAlarm = false;
  95. ResetState();
  96. }
  97. _holdTrig.RST = true;
  98. _emergencyStopTrig.RST = true;
  99. _pauseTrig.RST = true;
  100. _resumeTrig.RST = true;
  101. _timeout = SC.GetValue<int>($"{Module}.MotionTimeout");
  102. if (_needStartCheck)
  103. {
  104. if (!Singleton<EquipmentManager>.Instance.Modules.ContainsKey(_destination))
  105. {
  106. _cassetteRobotModule.PlaceCassetteFailAlarm.Set($"place to {_destination} failed for not install");
  107. return Result.FAIL;
  108. }
  109. if (ModuleHelper.IsLoadPort(_destination))
  110. {
  111. var lpModule = Singleton<EquipmentManager>.Instance.Modules[_destination] as LoadPortModule;
  112. if (lpModule == null)
  113. {
  114. _cassetteRobotModule.PlaceCassetteFailAlarm.Set($"place to {_destination} failed for not install");
  115. return Result.FAIL;
  116. }
  117. if (lpModule != null && !lpModule.CheckReadyForTransfer(ModuleHelper.Converter(Module), _blade, _destinationSlot, EnumTransferType.Place, out string reason))
  118. {
  119. _cassetteRobotModule.PlaceCassetteFailAlarm.Set($"place to {_destination} failed for {reason}");
  120. return Result.FAIL;
  121. }
  122. }
  123. else if (_destination == ModuleName.FIMS1 || _destination == ModuleName.FIMS2)
  124. {
  125. var fims = Singleton<EquipmentManager>.Instance.Modules[_destination] as FIMSModule;
  126. if (fims == null)
  127. {
  128. _cassetteRobotModule.PlaceCassetteFailAlarm.Set($"place to {_destination} failed for not install");
  129. return Result.FAIL;
  130. }
  131. if (fims != null && !fims.CheckReadyForTransfer(ModuleHelper.Converter(Module), _blade, _destinationSlot, EnumTransferType.Place, out string reason))
  132. {
  133. _cassetteRobotModule.PlaceCassetteFailAlarm.Set($"place to {_destination} failed for {reason}");
  134. return Result.FAIL;
  135. }
  136. if (!SC.GetValue<bool>("System.IsSimulatorMode"))
  137. {
  138. if (fims != null && fims.IsFoupExist)
  139. {
  140. _cassetteRobotModule.PlaceCassetteFailAlarm.Set($"place to {_destination} failed for carrier is present");
  141. return Result.FAIL;
  142. }
  143. }
  144. }
  145. else
  146. {
  147. var stockerModule = Singleton<EquipmentManager>.Instance.Modules[_destination] as StockerModule;
  148. if (stockerModule == null)
  149. {
  150. _cassetteRobotModule.PlaceCassetteFailAlarm.Set($"place to {_destination} failed for not install");
  151. return Result.FAIL;
  152. }
  153. if (!SC.GetValue<bool>("System.IsSimulatorMode"))
  154. {
  155. if (stockerModule != null && stockerModule.IsFoupPresent)
  156. {
  157. _cassetteRobotModule.PlaceCassetteFailAlarm.Set($"place to {_destination} failed for carrier is present");
  158. return Result.FAIL;
  159. }
  160. }
  161. }
  162. if (SC.GetValue<bool>("System.IsSimulatorMode"))
  163. {
  164. if (!CarrierManager.Instance.CheckHasCarrier(ModuleName.CarrierRobot, 0))
  165. {
  166. _cassetteRobotModule.BladeCassetteNotPresentWarning.Set($"{ModuleName.CarrierRobot} cassette not present");
  167. return Result.FAIL;
  168. }
  169. }
  170. else
  171. {
  172. if (!_cassetteRobotModule.CarrierRobotDevice.IsWaferPresenceOnBlade1 || !CarrierManager.Instance.CheckHasCarrier(ModuleName.CarrierRobot, 0))
  173. {
  174. _cassetteRobotModule.BladeCassetteNotPresentWarning.Set($"{ModuleName.CarrierRobot} cassette not present");
  175. return Result.FAIL;
  176. }
  177. }
  178. if (!CarrierManager.Instance.CheckNoCarrier(_destination, 0))
  179. {
  180. _cassetteRobotModule.PlaceCassetteFailAlarm.Set($"place to {_destination} failed for carrier is present");
  181. return Result.FAIL;
  182. }
  183. }
  184. Notify($"Start");
  185. return Result.RUN;
  186. }
  187. public void Abort()
  188. {
  189. _cassetteRobotModule.ResetRobotActionCommand();
  190. _cassetteRobotModule.Stop();
  191. (Singleton<EquipmentManager>.Instance.Modules[_destination] as ITransferTarget)?.NoteTransferStop(ModuleHelper.Converter(_cassetteRobotModule.Module), _blade, _destinationSlot, EnumTransferType.Place);
  192. }
  193. public override Result Monitor()
  194. {
  195. try
  196. {
  197. PauseRountine(_cassetteRobotModule.CarrierRobotDevice.IsPause);
  198. if (_cassetteRobotModule.CarrierRobotDevice.IsPause)
  199. return Result.RUN;
  200. CheckBeforePlace((int)RoutineStep.CheckBeforePlace, _destination, _destinationSlot, _blade);
  201. Goto((int)RoutineStep.Goto, _destination, _destinationSlot, _blade, true, _timeout);
  202. if (_destination == ModuleName.LP1 || _destination == ModuleName.LP2)
  203. {
  204. SaferDoorOpen((int)RoutineStep.DoorOpen, true, _timeout);
  205. SetLPLoad((int)RoutineStep.SetLPLoad, _destination, _timeout);
  206. }
  207. else if (_destination == ModuleName.LP3 || _destination == ModuleName.LP4)
  208. {
  209. SetLPLoad((int)RoutineStep.SetLPLoad, _destination, _timeout);
  210. }
  211. CheckGotoFinish((int)RoutineStep.CheckGotoFinish, _destination, _timeout);
  212. if (_cassetteRobotModule.TrigActionCommand != null)
  213. SetRobotActionCommand((int)RoutineStep.SetRobotActionCommand, _destination, _timeout);
  214. Place((int)RoutineStep.Place, _destination, _destinationSlot, _blade, _timeout);
  215. if (_destination == ModuleName.LP1 || _destination == ModuleName.LP2)
  216. {
  217. SetLPUnload((int)RoutineStep.SetLPUnload, _destination, _timeout);
  218. SaferDoorOpen((int)RoutineStep.DoorClose, false, _timeout);
  219. }
  220. else if (_destination == ModuleName.LP3 || _destination == ModuleName.LP4)
  221. {
  222. SetLPUnload((int)RoutineStep.SetLPUnload, _destination, _timeout);
  223. }
  224. RobotRequestCassettePresent((int)RoutineStep.RobotRequestCassettePresent, _blade, _timeout);
  225. CheckCassetteInfoByRobotSensor((int)RoutineStep.CheckCassetteInfoByRobotSensor, _blade, false);
  226. if (SC.ContainsItem("System.AddRobotDelay") && SC.ContainsItem("System.RobotDelayTime") && SC.GetValue<bool>("System.AddRobotDelay"))
  227. Delay((int)RoutineStep.Delay, float.Parse(SC.GetStringValue("System.RobotDelayTime")));
  228. }
  229. catch (RoutineBreakException)
  230. {
  231. return Result.RUN;
  232. }
  233. catch (RoutineFaildException ex)
  234. {
  235. _cassetteRobotModule.ResetRobotActionCommand();
  236. (Singleton<EquipmentManager>.Instance.Modules[_destination] as ITransferTarget)?.NoteTransferStop(ModuleHelper.Converter(_cassetteRobotModule.Module), _blade, _destinationSlot, EnumTransferType.Place);
  237. return Result.FAIL;
  238. }
  239. if (SC.GetValue<bool>("System.IsSimulatorMode"))
  240. CarrierManager.Instance.DeleteCarrier(_destination.ToString());
  241. _cassetteRobotModule.ResetRobotActionCommand();
  242. (Singleton<EquipmentManager>.Instance.Modules[_destination] as ITransferTarget)?.NoteTransferStop(ModuleHelper.Converter(_cassetteRobotModule.Module), _blade, _destinationSlot, EnumTransferType.Place);
  243. Notify("Finished");
  244. return Result.DONE;
  245. }
  246. private void SetRobotActionCommand(int id, ModuleName source, int timeout)
  247. {
  248. _routineStep = (RoutineStep)Enum.Parse(typeof(RoutineStep), id.ToString());
  249. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  250. {
  251. Notify($"Set robot action command target position {source}");
  252. _cassetteRobotModule.SetRobotActionCommand(source, EnumTransferType.Place);
  253. return true;
  254. }, () =>
  255. {
  256. return _cassetteRobotModule.CheckRobotActionCommand(source, EnumTransferType.Place);
  257. }, timeout * 1000);
  258. if (ret.Item1)
  259. {
  260. if (ret.Item2 == Result.FAIL)
  261. {
  262. _cassetteRobotModule.PlaceCassetteTimeoutAlarm.Set($"place to {source} failed for robot action command interlock");
  263. throw (new RoutineFaildException());
  264. }
  265. else if (ret.Item2 == Result.TIMEOUT) //timeout
  266. {
  267. _cassetteRobotModule.PlaceCassetteTimeoutAlarm.Set($"timeout over {timeout} seconds");
  268. throw (new RoutineFaildException());
  269. }
  270. else
  271. throw (new RoutineBreakException());
  272. }
  273. }
  274. private void SetLPLoad(int id, ModuleName source, int timeout)
  275. {
  276. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  277. {
  278. Notify($"Set {source} load");
  279. var lp = Singleton<EquipmentManager>.Instance.Modules[source] as LoadPortModule;
  280. if (lp != null)
  281. lp.LPDevice.Load(out string reason);
  282. return true;
  283. }, () =>
  284. {
  285. return true;
  286. }, timeout * 1000);
  287. if (ret.Item1)
  288. {
  289. if (ret.Item2 == Result.FAIL)
  290. {
  291. throw (new RoutineFaildException());
  292. }
  293. else if (ret.Item2 == Result.TIMEOUT) //timeout
  294. {
  295. throw (new RoutineFaildException());
  296. }
  297. else
  298. throw (new RoutineBreakException());
  299. }
  300. }
  301. private void SetLPUnload(int id, ModuleName source, int timeout)
  302. {
  303. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  304. {
  305. Notify($"Set {source} unload");
  306. var lp = Singleton<EquipmentManager>.Instance.Modules[source] as LoadPortModule;
  307. if (lp != null)
  308. {
  309. var lpCarrierInfo = CarrierManager.Instance.GetCarrier(source, 0);
  310. if (lpCarrierInfo != null)
  311. {
  312. (Singleton<EquipmentManager>.Instance.Modules[ModuleName.PM1] as PMModule).CarrierOutEnd(lpCarrierInfo, source.ToString().Replace("LP", "").ToString());
  313. }
  314. lp.LPDevice.Unload(out string reason);
  315. }
  316. return true;
  317. }, () =>
  318. {
  319. return true;
  320. }, timeout * 1000);
  321. if (ret.Item1)
  322. {
  323. if (ret.Item2 == Result.FAIL)
  324. {
  325. throw (new RoutineFaildException());
  326. }
  327. else if (ret.Item2 == Result.TIMEOUT) //timeout
  328. {
  329. throw (new RoutineFaildException());
  330. }
  331. else
  332. throw (new RoutineBreakException());
  333. }
  334. }
  335. private void Place(int id, ModuleName target, int slot, Hand hand, int timeout)
  336. {
  337. _routineStep = (RoutineStep)Enum.Parse(typeof(RoutineStep), id.ToString());
  338. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  339. {
  340. Notify($"Send place to {target} command to robot device");
  341. string reason;
  342. (Singleton<EquipmentManager>.Instance.Modules[target] as ITransferTarget)?.NoteTransferStart(ModuleHelper.Converter(_cassetteRobotModule.Module), hand, slot, EnumTransferType.Place);
  343. if (!_cassetteRobotModule.RobotPlace(target, slot, hand, out reason))
  344. {
  345. //_cassetteRobotModule.PlaceCassetteFailAlarm.Description = reason;
  346. _cassetteRobotModule.PlaceCassetteFailAlarm.Set(reason);
  347. return false;
  348. }
  349. return true;
  350. }, () =>
  351. {
  352. if (_cassetteRobotModule.CarrierRobotDevice.IsReady() && !_cassetteRobotModule.CarrierRobotDevice.IsError)
  353. {
  354. return true;
  355. }
  356. return false;
  357. }, timeout * 1000);
  358. if (ret.Item1)
  359. {
  360. if (ret.Item2 == Result.FAIL)
  361. {
  362. //_cassetteRobotModule.PlaceCassetteFailAlarm.Description = $"{_cassetteRobotModule.CassetteRobotDevice.ErrorCode}";
  363. _cassetteRobotModule.PlaceCassetteFailAlarm.Set($"place to {target} failed for robot error, error code={_cassetteRobotModule.CarrierRobotDevice.ErrorCode}");
  364. throw (new RoutineFaildException());
  365. }
  366. else if (ret.Item2 == Result.TIMEOUT) //timeout
  367. {
  368. //_cassetteRobotModule.PlaceCassetteTimeoutAlarm.Description = $"timeout over {timeout} seconds";
  369. _cassetteRobotModule.PlaceCassetteTimeoutAlarm.Set($"timeout over {timeout} seconds");
  370. throw (new RoutineFaildException());
  371. }
  372. else
  373. throw (new RoutineBreakException());
  374. }
  375. }
  376. private void RobotRequestCassettePresent(int id, Hand hand, int timeout)
  377. {
  378. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  379. {
  380. Notify("Request cassette present");
  381. if (!_cassetteRobotModule.RequestCassettePresent(hand, out string reason))
  382. {
  383. //_cassetteRobotModule.RequestCassettePresentFailAlarm.Description = reason;
  384. _cassetteRobotModule.RequestCassettePresentFailAlarm.Set(reason);
  385. return false;
  386. }
  387. return true;
  388. }, () =>
  389. {
  390. if (_cassetteRobotModule.CarrierRobotDevice.IsReady() && !_cassetteRobotModule.CarrierRobotDevice.IsError)
  391. {
  392. return true;
  393. }
  394. return false;
  395. }, timeout * 1000);
  396. if (ret.Item1)
  397. {
  398. if (ret.Item2 == Result.FAIL)
  399. {
  400. throw (new RoutineFaildException());
  401. }
  402. else if (ret.Item2 == Result.TIMEOUT) //timeout
  403. {
  404. //_cassetteRobotModule.RequestCassettePresentTimeoutAlarm.Description = $"timeout over {timeout} seconds";
  405. _cassetteRobotModule.RequestCassettePresentTimeoutAlarm.Set($"timeout over {timeout} seconds");
  406. throw (new RoutineFaildException());
  407. }
  408. else
  409. throw (new RoutineBreakException());
  410. }
  411. }
  412. private void CheckCassetteInfoByRobotSensor(int id, Hand hand, bool isAfterPick)
  413. {
  414. Tuple<bool, Result> ret = Execute(id, () =>
  415. {
  416. Notify($"Check cassette info by robot RQ present");
  417. if (SC.GetValue<bool>("System.IsSimulatorMode"))
  418. return true;
  419. if (hand == Hand.Blade1 || hand == Hand.Both)
  420. {
  421. if (!isAfterPick && _cassetteRobotModule.CarrierRobotDevice.IsWaferPresenceOnBlade1)
  422. {
  423. //_cassetteRobotModule.RobotSensorFoundCassetteOnBladeAfterPlaceAlarm.Description = "Cassette Robot sensor found cassette on blade 1";
  424. _cassetteRobotModule.RobotSensorFoundCassetteOnBladeAfterPlaceAlarm.Set("Cassette Robot sensor found cassette on blade 1");
  425. return false;
  426. }
  427. if (isAfterPick && !_cassetteRobotModule.CarrierRobotDevice.IsWaferPresenceOnBlade1)
  428. {
  429. //_cassetteRobotModule.RobotSensorNotFoundCassetteOnBladeAfterPickAlarm.Description = "Cassette Robot sensor no cassette on blade 1";
  430. _cassetteRobotModule.RobotSensorNotFoundCassetteOnBladeAfterPickAlarm.Set("Cassette Robot sensor no cassette on blade 1");
  431. return false;
  432. }
  433. }
  434. if (hand == Hand.Blade2 || hand == Hand.Both)
  435. {
  436. if (!isAfterPick && _cassetteRobotModule.CarrierRobotDevice.IsWaferPresenceOnBlade2)
  437. {
  438. //_cassetteRobotModule.RobotSensorFoundCassetteOnBladeAfterPlaceAlarm.Description = "Cassette Robot sensor found cassette on blade 2";
  439. _cassetteRobotModule.RobotSensorFoundCassetteOnBladeAfterPlaceAlarm.Set("Cassette Robot sensor found cassette on blade 2");
  440. return false;
  441. }
  442. if (isAfterPick && !_cassetteRobotModule.CarrierRobotDevice.IsWaferPresenceOnBlade2)
  443. {
  444. //_cassetteRobotModule.RobotSensorNotFoundCassetteOnBladeAfterPickAlarm.Description = "Cassette Robot sensor no cassette on blade 2";
  445. _cassetteRobotModule.RobotSensorNotFoundCassetteOnBladeAfterPickAlarm.Set("Cassette Robot sensor no cassette on blade 2");
  446. return false;
  447. }
  448. }
  449. return true;
  450. });
  451. if (ret.Item1)
  452. {
  453. if (ret.Item2 == Result.FAIL)
  454. {
  455. //_cassetteRobotModule.CheckCassetteInformationFailAlarm.Description = $"check cassette info failed.";
  456. _cassetteRobotModule.CheckCassetteInformationFailAlarm.Set($"check cassette info failed.");
  457. throw (new RoutineFaildException());
  458. }
  459. else
  460. throw (new RoutineBreakException());
  461. }
  462. }
  463. private void CheckBeforePlace(int id, ModuleName target, int slot, Hand blade)
  464. {
  465. Tuple<bool, Result> ret = Execute(id, () =>
  466. {
  467. Notify($"Check place to {target} condition");
  468. string reason = string.Empty;
  469. if (_cassetteRobotModule.CarrierRobotDevice.IsError)
  470. {
  471. _cassetteRobotModule.PlaceCassetteFailAlarm.Set($"place to {target} failed for robot error, error code={_cassetteRobotModule.CarrierRobotDevice.ErrorCode}");
  472. return false;
  473. }
  474. if (!_cassetteRobotModule.CarrierRobotDevice.IsReady())
  475. {
  476. _cassetteRobotModule.PlaceCassetteFailAlarm.Set($"place to {target} failed for robot isn't Ready");
  477. return false;
  478. }
  479. if (!CarrierManager.Instance.CheckNoCarrier(_destination, 0))
  480. {
  481. _cassetteRobotModule.PlaceCassetteFailAlarm.Set($"place to {_destination} failed for pod is present");
  482. return false;
  483. }
  484. if (blade == Hand.Blade1)
  485. {
  486. if (!CarrierManager.Instance.CheckNoCarrier(target, 0))
  487. {
  488. _cassetteRobotModule.PlaceCassetteFailAlarm.Set($"place to {target} failed for {target} has carrier");
  489. return false;
  490. }
  491. if (!CarrierManager.Instance.CheckHasCarrier(Module, 0))
  492. {
  493. _cassetteRobotModule.PlaceCassetteFailAlarm.Set($"place to {target} failed for blade no carrier");
  494. return false;
  495. }
  496. }
  497. else if (blade == Hand.Blade2)
  498. {
  499. if (!CarrierManager.Instance.CheckNoCarrier(target, 0))
  500. {
  501. _cassetteRobotModule.PlaceCassetteFailAlarm.Set($"place to {target} failed for {target} has carrier");
  502. return false;
  503. }
  504. if (!CarrierManager.Instance.CheckHasCarrier(Module, 0))
  505. {
  506. _cassetteRobotModule.PlaceCassetteFailAlarm.Set($"place to {target} failed for blade no carrier");
  507. return false;
  508. }
  509. }
  510. else
  511. {
  512. if (!CarrierManager.Instance.CheckNoCarrier(target, 0))
  513. {
  514. _cassetteRobotModule.PlaceCassetteFailAlarm.Set($"place to {target} failed for {target} has carrier");
  515. return false;
  516. }
  517. if (!CarrierManager.Instance.CheckHasCarrier(Module, 0))
  518. {
  519. _cassetteRobotModule.PlaceCassetteFailAlarm.Set($"place to {target} failed for blade no carrier");
  520. return false;
  521. }
  522. }
  523. return true;
  524. });
  525. if (ret.Item1)
  526. {
  527. if (ret.Item2 == Result.FAIL)
  528. {
  529. throw (new RoutineFaildException());
  530. }
  531. }
  532. _needStartCheck = false;
  533. }
  534. private void Goto(int id, ModuleName target, int slot, Hand hand, bool isPickReady, int timeout)
  535. {
  536. _routineStep = (RoutineStep)Enum.Parse(typeof(RoutineStep), id.ToString());
  537. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  538. {
  539. Notify($"Send goto to {target} command to robot device");
  540. string reason;
  541. _cassetteRobotModule.RobotGoto(target, slot, hand, isPickReady, out reason);
  542. return true;
  543. }, () =>
  544. {
  545. return true;
  546. }, timeout * 1000);
  547. if (ret.Item1)
  548. {
  549. if (ret.Item2 == Result.FAIL)
  550. {
  551. _cassetteRobotModule.GotoFailAlarm.Set($"goto to {target} failed for robot error, error code={_cassetteRobotModule.CarrierRobotDevice.ErrorCode}");
  552. throw (new RoutineFaildException());
  553. }
  554. else if (ret.Item2 == Result.TIMEOUT) //timeout
  555. {
  556. _cassetteRobotModule.GotoTimeoutAlarm.Set($"timeout over {timeout} seconds");
  557. throw (new RoutineFaildException());
  558. }
  559. else
  560. throw (new RoutineBreakException());
  561. }
  562. }
  563. private void CheckGotoFinish(int id, ModuleName target, int timeout)
  564. {
  565. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  566. {
  567. Notify($"Check goto to {target} command finish");
  568. return true;
  569. }, () =>
  570. {
  571. if (_cassetteRobotModule.CarrierRobotDevice.IsError)
  572. return null;
  573. if (_cassetteRobotModule.CarrierRobotDevice.IsReady() && !_cassetteRobotModule.CarrierRobotDevice.IsError)
  574. {
  575. return true;
  576. }
  577. return false;
  578. }, timeout * 1000);
  579. if (ret.Item1)
  580. {
  581. if (ret.Item2 == Result.FAIL)
  582. {
  583. _cassetteRobotModule.GotoFailAlarm.Set($"goto to {target} failed for robot error, error code={_cassetteRobotModule.CarrierRobotDevice.ErrorCode}");
  584. throw (new RoutineFaildException());
  585. }
  586. else if (ret.Item2 == Result.TIMEOUT) //timeout
  587. {
  588. _cassetteRobotModule.GotoTimeoutAlarm.Set($"timeout over {timeout} seconds");
  589. throw (new RoutineFaildException());
  590. }
  591. else
  592. throw (new RoutineBreakException());
  593. }
  594. }
  595. private void SaferDoorOpen(int id, bool isOpen, int timeout)
  596. {
  597. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  598. {
  599. Notify($"Shutter Door {(isOpen ? "Open" : "Close")}");
  600. if (isOpen)
  601. _cassetteRobotModule.DoorDevice.Open();
  602. else
  603. _cassetteRobotModule.DoorDevice.Close();
  604. if (isOpen)
  605. (Singleton<EquipmentManager>.Instance.Modules[_destination] as LoadPortModule)?.LPDevice.Unclamp(out _);
  606. return true;
  607. }, () =>
  608. {
  609. return isOpen ? _cassetteRobotModule.DoorDevice.OpenCloseStatus == Devices.DeviceStatus.Open && (Singleton<EquipmentManager>.Instance.Modules[_destination] as LoadPortModule).IsReleased : _cassetteRobotModule.DoorDevice.OpenCloseStatus == Devices.DeviceStatus.Close;
  610. }, timeout * 1000);
  611. if (ret.Item1)
  612. {
  613. if (ret.Item2 == Result.FAIL)
  614. {
  615. throw new RoutineFaildException();
  616. }
  617. else if (ret.Item2 == Result.TIMEOUT) //timeout
  618. {
  619. if (isOpen)
  620. _cassetteRobotModule.ShutterOpenTimeoutAlarm.Set($"timeout over {timeout} seconds");
  621. else
  622. _cassetteRobotModule.ShutterCloseTimeoutAlarm.Set($"timeout over {timeout} seconds");
  623. throw (new RoutineFaildException());
  624. }
  625. else
  626. throw new RoutineBreakException();
  627. }
  628. }
  629. }
  630. }