LoadPortLoadRoutine.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. using System;
  2. using Aitex.Core.RT.Device;
  3. using Aitex.Core.RT.Event;
  4. using Aitex.Core.RT.Log;
  5. using Aitex.Core.RT.Routine;
  6. using Aitex.Core.RT.SCCore;
  7. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts;
  8. namespace VirgoRT.Modules.LPs
  9. {
  10. class LoadPortLoadRoutine : ModuleRoutine, IRoutine
  11. {
  12. enum RoutineStep
  13. {
  14. Load,
  15. }
  16. private int _timeout = 0;
  17. private LoadPortModule _lpModule;
  18. public LoadPortLoadRoutine(LoadPortModule lpModule)
  19. {
  20. _lpModule = lpModule;
  21. Module = lpModule.Module;
  22. Name = "Load";
  23. }
  24. public Result Start(params object[] objs)
  25. {
  26. Reset();
  27. _timeout = SC.GetValue<int>("EFEM.LoadPort.MotionTimeout");
  28. if (!_lpModule.LPDevice.HasCassette )
  29. {
  30. EV.PostWarningLog(Module, $"{Module} not found carrier, can not load");
  31. return Result.FAIL;
  32. }
  33. Notify($"Start");
  34. return Result.RUN;
  35. }
  36. public Result Monitor()
  37. {
  38. try
  39. {
  40. Load((int)RoutineStep.Load, _timeout);
  41. }
  42. catch (RoutineBreakException)
  43. {
  44. return Result.RUN;
  45. }
  46. catch (RoutineFaildException )
  47. {
  48. return Result.FAIL;
  49. }
  50. Notify("Finished");
  51. return Result.DONE;
  52. }
  53. public void Load(int id, int timeout)
  54. {
  55. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  56. {
  57. Notify($"Start Load {_lpModule.Name}");
  58. _lpModule.LPDevice.Load();
  59. return true;
  60. }, () =>
  61. {
  62. if (_lpModule.LPDevice.IsError)
  63. return null;
  64. if (_lpModule.LPDevice.IsBusy)
  65. return false;
  66. return true;
  67. }, timeout * 1000);
  68. if (ret.Item1)
  69. {
  70. if (ret.Item2 == Result.FAIL)
  71. {
  72. Stop(string.Format("failed."));
  73. throw (new RoutineFaildException());
  74. }
  75. else if (ret.Item2 == Result.TIMEOUT) //timeout
  76. {
  77. Stop(string.Format("timeout, can not complete in {0} seconds", timeout));
  78. throw (new RoutineFaildException());
  79. }
  80. else
  81. throw (new RoutineBreakException());
  82. }
  83. }
  84. public void Abort()
  85. {
  86. }
  87. }
  88. }