LoadPortReadCarrierId.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using Aitex.Core.Common;
  5. using Aitex.Core.RT.DataCenter;
  6. using Aitex.Core.RT.Device;
  7. using Aitex.Core.RT.Device.Unit;
  8. using Aitex.Core.RT.Event;
  9. using Aitex.Core.RT.Fsm;
  10. using Aitex.Core.RT.OperationCenter;
  11. using Aitex.Core.RT.Routine;
  12. using Aitex.Core.RT.SCCore;
  13. using Aitex.Core.Utilities;
  14. using Aitex.Sorter.Common;
  15. using MECF.Framework.Common.Alarms;
  16. using MECF.Framework.Common.Device.Bases;
  17. using MECF.Framework.Common.Equipment;
  18. using MECF.Framework.Common.Event;
  19. using MECF.Framework.Common.Schedulers;
  20. using MECF.Framework.Common.SubstrateTrackings;
  21. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts;
  22. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robot;
  23. using FurnaceRT.Equipments.Systems;
  24. using FurnaceRT.Devices;
  25. using Aitex.Core.Util;
  26. namespace FurnaceRT.Equipments.LPs
  27. {
  28. public class LoadPortReadCarrierId : ModuleRoutine, IRoutine
  29. {
  30. enum RoutineStep
  31. {
  32. ReadCarrierId,
  33. }
  34. private int _timeout = 0;
  35. private LoadPortModule _lpModule;
  36. public LoadPortReadCarrierId(LoadPortModule lpModule)
  37. {
  38. _lpModule = lpModule;
  39. Module = lpModule.Module;
  40. Name = "ReadCarrierId";
  41. }
  42. public bool Initalize()
  43. {
  44. return true;
  45. }
  46. public Result Start(params object[] objs)
  47. {
  48. Reset();
  49. _timeout = SC.GetValue<int>($"LoadPort.{Module}.MotionTimeout");
  50. Notify($"Start");
  51. return Result.RUN;
  52. }
  53. public void Abort()
  54. {
  55. }
  56. public Result Monitor()
  57. {
  58. try
  59. {
  60. ReadCarrierId((int)RoutineStep.ReadCarrierId, _timeout);
  61. }
  62. catch (RoutineBreakException)
  63. {
  64. return Result.RUN;
  65. }
  66. catch (RoutineFaildException)
  67. {
  68. return Result.FAIL;
  69. }
  70. Notify("Finished");
  71. return Result.DONE;
  72. }
  73. public void ReadCarrierId(int id, int timeout)
  74. {
  75. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  76. {
  77. Notify($"Start read carrier id {Module}");
  78. if (!_lpModule.LPDevice.ReadCarrierID())
  79. {
  80. Stop("ReadCarrierID failed");
  81. return false;
  82. }
  83. return true;
  84. }, () =>
  85. {
  86. //if (_lp.CurrentState == LoadPortStateEnum.Error && !_lp.IsBusy)
  87. // return false;
  88. //if (_lp.IsReady() && !_lp.ReadCarrierIDError)
  89. // return true;
  90. return true;
  91. }, timeout * 1000);
  92. if (ret.Item1)
  93. {
  94. if (ret.Item2 == Result.FAIL)
  95. {
  96. Stop(string.Format("failed."));
  97. throw (new RoutineFaildException());
  98. }
  99. else if (ret.Item2 == Result.TIMEOUT) //timeout
  100. {
  101. Stop(string.Format("timeout, can not complete in {0} seconds", timeout));
  102. throw (new RoutineFaildException());
  103. }
  104. else
  105. throw (new RoutineBreakException());
  106. }
  107. }
  108. }
  109. }