LoadPortHome.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 = false;
  68. _lpModule.LPDevice.IsUnloadCompleted = true;
  69. Notify($"{Name} home finished");
  70. return Result.DONE;
  71. }
  72. private void Home(int id, int timeout)
  73. {
  74. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  75. {
  76. Notify($"{Module} home");
  77. if (!_lpModule.HomeLoadPort(out string reason))
  78. {
  79. Stop(reason);
  80. return false;
  81. }
  82. return true;
  83. }, () =>
  84. {
  85. return _lpModule.IsHomed;
  86. }, timeout * 1000);
  87. if (ret.Item1)
  88. {
  89. if (ret.Item2 == Result.FAIL)
  90. {
  91. throw (new RoutineFaildException());
  92. }
  93. else if (ret.Item2 == Result.TIMEOUT) //timeout
  94. {
  95. //_lpModule.HomeTimeoutAlarm.Description = $"home timeout, can not complete in {timeout} seconds";
  96. _lpModule.HomeTimeoutAlarm.Set($"home timeout, can not complete in {timeout} seconds");
  97. throw (new RoutineFaildException());
  98. }
  99. else
  100. throw (new RoutineBreakException());
  101. }
  102. }
  103. }
  104. }