CarrierUnload.cs 30 KB

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