StopGasFlowRoutine.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. using System;
  2. using Aitex.Core.RT.Device.Unit;
  3. using Aitex.Core.RT.Routine;
  4. using Aitex.RT.Properties;
  5. using Aitex.Triton160.RT.Device;
  6. namespace Aitex.Triton160.RT.Routine.PM
  7. {
  8. public class StopGasFlowRoutine : CommonRoutine
  9. {
  10. private enum RoutineStep
  11. {
  12. StopGasFlow,
  13. End,
  14. };
  15. public StopGasFlowRoutine(string module, string name)
  16. {
  17. Module = module;
  18. Name = name;
  19. Display = Resources.StopGasFlowRoutine_StopGasFlowRoutine_StopGasFlow;
  20. bUINotify = true;
  21. }
  22. public bool Initialize()
  23. {
  24. InitCommon();
  25. return true;
  26. }
  27. public void Terminate()
  28. {
  29. }
  30. public Result Start(params object[] objs)
  31. {
  32. Reset();
  33. UpdateSCValue();
  34. return Result.RUN;
  35. }
  36. public Result Monitor()
  37. {
  38. try
  39. {
  40. StopGasFlow((int)RoutineStep.StopGasFlow, Resources.StopGasFlowRoutine_Monitor_CloseValveAndStopMfc, Notify, Stop);
  41. End((int)RoutineStep.End, Resources.StopGasFlowRoutine_Monitor_StopGasFlowCompleted, Notify, Stop);
  42. }
  43. catch (RoutineBreakException)
  44. {
  45. return Result.RUN;
  46. }
  47. catch (RoutineFaildException)
  48. {
  49. return Result.FAIL;
  50. }
  51. return Result.DONE;
  52. }
  53. public void StopGasFlow(int id, string name, Action<string> notify, Action<string> error)
  54. {
  55. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  56. {
  57. notify(name);
  58. IoValve[] valves = { DeviceModel.ValveMfc1, DeviceModel.ValveMfc2, DeviceModel.ValveMfc3 , DeviceModel.ValveMfc4 , DeviceModel.ValveMfc5 };
  59. IoMfc[] mfcs = { DeviceModel.MfcGas1, DeviceModel.MfcGas2, DeviceModel.MfcGas3, DeviceModel.MfcGas4, DeviceModel.MfcGas5 };
  60. string reason = string.Empty;
  61. for (int i = 0; i < mfcs.Length; i++)
  62. {
  63. if (valves[i] != null)
  64. valves[i].TurnValve(false, out reason);
  65. if (mfcs[i] != null)
  66. mfcs[i].Ramp(0, 0);
  67. }
  68. if (DeviceModel.ValveProcessGasFinal != null)
  69. DeviceModel.ValveProcessGasFinal.TurnValve(false, out reason);
  70. return true;
  71. }, () =>
  72. {
  73. return true;
  74. }, 10 * 1000);
  75. if (ret.Item1)
  76. {
  77. if (ret.Item2 == Result.FAIL)
  78. {
  79. throw (new RoutineFaildException());
  80. }
  81. else if (ret.Item2 == Result.TIMEOUT) //timeout
  82. {
  83. throw (new RoutineFaildException());
  84. }
  85. else
  86. throw (new RoutineBreakException());
  87. }
  88. }
  89. }
  90. }