StandardHotMetalCellPumpRoutine.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. using Aitex.Core.RT.Device;
  2. using Aitex.Core.RT.Routine;
  3. using Aitex.Core.RT.SCCore;
  4. using MECF.Framework.Common.Beckhoff.ModuleIO;
  5. using MECF.Framework.Common.Routine;
  6. using MECF.Framework.Common.TwinCat;
  7. using CyberX8_Core;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using MECF.Framework.Common.IOCore;
  14. namespace CyberX8_RT.Devices.Metal
  15. {
  16. public class StandardHotMetalCellPumpRoutine : RoutineBase, IRoutine
  17. {
  18. private enum PumpStep
  19. {
  20. Pump,
  21. Delay,
  22. CheckFlow,
  23. End
  24. }
  25. #region 常量
  26. private const string CELL_PUMP = "CellPump";
  27. #endregion
  28. #region 内部变量
  29. private int _cellFlowFaultHoldOffTime = 5000;
  30. private double _minPumpFlow = 0.2;
  31. private bool _pumpOn = false;
  32. private StandardHotMetalDevice _device;
  33. #endregion
  34. /// <summary>
  35. /// 构造函数
  36. /// </summary>
  37. /// <param name="module"></param>
  38. public StandardHotMetalCellPumpRoutine(string module) : base(module)
  39. {
  40. }
  41. /// <summary>
  42. /// 中止
  43. /// </summary>
  44. public void Abort()
  45. {
  46. Runner.Stop("Manual Abort");
  47. }
  48. /// <summary>
  49. /// 监控
  50. /// </summary>
  51. /// <returns></returns>
  52. public RState Monitor()
  53. {
  54. Runner.Run(PumpStep.Pump, ExecutePump, () => { return _device.MetalDeviceData.CellPump==_pumpOn; }, _delay_1ms)
  55. .Delay(PumpStep.Delay, _cellFlowFaultHoldOffTime)
  56. .RunIf(PumpStep.CheckFlow, _pumpOn, CheckFlow, NullFun, _delay_1ms)
  57. .End(PumpStep.End, NullFun, _delay_1ms);
  58. return Runner.Status;
  59. }
  60. /// <summary>
  61. /// 执行Pump开或关
  62. /// </summary>
  63. /// <returns></returns>
  64. private bool ExecutePump()
  65. {
  66. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{CELL_PUMP}");
  67. return IOModuleManager.Instance.WriteIoValue(ioName, _pumpOn);
  68. }
  69. /// <summary>
  70. /// 检验Flow
  71. /// </summary>
  72. /// <returns></returns>
  73. private bool CheckFlow()
  74. {
  75. return _device.MetalDeviceData.CellFlow >= _minPumpFlow;
  76. }
  77. /// <summary>
  78. /// 启动
  79. /// </summary>
  80. /// <param name="objs"></param>
  81. /// <returns></returns>
  82. public RState Start(params object[] objs)
  83. {
  84. _pumpOn=(bool)objs[0];
  85. _device = DEVICE.GetDevice<StandardHotMetalDevice>(Module.ToString());
  86. _cellFlowFaultHoldOffTime = SC.GetValue<int>("Metal.CellFlowFaultHoldOffTime");
  87. _minPumpFlow = SC.GetValue<double>("Metal.MinPumpFlow");
  88. if(!_pumpOn)
  89. {
  90. _cellFlowFaultHoldOffTime = 0;
  91. }
  92. return Runner.Start(Module.ToString(), "Cell Pump");
  93. }
  94. }
  95. }