LoadPortHome.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. using Aitex.Core.RT.Log;
  17. namespace FurnaceRT.Equipments.LPs
  18. {
  19. public class LoadPortHome : ModuleRoutine, IRoutine
  20. {
  21. enum RoutineStep
  22. {
  23. Home,
  24. }
  25. private LoadPortModule _lpModule;
  26. private int _timeout = 0;
  27. public LoadPortHome(LoadPortModule smifModule)
  28. {
  29. _lpModule = smifModule;
  30. Module = smifModule.Module;
  31. Name = "Home";
  32. }
  33. public Result Start(params object[] objs)
  34. {
  35. Reset();
  36. _timeout = SC.GetValue<int>($"LoadPort.{Module}.HomeTimeout");
  37. //_smifDevice = DEVICE.GetDevice<IoSmif>($"System.{Module}");
  38. _lpModule.HomeFailAlarm.RetryMessage = (int)LoadPortModule.MSG.Home;
  39. _lpModule.HomeTimeoutAlarm.RetryMessage = (int)LoadPortModule.MSG.Home;
  40. //if (!_lpModule.SMIFDevice.IsIdle)
  41. //{
  42. // //_lpModule.SMIFNotReadyWarning.Description = $"{Module} is not ready, home failed";
  43. // _lpModule.SMIFNotReadyWarning.Set($"{Module} is not ready, home failed");
  44. // return Result.FAIL;
  45. //}
  46. Notify($"{Module} home start");
  47. return Result.RUN;
  48. }
  49. public void Abort()
  50. {
  51. _lpModule.Stop();
  52. }
  53. public override Result Monitor()
  54. {
  55. try
  56. {
  57. Home((int)RoutineStep.Home, _timeout);
  58. }
  59. catch (RoutineBreakException)
  60. {
  61. return Result.RUN;
  62. }
  63. catch (RoutineFaildException ex)
  64. {
  65. return Result.FAIL;
  66. }
  67. LOG.Info($"AAAAA-Home-{Name} IsLoadCompleted from {_lpModule.LPDevice.IsLoadCompleted} to {false} and IsUnloadCompleted from {_lpModule.LPDevice.IsUnloadCompleted} to {true}");
  68. _lpModule.LPDevice.IsInitCompleted = true;
  69. _lpModule.LPDevice.IsLoadCompleted = false;
  70. _lpModule.LPDevice.IsUnloadCompleted = true;
  71. Notify($"{Name} home finished");
  72. return Result.DONE;
  73. }
  74. private void Home(int id, int timeout)
  75. {
  76. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  77. {
  78. Notify($"{Module} home");
  79. if (!_lpModule.HomeLoadPort(out string reason))
  80. {
  81. Stop(reason);
  82. return false;
  83. }
  84. return true;
  85. }, () =>
  86. {
  87. return _lpModule.IsHomed;
  88. }, timeout * 1000);
  89. if (ret.Item1)
  90. {
  91. if (ret.Item2 == Result.FAIL)
  92. {
  93. throw (new RoutineFaildException());
  94. }
  95. else if (ret.Item2 == Result.TIMEOUT) //timeout
  96. {
  97. //_lpModule.HomeTimeoutAlarm.Description = $"home timeout, can not complete in {timeout} seconds";
  98. _lpModule.HomeTimeoutAlarm.Set($"home timeout, can not complete in {timeout} seconds");
  99. throw (new RoutineFaildException());
  100. }
  101. else
  102. throw (new RoutineBreakException());
  103. }
  104. }
  105. }
  106. }