PrewetInitializeRoutine.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using Aitex.Core.RT.Device;
  2. using Aitex.Core.RT.Routine;
  3. using MECF.Framework.Common.Routine;
  4. using CyberX8_Core;
  5. using CyberX8_RT.Devices.LinMot;
  6. using CyberX8_RT.Devices.Prewet;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading;
  12. using System.Threading.Tasks;
  13. namespace CyberX8_RT.Modules.Prewet
  14. {
  15. public class PrewetInitializeRoutine : RoutineBase, IRoutine
  16. {
  17. private enum InitializeStep
  18. {
  19. PumpValveOff,
  20. ResetLinmot,
  21. WaitReset,
  22. End
  23. }
  24. #region 内部变量
  25. private PrewetDevice _prewetDevice;
  26. private LinMotAxis _linmotAxis;
  27. #endregion
  28. /// <summary>
  29. /// 当前执行到哪一步
  30. /// </summary>
  31. public string CurrentStateMachine
  32. {
  33. get { return Runner.CurrentStep.ToString(); ; }
  34. }
  35. /// <summary>
  36. /// 构造函数
  37. /// </summary>
  38. /// <param name="module"></param>
  39. public PrewetInitializeRoutine(string module,LinMotAxis linMotAxis) : base(module)
  40. {
  41. _linmotAxis = linMotAxis;
  42. }
  43. /// <summary>
  44. /// 中止
  45. /// </summary>
  46. public void Abort()
  47. {
  48. Runner.Stop("Manual Abort");
  49. }
  50. /// <summary>
  51. /// 监控
  52. /// </summary>
  53. /// <returns></returns>
  54. public RState Monitor()
  55. {
  56. Runner.Run(InitializeStep.PumpValveOff, () => { return _prewetDevice.PumpValveClose(); }, () => { return !_prewetDevice.PrewetPumpData.PumpValve && !_prewetDevice.PrewetPumpData.PumpEnable; }, _delay_5s)
  57. .Run(InitializeStep.ResetLinmot, ResetLinmot, _delay_1ms)
  58. .WaitWithStopCondition(InitializeStep.WaitReset, () => { return _linmotAxis.Status == RState.End; }, () => { return _linmotAxis.Status == RState.Failed; })
  59. .End(InitializeStep.End, NullFun, _delay_1ms);
  60. return Runner.Status;
  61. }
  62. /// <summary>
  63. /// Reset Linmot
  64. /// </summary>
  65. /// <returns></returns>
  66. private bool ResetLinmot()
  67. {
  68. return _linmotAxis.ResetOperation("", true);
  69. }
  70. /// <summary>
  71. /// 启动
  72. /// </summary>
  73. /// <param name="objs"></param>
  74. /// <returns></returns>
  75. /// <exception cref="NotImplementedException"></exception>
  76. public RState Start(params object[] objs)
  77. {
  78. _prewetDevice = DEVICE.GetDevice<PrewetDevice>(Module);
  79. return Runner.Start(Module, "Initialize");
  80. }
  81. }
  82. }