LoadPortReadCarrierIdRoutine.cs 2.5 KB

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