LoadPortHome.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. using Aitex.Core.RT.Device;
  2. using Aitex.Core.RT.Event;
  3. using Aitex.Core.RT.Routine;
  4. using Aitex.Core.RT.SCCore;
  5. using Aitex.Sorter.Common;
  6. using MECF.Framework.Common.Device.Bases;
  7. using MECF.Framework.Common.Equipment;
  8. using MECF.Framework.Common.SubstrateTrackings;
  9. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robot;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. using FurnaceRT.Equipments.Systems;
  16. namespace FurnaceRT.Equipments.LPs
  17. {
  18. public class LoadPortHome : ModuleRoutine, IRoutine
  19. {
  20. enum RoutineStep
  21. {
  22. Home,
  23. }
  24. private LoadPortModule _lpModule;
  25. private int _timeout = 0;
  26. public LoadPortHome(LoadPortModule smifModule)
  27. {
  28. _lpModule = smifModule;
  29. Module = smifModule.Module;
  30. Name = "Home";
  31. }
  32. public Result Start(params object[] objs)
  33. {
  34. Reset();
  35. _timeout = SC.GetValue<int>($"LoadPort.{Module}.HomeTimeout");
  36. //_smifDevice = DEVICE.GetDevice<IoSmif>($"System.{Module}");
  37. _lpModule.HomeFailAlarm.RetryMessage = (int)LoadPortModule.MSG.Home;
  38. _lpModule.HomeTimeoutAlarm.RetryMessage = (int)LoadPortModule.MSG.Home;
  39. //if (!_lpModule.SMIFDevice.IsIdle)
  40. //{
  41. // //_lpModule.SMIFNotReadyWarning.Description = $"{Module} is not ready, home failed";
  42. // _lpModule.SMIFNotReadyWarning.Set($"{Module} is not ready, home failed");
  43. // return Result.FAIL;
  44. //}
  45. Notify($"{Module} home start");
  46. return Result.RUN;
  47. }
  48. public void Abort()
  49. {
  50. _lpModule.Stop();
  51. }
  52. public override Result Monitor()
  53. {
  54. try
  55. {
  56. Home((int)RoutineStep.Home, _timeout);
  57. }
  58. catch (RoutineBreakException)
  59. {
  60. return Result.RUN;
  61. }
  62. catch (RoutineFaildException ex)
  63. {
  64. return Result.FAIL;
  65. }
  66. _lpModule.LPDevice.IsInitCompleted = true;
  67. _lpModule.LPDevice.IsLoadCompleted = true;
  68. Notify($"{Name} home finished");
  69. return Result.DONE;
  70. }
  71. private void Home(int id, int timeout)
  72. {
  73. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  74. {
  75. Notify($"{Module} home");
  76. if (!_lpModule.HomeLoadPort(out string reason))
  77. {
  78. Stop(reason);
  79. return false;
  80. }
  81. return true;
  82. }, () =>
  83. {
  84. return _lpModule.IsHomed;
  85. }, timeout * 1000);
  86. if (ret.Item1)
  87. {
  88. if (ret.Item2 == Result.FAIL)
  89. {
  90. throw (new RoutineFaildException());
  91. }
  92. else if (ret.Item2 == Result.TIMEOUT) //timeout
  93. {
  94. //_lpModule.HomeTimeoutAlarm.Description = $"home timeout, can not complete in {timeout} seconds";
  95. _lpModule.HomeTimeoutAlarm.Set($"home timeout, can not complete in {timeout} seconds");
  96. throw (new RoutineFaildException());
  97. }
  98. else
  99. throw (new RoutineBreakException());
  100. }
  101. }
  102. }
  103. }