PMHomeRoutine.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. using Aitex.Core.RT.Routine;
  2. using Aitex.Core.RT.SCCore;
  3. using MECF.Framework.Common.Equipment;
  4. using FurnaceRT.Equipments.PMs;
  5. using System;
  6. using FurnaceRT.Equipments.PMs.Routines;
  7. namespace FurnaceRT.Modules.PMs
  8. {
  9. public class PMHomeRoutine : PMBaseRoutine
  10. {
  11. enum RoutineStep
  12. {
  13. CheckInterlock,
  14. SetMainPowerOn,
  15. WaitHomeFinished,
  16. }
  17. private int _timeout;
  18. public PMHomeRoutine(ModuleName module, PMModule pm) : base(module, pm)
  19. {
  20. Module = module.ToString();
  21. Name = "Home";
  22. }
  23. public Result Init()
  24. {
  25. return Result.DONE;
  26. }
  27. public override Result Start(params object[] objs)
  28. {
  29. Reset();
  30. _timeout = SC.GetValue<int>($"{Module}.HomeTimeout");
  31. Notify("Start");
  32. return Result.RUN;
  33. }
  34. public override Result Monitor()
  35. {
  36. try
  37. {
  38. //if (PMDevice != null && PMDevice.IsInstalled)
  39. {
  40. //CheckInterlock((int)RoutineStep.CheckInterlock, PMModule as PMModule, _timeout);
  41. //SetMainPowerOn((int)RoutineStep.SetMainPowerOn, PMModule as PMModule, _timeout);
  42. //SetMainPowerOn((int)RoutineStep.SetMainPowerOn, PMDevice as FurnacePM, _timeout);
  43. //WaitHomeFinished((int)RoutineStep.WaitHomeFinished, PMModule as PMModule, _timeout);
  44. }
  45. }
  46. catch (RoutineBreakException)
  47. {
  48. return Result.RUN;
  49. }
  50. catch (RoutineFaildException)
  51. {
  52. return Result.FAIL;
  53. }
  54. Notify("Finished");
  55. return Result.DONE;
  56. }
  57. public override void Abort()
  58. {
  59. }
  60. public void CheckInterlock(int id, PMModule pm, int timeout)
  61. {
  62. Tuple<bool, Result> ret = Execute(id, () =>
  63. {
  64. Notify($"Run {pm.Name} home");
  65. // pm.Home(out _);
  66. return true;
  67. } );
  68. if (ret.Item1)
  69. {
  70. if (ret.Item2 == Result.FAIL)
  71. {
  72. Stop($"{pm.Name} error");
  73. throw (new RoutineFaildException());
  74. }
  75. else
  76. throw (new RoutineBreakException());
  77. }
  78. }
  79. public void SetMainPowerOn(int id, PMModule pm, int timeout)
  80. {
  81. Tuple<bool, Result> ret = Execute(id, () =>
  82. {
  83. Notify($"Set {pm.Name} main power on");
  84. //if (!pm.MainChiller.SetMainPowerOnOff(true, out string reason))
  85. //{
  86. // Stop(reason);
  87. // return false;
  88. //}
  89. //if (!pm.MainPump.SetMainPowerOnOff(true, out reason))
  90. //{
  91. // Stop(reason);
  92. // return false;
  93. //}
  94. return true;
  95. } );
  96. if (ret.Item1)
  97. {
  98. if (ret.Item2 == Result.FAIL)
  99. {
  100. Stop($"{pm.Name} error");
  101. throw (new RoutineFaildException());
  102. }
  103. else
  104. throw (new RoutineBreakException());
  105. }
  106. }
  107. public void WaitHomeFinished(int id, PMModule pm, int timeout)
  108. {
  109. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  110. {
  111. Notify($"Wait chiller is running");
  112. return true;
  113. }, () =>
  114. {
  115. return true/*pm.MainChiller.IsRunning*/;
  116. }, timeout * 1000);
  117. if (ret.Item1)
  118. {
  119. if (ret.Item2 == Result.FAIL)
  120. {
  121. Stop($"{pm.Name} error");
  122. throw (new RoutineFaildException());
  123. }
  124. else if (ret.Item2 == Result.TIMEOUT) //timeout
  125. {
  126. Stop($"timeout, over {timeout} seconds");
  127. throw (new RoutineFaildException());
  128. }
  129. else
  130. throw (new RoutineBreakException());
  131. }
  132. }
  133. }
  134. }