CarrierLoad.cs 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845
  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 FurnaceRT.Equipments.WaferRobots;
  16. using static FurnaceRT.Equipments.FIMSs.FIMSModule;
  17. namespace FurnaceRT.Equipments.CarrierRobots
  18. {
  19. public class CarrierLoad : ModuleRoutine, IRoutine
  20. {
  21. enum RoutineStep
  22. {
  23. SetLPLoad,
  24. SetLPUnload,
  25. Pick,
  26. DoorOpen,
  27. DoorClose,
  28. RobotRequestCassettePresent,
  29. CheckCassetteInfoByRobotSensor,
  30. ReadCarrierID,
  31. CheckCarrierID,
  32. CheckBeforePick,
  33. SetRobotActionCommand,
  34. Goto,
  35. Delay,
  36. CheckGotoFinish,
  37. CheckRobotIsReady,
  38. }
  39. private CarrierRobotModule _cassetteRobotModule;
  40. private ModuleName _source;
  41. private ModuleName _destinationStocker;
  42. private int _sourceSlot;
  43. private Hand _blade;
  44. private int _timeout = 0;
  45. private RD_TRIG _holdTrig = new RD_TRIG();
  46. private R_TRIG _emergencyStopTrig = new R_TRIG();
  47. private R_TRIG _pauseTrig = new R_TRIG();
  48. private R_TRIG _resumeTrig = new R_TRIG();
  49. private RoutineStep _routineStep;
  50. private double _durationTime = 0;
  51. private bool _isHasAlarm = false;
  52. private bool _needStartCheck = true;
  53. private CarrierType _carrierType;
  54. private string _reservedCarrierId;
  55. private string _readCarrierId;
  56. private string _currentCarrierId;
  57. private string _bypassReadID;
  58. private string _carrierIDReaderSetting;
  59. public CarrierLoad(CarrierRobotModule cassetteModule)
  60. {
  61. _cassetteRobotModule = cassetteModule;
  62. Module = cassetteModule.Module;
  63. Name = "Load";
  64. }
  65. public void Init(ModuleName source, int sourceSlot, Hand blade, ModuleName destinationStocker,
  66. CarrierType carrierType, string reservedCarrierId, bool isHasAlarm)
  67. {
  68. _source = source;
  69. _sourceSlot = sourceSlot;
  70. _blade = blade;
  71. _destinationStocker = destinationStocker;
  72. _carrierType = carrierType;
  73. _reservedCarrierId = reservedCarrierId;
  74. var para = new List<object> { _source, _sourceSlot, _blade, destinationStocker, _carrierType, _reservedCarrierId, true };
  75. _cassetteRobotModule.PickCassetteTimeoutAlarm.RetryMessage = (int)CarrierRobotModule.MSG.LoadRetry;
  76. _cassetteRobotModule.PickCassetteTimeoutAlarm.RetryMessageParas = para.ToArray();
  77. _cassetteRobotModule.PickCassetteFailAlarm.RetryMessage = (int)CarrierRobotModule.MSG.LoadRetry;
  78. _cassetteRobotModule.PickCassetteFailAlarm.RetryMessageParas = para.ToArray();
  79. _cassetteRobotModule.RequestCassettePresentFailAlarm.RetryMessage = (int)CarrierRobotModule.MSG.LoadRetry;
  80. _cassetteRobotModule.RequestCassettePresentFailAlarm.RetryMessageParas = para.ToArray();
  81. _cassetteRobotModule.RequestCassettePresentTimeoutAlarm.RetryMessage = (int)CarrierRobotModule.MSG.LoadRetry;
  82. _cassetteRobotModule.RequestCassettePresentTimeoutAlarm.RetryMessageParas = para.ToArray();
  83. _cassetteRobotModule.SetStageValveFailAlarm.RetryMessage = (int)CarrierRobotModule.MSG.LoadRetry;
  84. _cassetteRobotModule.SetStageValveFailAlarm.RetryMessageParas = para.ToArray();
  85. _cassetteRobotModule.SetStageValveTimeout.RetryMessage = (int)CarrierRobotModule.MSG.LoadRetry;
  86. _cassetteRobotModule.SetStageValveTimeout.RetryMessageParas = para.ToArray();
  87. _cassetteRobotModule.RobotHasError.RetryMessage = (int)CarrierRobotModule.MSG.LoadRetry;
  88. _cassetteRobotModule.RobotHasError.RetryMessageParas = para.ToArray();
  89. _cassetteRobotModule.ShutterOpenTimeoutAlarm.RetryMessage = (int)CarrierRobotModule.MSG.LoadRetry;
  90. _cassetteRobotModule.ShutterOpenTimeoutAlarm.RetryMessageParas = para.ToArray();
  91. _cassetteRobotModule.ShutterCloseTimeoutAlarm.RetryMessage = (int)CarrierRobotModule.MSG.LoadRetry;
  92. _cassetteRobotModule.ShutterCloseTimeoutAlarm.RetryMessageParas = para.ToArray();
  93. _isHasAlarm = isHasAlarm;
  94. if (!_isHasAlarm)
  95. _needStartCheck = true;
  96. }
  97. public Result Start(params object[] objs)
  98. {
  99. // 抛出过alarm就不reset
  100. if (!_isHasAlarm)
  101. {
  102. Reset();
  103. }
  104. else
  105. {
  106. _historySteps.Remove((int)_routineStep);
  107. _isHasAlarm = false;
  108. ResetState();
  109. }
  110. _holdTrig.RST = true;
  111. _emergencyStopTrig.RST = true;
  112. _pauseTrig.RST = true;
  113. _resumeTrig.RST = true;
  114. _currentCarrierId = "";
  115. _timeout = SC.GetValue<int>($"{Module}.MotionTimeout");
  116. _bypassReadID = SC.GetStringValue($"LoadPort.{_source}.BypassReadID");
  117. _carrierIDReaderSetting = SC.GetStringValue($"LoadPort.{_source}.CarrierIDReaderSetting");
  118. if (_carrierIDReaderSetting == "UseReservedID")
  119. _currentCarrierId = _reservedCarrierId;
  120. if ((Singleton<EquipmentManager>.Instance.Modules[_source] as LoadPortModule).LPDevice.IsFoupPresent)
  121. {
  122. if (!CarrierManager.Instance.CheckNoCarrier(_source.ToString(), 0))
  123. CarrierManager.Instance.DeleteCarrier(_source.ToString());
  124. CarrierManager.Instance.CreateCarrier(_source.ToString(), _carrierType, _destinationStocker.ToString());
  125. }
  126. if (_needStartCheck)
  127. {
  128. if (!Singleton<EquipmentManager>.Instance.Modules.ContainsKey(_source))
  129. {
  130. _cassetteRobotModule.PlaceCassetteFailAlarm.Set($"pick from {_source} failed for not install");
  131. return Result.FAIL;
  132. }
  133. if (ModuleHelper.IsLoadPort(_source))
  134. {
  135. var lpModule = Singleton<EquipmentManager>.Instance.Modules[_source] as LoadPortModule;
  136. if (lpModule == null)
  137. {
  138. _cassetteRobotModule.PickCassetteFailAlarm.Set($"pick from {_source} failed for not install");
  139. return Result.FAIL;
  140. }
  141. if (lpModule != null && !lpModule.CheckReadyForTransfer(ModuleHelper.Converter(Module), _blade, _sourceSlot, EnumTransferType.Pick, out string reason))
  142. {
  143. _cassetteRobotModule.PickCassetteFailAlarm.Set($"pick from {_source} failed for {reason}");
  144. return Result.FAIL;
  145. }
  146. }
  147. else if (_source == ModuleName.FIMS1 || _source == ModuleName.FIMS2)
  148. {
  149. var fims = Singleton<EquipmentManager>.Instance.Modules[_source] as FIMSModule;
  150. if (fims == null)
  151. {
  152. _cassetteRobotModule.PickCassetteFailAlarm.Set($"pick from {_source} failed for not install");
  153. return Result.FAIL;
  154. }
  155. if (fims != null && !fims.CheckReadyForTransfer(ModuleHelper.Converter(Module), _blade, _sourceSlot, EnumTransferType.Pick, out string reason))
  156. {
  157. _cassetteRobotModule.PickCassetteFailAlarm.Set($"pick from {_source} failed for {reason}");
  158. return Result.FAIL;
  159. }
  160. if (!SC.GetValue<bool>("System.IsSimulatorMode"))
  161. {
  162. if (fims != null && !fims.IsFoupExist)
  163. {
  164. _cassetteRobotModule.PickCassetteFailAlarm.Set($"pick from {_source} failed for cassette is not present");
  165. return Result.FAIL;
  166. }
  167. }
  168. }
  169. else
  170. {
  171. var stockerModule = Singleton<EquipmentManager>.Instance.Modules[_source] as StockerModule;
  172. if (stockerModule == null)
  173. {
  174. _cassetteRobotModule.PickCassetteFailAlarm.Set($"pick from {_source} failed for not install");
  175. return Result.FAIL;
  176. }
  177. if (!SC.GetValue<bool>("System.IsSimulatorMode"))
  178. {
  179. if (stockerModule != null && !stockerModule.IsFoupPresent)
  180. {
  181. _cassetteRobotModule.PickCassetteFailAlarm.Set($"pick from {_source} failed for cassette is not present");
  182. return Result.FAIL;
  183. }
  184. }
  185. }
  186. if (SC.GetValue<bool>("System.IsSimulatorMode"))
  187. {
  188. if (!CarrierManager.Instance.CheckNoCarrier(ModuleName.CarrierRobot, 0))
  189. {
  190. _cassetteRobotModule.BladeCassettePresentWarning.Set($"{ModuleName.CarrierRobot} cassette present");
  191. return Result.FAIL;
  192. }
  193. }
  194. else
  195. {
  196. if (_cassetteRobotModule.CarrierRobotDevice.IsWaferPresenceOnBlade1 || !CarrierManager.Instance.CheckNoCarrier(ModuleName.CarrierRobot, 0))
  197. {
  198. _cassetteRobotModule.BladeCassettePresentWarning.Set($"{ModuleName.CarrierRobot} cassette present");
  199. return Result.FAIL;
  200. }
  201. }
  202. if (!CarrierManager.Instance.CheckHasCarrier(_source, 0))
  203. {
  204. _cassetteRobotModule.PickCassetteFailAlarm.Set($"pick from {_source} failed for cassette is not present");
  205. return Result.FAIL;
  206. }
  207. }
  208. Notify($"Start");
  209. return Result.RUN;
  210. }
  211. public void Abort()
  212. {
  213. _cassetteRobotModule.ResetRobotActionCommand();
  214. _cassetteRobotModule.Stop();
  215. (Singleton<EquipmentManager>.Instance.Modules[_source] as ITransferTarget)?.NoteTransferStop(ModuleHelper.Converter(_cassetteRobotModule.Module), _blade, _sourceSlot, EnumTransferType.Pick);
  216. }
  217. public override Result Monitor()
  218. {
  219. try
  220. {
  221. PauseRountine(_cassetteRobotModule.CarrierRobotDevice.IsPause);
  222. if (_cassetteRobotModule.CarrierRobotDevice.IsPause)
  223. return Result.RUN;
  224. CheckBeforePick((int)RoutineStep.CheckBeforePick, _source, _sourceSlot, _blade);
  225. //if (_carrierIDReaderSetting == "UseReadID" || _carrierIDReaderSetting == "ReadWithReservedIDCheck")
  226. // ReadCarrierID((int)RoutineStep.ReadCarrierID, _timeout);
  227. //if (_carrierIDReaderSetting == "ReadWithReservedIDCheck")
  228. // CheckCarrierID((int)RoutineStep.CheckCarrierID);
  229. Goto((int)RoutineStep.Goto, _source, _sourceSlot, _blade, true, _timeout);
  230. if (_source == ModuleName.LP1 || _source == ModuleName.LP2)
  231. {
  232. SaferDoorOpen((int)RoutineStep.DoorOpen, true, _timeout);
  233. SetLPLoad((int)RoutineStep.SetLPLoad, _source, _timeout);
  234. }
  235. else if (_source == ModuleName.LP3 || _source == ModuleName.LP4)
  236. {
  237. SetLPLoad((int)RoutineStep.SetLPLoad, _source, _timeout);
  238. }
  239. CheckGotoFinish((int)RoutineStep.CheckGotoFinish, _source, _timeout);
  240. if (_cassetteRobotModule.TrigActionCommand != null)
  241. SetRobotActionCommand((int)RoutineStep.SetRobotActionCommand, _source, _timeout);
  242. Pick((int)RoutineStep.Pick, _source, _sourceSlot, _blade, _carrierType, _currentCarrierId, _destinationStocker, _timeout);
  243. if (_source == ModuleName.LP1 || _source == ModuleName.LP2)
  244. {
  245. SetLPUnload((int)RoutineStep.SetLPUnload, _source, _timeout);
  246. SaferDoorOpen((int)RoutineStep.DoorClose, false, _timeout);
  247. }
  248. else if (_source == ModuleName.LP3 || _source == ModuleName.LP4)
  249. {
  250. SetLPUnload((int)RoutineStep.SetLPUnload, _source, _timeout);
  251. }
  252. RobotRequestCassettePresent((int)RoutineStep.RobotRequestCassettePresent, _blade, _timeout);
  253. CheckCassetteInfoByRobotSensor((int)RoutineStep.CheckCassetteInfoByRobotSensor, _blade, true);
  254. CheckRobotIsReady((int)RoutineStep.CheckRobotIsReady, _timeout);
  255. if (SC.ContainsItem("System.AddRobotDelay") && SC.ContainsItem("System.RobotDelayTime") && SC.GetValue<bool>("System.AddRobotDelay"))
  256. Delay((int)RoutineStep.Delay, float.Parse(SC.GetStringValue("System.RobotDelayTime")));
  257. }
  258. catch (RoutineBreakException)
  259. {
  260. return Result.RUN;
  261. }
  262. catch (RoutineFaildException ex)
  263. {
  264. _cassetteRobotModule.ResetRobotActionCommand();
  265. (Singleton<EquipmentManager>.Instance.Modules[_source] as ITransferTarget)?.NoteTransferStop(ModuleHelper.Converter(_cassetteRobotModule.Module), _blade, _sourceSlot, EnumTransferType.Pick);
  266. return Result.FAIL;
  267. }
  268. _cassetteRobotModule.ResetRobotActionCommand();
  269. (Singleton<EquipmentManager>.Instance.Modules[_source] as ITransferTarget)?.NoteTransferStop(ModuleHelper.Converter(_cassetteRobotModule.Module), _blade, _sourceSlot, EnumTransferType.Pick);
  270. Notify("Finished");
  271. return Result.DONE;
  272. }
  273. private void CheckRobotIsReady(int id, int timeout)
  274. {
  275. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  276. {
  277. return true;
  278. }, () =>
  279. {
  280. int count = 0;
  281. while (count < 3)
  282. {
  283. if (_cassetteRobotModule.CarrierRobotDevice.IsReady() && !_cassetteRobotModule.CarrierRobotDevice.IsError)
  284. count++;
  285. }
  286. if (count == 3)
  287. return true;
  288. return false;
  289. }, timeout * 1000);
  290. if (ret.Item1)
  291. {
  292. if (ret.Item2 == Result.FAIL)
  293. {
  294. _cassetteRobotModule.PickCassetteFailAlarm.Set($"pick CheckRobotIsReady failed for robot isn't Ready");
  295. throw (new RoutineFaildException());
  296. }
  297. else if (ret.Item2 == Result.TIMEOUT) //timeout
  298. {
  299. _cassetteRobotModule.PickCassetteFailAlarm.Set($"pick CheckRobotIsReady failed for robot isn't Ready");
  300. throw (new RoutineFaildException());
  301. }
  302. else
  303. throw (new RoutineBreakException());
  304. }
  305. }
  306. private void SetRobotActionCommand(int id, ModuleName source, int timeout)
  307. {
  308. _routineStep = (RoutineStep)Enum.Parse(typeof(RoutineStep), id.ToString());
  309. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  310. {
  311. Notify($"Set robot action command target position {source}");
  312. _cassetteRobotModule.SetRobotActionCommand(source, EnumTransferType.Pick);
  313. return true;
  314. }, () =>
  315. {
  316. return _cassetteRobotModule.CheckRobotActionCommand(source, EnumTransferType.Pick);
  317. }, timeout * 1000);
  318. if (ret.Item1)
  319. {
  320. if (ret.Item2 == Result.FAIL)
  321. {
  322. _cassetteRobotModule.PickCassetteFailAlarm.Set($"pick from {source} failed for robot action command interlock");
  323. throw (new RoutineFaildException());
  324. }
  325. else if (ret.Item2 == Result.TIMEOUT) //timeout
  326. {
  327. _cassetteRobotModule.PickCassetteTimeoutAlarm.Set($"timeout over {timeout} seconds");
  328. throw (new RoutineFaildException());
  329. }
  330. else
  331. throw (new RoutineBreakException());
  332. }
  333. }
  334. private void SetLPLoad(int id, ModuleName source, int timeout)
  335. {
  336. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  337. {
  338. Notify($"Set {source} load");
  339. var lp = Singleton<EquipmentManager>.Instance.Modules[source] as LoadPortModule;
  340. if (lp != null)
  341. lp.LPDevice.Load(out string reason);
  342. return true;
  343. }, () =>
  344. {
  345. return true;
  346. }, timeout * 1000);
  347. if (ret.Item1)
  348. {
  349. if (ret.Item2 == Result.FAIL)
  350. {
  351. throw (new RoutineFaildException());
  352. }
  353. else if (ret.Item2 == Result.TIMEOUT) //timeout
  354. {
  355. throw (new RoutineFaildException());
  356. }
  357. else
  358. throw (new RoutineBreakException());
  359. }
  360. }
  361. private void SetLPUnload(int id, ModuleName source, int timeout)
  362. {
  363. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  364. {
  365. Notify($"Set {source} unload");
  366. var lp = Singleton<EquipmentManager>.Instance.Modules[source] as LoadPortModule;
  367. if (lp != null)
  368. lp.LPDevice.Unload(out string reason);
  369. return true;
  370. }, () =>
  371. {
  372. return true;
  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. throw (new RoutineFaildException());
  383. }
  384. else
  385. throw (new RoutineBreakException());
  386. }
  387. }
  388. private void ReadCarrierID(int id, int timeout)
  389. {
  390. _routineStep = (RoutineStep)Enum.Parse(typeof(RoutineStep), id.ToString());
  391. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  392. {
  393. Notify($"Read carrier ID");
  394. string reason;
  395. return true;
  396. }, () =>
  397. {
  398. _readCarrierId = "123";//Carrier ID reader读取到的值
  399. _currentCarrierId = "123";//Carrier ID reader读取到的值
  400. return true;
  401. }, timeout * 1000);
  402. if (ret.Item1)
  403. {
  404. if (ret.Item2 == Result.FAIL)
  405. {
  406. throw (new RoutineFaildException());
  407. }
  408. else if (ret.Item2 == Result.TIMEOUT) //timeout
  409. {
  410. //_cassetteRobotModule.SetStageValveTimeout.Description = $"timeout over {timeout} seconds";
  411. _cassetteRobotModule.SetStageValveTimeout.Set($"timeout over {timeout} seconds");
  412. throw (new RoutineFaildException());
  413. }
  414. else
  415. throw (new RoutineBreakException());
  416. }
  417. }
  418. private void Pick(int id, ModuleName source, int slot, Hand hand, CarrierType carrierType, string lotId, ModuleName carrierInternalModuleName, int timeout)
  419. {
  420. _routineStep = (RoutineStep)Enum.Parse(typeof(RoutineStep), id.ToString());
  421. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  422. {
  423. Notify($"Send pick from {source} command to robot device");
  424. string reason;
  425. if (!CarrierManager.Instance.CheckNoCarrier(source.ToString(), 0))
  426. CarrierManager.Instance.DeleteCarrier(source.ToString());//要保留
  427. CarrierManager.Instance.CreateCarrier(source.ToString(), carrierType, carrierInternalModuleName.ToString());
  428. CarrierManager.Instance.GetCarrier(source.ToString(), 0).IsMapOK = false;
  429. CarrierManager.Instance.GetCarrier(source.ToString(), 0).IsMapped = false;
  430. (Singleton<EquipmentManager>.Instance.Modules[source] as ITransferTarget)?.NoteTransferStart(ModuleHelper.Converter(_cassetteRobotModule.Module), hand, slot, EnumTransferType.Pick);
  431. if (!_cassetteRobotModule.RobotPick(source, slot, hand, out reason))
  432. {
  433. //_cassetteRobotModule.PickCassetteFailAlarm.Description = reason;
  434. _cassetteRobotModule.PickCassetteFailAlarm.Set(reason);
  435. return false;
  436. }
  437. return true;
  438. }, () =>
  439. {
  440. if (_cassetteRobotModule.CarrierRobotDevice.IsReady() && !_cassetteRobotModule.CarrierRobotDevice.IsError)
  441. {
  442. var lp = Singleton<EquipmentManager>.Instance.Modules[_source] as LoadPortModule;
  443. var readCarrierId = lp != null ? lp.CarrierId : lotId;
  444. CarrierManager.Instance.UpdateCarrierId(ModuleName.CarrierRobot.ToString(), readCarrierId);
  445. return true;
  446. }
  447. return false;
  448. }, timeout * 1000);
  449. if (ret.Item1)
  450. {
  451. if (ret.Item2 == Result.FAIL)
  452. {
  453. //_cassetteRobotModule.PickCassetteFailAlarm.Description = $"{_cassetteRobotModule.CassetteRobotDevice.ErrorCode}";
  454. _cassetteRobotModule.PickCassetteFailAlarm.Set($"pick from {source} failed for robot error, error code={_cassetteRobotModule.CarrierRobotDevice.ErrorCode}");
  455. throw (new RoutineFaildException());
  456. }
  457. else if (ret.Item2 == Result.TIMEOUT) //timeout
  458. {
  459. //_cassetteRobotModule.PickCassetteTimeoutAlarm.Description = $"timeout over {timeout} seconds";
  460. _cassetteRobotModule.PickCassetteTimeoutAlarm.Set($"timeout over {timeout} seconds");
  461. throw (new RoutineFaildException());
  462. }
  463. else
  464. throw (new RoutineBreakException());
  465. }
  466. }
  467. private void RobotRequestCassettePresent(int id, Hand hand, int timeout)
  468. {
  469. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  470. {
  471. Notify("Request cassette present");
  472. if (!_cassetteRobotModule.RequestCassettePresent(hand, out string reason))
  473. {
  474. //_cassetteRobotModule.RequestCassettePresentFailAlarm.Description = reason;
  475. _cassetteRobotModule.RequestCassettePresentFailAlarm.Set(reason);
  476. return false;
  477. }
  478. return true;
  479. }, () =>
  480. {
  481. if (_cassetteRobotModule.CarrierRobotDevice.IsReady() && !_cassetteRobotModule.CarrierRobotDevice.IsError)
  482. {
  483. return true;
  484. }
  485. return false;
  486. }, timeout * 1000);
  487. if (ret.Item1)
  488. {
  489. if (ret.Item2 == Result.FAIL)
  490. {
  491. throw (new RoutineFaildException());
  492. }
  493. else if (ret.Item2 == Result.TIMEOUT) //timeout
  494. {
  495. //_cassetteRobotModule.RequestCassettePresentTimeoutAlarm.Description = $"timeout over {timeout} seconds";
  496. _cassetteRobotModule.RequestCassettePresentTimeoutAlarm.Set($"timeout over {timeout} seconds");
  497. throw (new RoutineFaildException());
  498. }
  499. else
  500. throw (new RoutineBreakException());
  501. }
  502. }
  503. private void CheckCassetteInfoByRobotSensor(int id, Hand hand, bool isAfterPick)
  504. {
  505. Tuple<bool, Result> ret = Execute(id, () =>
  506. {
  507. Notify($"Check cassette info by robot RQ present");
  508. if (SC.GetValue<bool>("System.IsSimulatorMode"))
  509. return true;
  510. if (hand == Hand.Blade1 || hand == Hand.Both)
  511. {
  512. if (!isAfterPick && _cassetteRobotModule.CarrierRobotDevice.IsWaferPresenceOnBlade1)
  513. {
  514. //_cassetteRobotModule.RobotSensorFoundCassetteOnBladeAfterPlaceAlarm.Description = "Cassette Robot sensor found cassette on blade 1";
  515. _cassetteRobotModule.RobotSensorFoundCassetteOnBladeAfterPlaceAlarm.Set("Cassette Robot sensor found cassette on blade 1");
  516. return false;
  517. }
  518. if (isAfterPick && !_cassetteRobotModule.CarrierRobotDevice.IsWaferPresenceOnBlade1)
  519. {
  520. //_cassetteRobotModule.RobotSensorNotFoundCassetteOnBladeAfterPickAlarm.Description = "Cassette Robot sensor no cassette on blade 1";
  521. _cassetteRobotModule.RobotSensorNotFoundCassetteOnBladeAfterPickAlarm.Set("Cassette Robot sensor no cassette on blade 1");
  522. return false;
  523. }
  524. }
  525. if (hand == Hand.Blade2 || hand == Hand.Both)
  526. {
  527. if (!isAfterPick && _cassetteRobotModule.CarrierRobotDevice.IsWaferPresenceOnBlade2)
  528. {
  529. //_cassetteRobotModule.RobotSensorFoundCassetteOnBladeAfterPlaceAlarm.Description = "Cassette Robot sensor found cassette on blade 2";
  530. _cassetteRobotModule.RobotSensorFoundCassetteOnBladeAfterPlaceAlarm.Set("Cassette Robot sensor found cassette on blade 2");
  531. return false;
  532. }
  533. if (isAfterPick && !_cassetteRobotModule.CarrierRobotDevice.IsWaferPresenceOnBlade2)
  534. {
  535. //_cassetteRobotModule.RobotSensorNotFoundCassetteOnBladeAfterPickAlarm.Description = "Cassette Robot sensor no cassette on blade 2";
  536. _cassetteRobotModule.RobotSensorNotFoundCassetteOnBladeAfterPickAlarm.Set("Cassette Robot sensor no cassette on blade 2");
  537. return false;
  538. }
  539. }
  540. return true;
  541. });
  542. if (ret.Item1)
  543. {
  544. if (ret.Item2 == Result.FAIL)
  545. {
  546. //_cassetteRobotModule.CheckCassetteInformationFailAlarm.Description = $"check cassette info failed.";
  547. _cassetteRobotModule.CheckCassetteInformationFailAlarm.Set($"check cassette info failed.");
  548. throw (new RoutineFaildException());
  549. }
  550. else
  551. throw (new RoutineBreakException());
  552. }
  553. }
  554. private void CheckBeforePick(int id, ModuleName source, int slot, Hand blade)
  555. {
  556. Tuple<bool, Result> ret = Execute(id, () =>
  557. {
  558. Notify($"Check pick from {source} condition");
  559. string reason = string.Empty;
  560. if (_cassetteRobotModule.CarrierRobotDevice.IsError)
  561. {
  562. _cassetteRobotModule.PickCassetteFailAlarm.Set($"pick from {source} failed for robot error, error code={_cassetteRobotModule.CarrierRobotDevice.ErrorCode}");
  563. return false;
  564. }
  565. if (!_cassetteRobotModule.CarrierRobotDevice.IsReady())
  566. {
  567. _cassetteRobotModule.PickCassetteFailAlarm.Set($"pick from {source} failed for robot isn't Ready");
  568. return false;
  569. }
  570. if (!CarrierManager.Instance.CheckHasCarrier(_source, 0))
  571. {
  572. _cassetteRobotModule.PickCassetteFailAlarm.Set($"pick from {_source} failed for pod is not present");
  573. return false;
  574. }
  575. if (blade == Hand.Blade1)
  576. {
  577. if (!CarrierManager.Instance.CheckHasCarrier(source, 0))
  578. {
  579. _cassetteRobotModule.PickCassetteFailAlarm.Set($"pick from {source} failed for {source} no carrrier");
  580. return false;
  581. }
  582. if (!CarrierManager.Instance.CheckNoCarrier(Module, 0))
  583. {
  584. _cassetteRobotModule.PickCassetteFailAlarm.Set($"pick from {source} failed for blade has carrier");
  585. return false;
  586. }
  587. }
  588. else if (blade == Hand.Blade2)
  589. {
  590. if (!CarrierManager.Instance.CheckHasCarrier(source, 0))
  591. {
  592. _cassetteRobotModule.PickCassetteFailAlarm.Set($"pick from {source} failed for {source} no carrier");
  593. return false;
  594. }
  595. if (!CarrierManager.Instance.CheckNoCarrier(Module, 0))
  596. {
  597. _cassetteRobotModule.PickCassetteFailAlarm.Set($"pick from {source} failed for blade has carrier");
  598. return false;
  599. }
  600. }
  601. else
  602. {
  603. if (!CarrierManager.Instance.CheckHasCarrier(source, 0))
  604. {
  605. _cassetteRobotModule.PickCassetteFailAlarm.Set($"pick from {source} failed for {source} no carrier");
  606. return false;
  607. }
  608. if (!CarrierManager.Instance.CheckNoCarrier(Module, 0))
  609. {
  610. _cassetteRobotModule.PickCassetteFailAlarm.Set($"pick from {source} failed for blade has carrier");
  611. return false;
  612. }
  613. }
  614. return true;
  615. });
  616. if (ret.Item1)
  617. {
  618. if (ret.Item2 == Result.FAIL)
  619. {
  620. throw (new RoutineFaildException());
  621. }
  622. }
  623. _needStartCheck = false;
  624. }
  625. private void CheckCarrierID(int id)
  626. {
  627. Tuple<bool, Result> ret = Execute(id, () =>
  628. {
  629. Notify($"Check carrier ID");
  630. string reason = string.Empty;
  631. if (_readCarrierId != _reservedCarrierId)
  632. {
  633. _cassetteRobotModule.CheckCarrierIDFailAlarm.Set($"read id={_readCarrierId}, reserved id={_reservedCarrierId}, mismatch");
  634. return false;
  635. }
  636. return true;
  637. });
  638. if (ret.Item1)
  639. {
  640. if (ret.Item2 == Result.FAIL)
  641. {
  642. throw (new RoutineFaildException());
  643. }
  644. }
  645. _needStartCheck = false;
  646. }
  647. private void Goto(int id, ModuleName target, int slot, Hand hand, bool isPickReady, int timeout)
  648. {
  649. _routineStep = (RoutineStep)Enum.Parse(typeof(RoutineStep), id.ToString());
  650. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  651. {
  652. Notify($"Send goto to {target} command to robot device");
  653. string reason;
  654. _cassetteRobotModule.RobotGoto(target, slot, hand, isPickReady, out reason);
  655. return true;
  656. }, () =>
  657. {
  658. return true;
  659. }, timeout * 1000);
  660. if (ret.Item1)
  661. {
  662. if (ret.Item2 == Result.FAIL)
  663. {
  664. _cassetteRobotModule.GotoFailAlarm.Set($"goto to {target} failed for robot error, error code={_cassetteRobotModule.CarrierRobotDevice.ErrorCode}");
  665. throw (new RoutineFaildException());
  666. }
  667. else if (ret.Item2 == Result.TIMEOUT) //timeout
  668. {
  669. _cassetteRobotModule.GotoTimeoutAlarm.Set($"timeout over {timeout} seconds");
  670. throw (new RoutineFaildException());
  671. }
  672. else
  673. throw (new RoutineBreakException());
  674. }
  675. }
  676. private void CheckGotoFinish(int id, ModuleName target, int timeout)
  677. {
  678. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  679. {
  680. Notify($"Check goto to {target} command finish");
  681. return true;
  682. }, () =>
  683. {
  684. if (_cassetteRobotModule.CarrierRobotDevice.IsError)
  685. return null;
  686. if (_cassetteRobotModule.CarrierRobotDevice.IsReady() && !_cassetteRobotModule.CarrierRobotDevice.IsError)
  687. {
  688. return true;
  689. }
  690. return false;
  691. }, timeout * 1000);
  692. if (ret.Item1)
  693. {
  694. if (ret.Item2 == Result.FAIL)
  695. {
  696. _cassetteRobotModule.GotoFailAlarm.Set($"goto to {target} failed for robot error, error code={_cassetteRobotModule.CarrierRobotDevice.ErrorCode}");
  697. throw (new RoutineFaildException());
  698. }
  699. else if (ret.Item2 == Result.TIMEOUT) //timeout
  700. {
  701. _cassetteRobotModule.GotoTimeoutAlarm.Set($"timeout over {timeout} seconds");
  702. throw (new RoutineFaildException());
  703. }
  704. else
  705. throw (new RoutineBreakException());
  706. }
  707. }
  708. private void SaferDoorOpen(int id, bool isOpen, int timeout)
  709. {
  710. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  711. {
  712. Notify($"Shutter Door {(isOpen ? "Open" : "Close")}");
  713. if (isOpen)
  714. _cassetteRobotModule.DoorDevice.Open();
  715. else
  716. _cassetteRobotModule.DoorDevice.Close();
  717. if (isOpen)
  718. (Singleton<EquipmentManager>.Instance.Modules[_source] as LoadPortModule)?.LPDevice.Unclamp(out _);
  719. return true;
  720. }, () =>
  721. {
  722. return isOpen ? _cassetteRobotModule.DoorDevice.OpenCloseStatus == Devices.DeviceStatus.Open && (Singleton<EquipmentManager>.Instance.Modules[_source] as LoadPortModule).IsReleased : _cassetteRobotModule.DoorDevice.OpenCloseStatus == Devices.DeviceStatus.Close;
  723. }, timeout * 1000);
  724. if (ret.Item1)
  725. {
  726. if (ret.Item2 == Result.FAIL)
  727. {
  728. throw new RoutineFaildException();
  729. }
  730. else if (ret.Item2 == Result.TIMEOUT) //timeout
  731. {
  732. if (isOpen)
  733. _cassetteRobotModule.ShutterOpenTimeoutAlarm.Set($"timeout over {timeout} seconds");
  734. else
  735. _cassetteRobotModule.ShutterCloseTimeoutAlarm.Set($"timeout over {timeout} seconds");
  736. throw (new RoutineFaildException());
  737. }
  738. else
  739. throw new RoutineBreakException();
  740. }
  741. }
  742. }
  743. }