StandardHotMetalCellPumpRoutine.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. using MECF.Framework.Common.ToolLayout;
  15. namespace CyberX8_RT.Devices.Metal
  16. {
  17. public class StandardHotMetalCellPumpRoutine : RoutineBase, IRoutine
  18. {
  19. private enum PumpStep
  20. {
  21. Pump,
  22. Delay,
  23. CheckFlow,
  24. End
  25. }
  26. #region 常量
  27. private const string CELL_PUMP = "CellPump";
  28. #endregion
  29. #region 内部变量
  30. private int _cellFlowFaultHoldOffTime = 5000;
  31. private double _minPumpFlow = 0.2;
  32. private bool _pumpOn = false;
  33. private bool _isSignalPump = false;
  34. private StandardHotMetalDevice _device;
  35. #endregion
  36. /// <summary>
  37. /// 构造函数
  38. /// </summary>
  39. /// <param name="module"></param>
  40. public StandardHotMetalCellPumpRoutine(string module) : base(module)
  41. {
  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.RunIf(PumpStep.Pump, _isSignalPump, ExecutePump, () => { return _device.MetalDeviceData.CellPump ==_pumpOn; }, _delay_1s)
  57. .Delay(PumpStep.Delay, _cellFlowFaultHoldOffTime)
  58. .RunIf(PumpStep.CheckFlow, _pumpOn, CheckFlow, NullFun, _delay_1ms)
  59. .End(PumpStep.End, NullFun, _delay_1ms);
  60. return Runner.Status;
  61. }
  62. /// <summary>
  63. /// 执行Pump开或关
  64. /// </summary>
  65. /// <returns></returns>
  66. private bool ExecutePump()
  67. {
  68. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{CELL_PUMP}");
  69. return IOModuleManager.Instance.WriteIoValue(ioName, _pumpOn);
  70. }
  71. /// <summary>
  72. /// 检验Flow
  73. /// </summary>
  74. /// <returns></returns>
  75. private bool CheckFlow()
  76. {
  77. return _device.MetalDeviceData.CellFlow >= _minPumpFlow;
  78. }
  79. /// <summary>
  80. /// 启动
  81. /// </summary>
  82. /// <param name="objs"></param>
  83. /// <returns></returns>
  84. public RState Start(params object[] objs)
  85. {
  86. _pumpOn=(bool)objs[0];
  87. _device = DEVICE.GetDevice<StandardHotMetalDevice>(Module.ToString());
  88. _cellFlowFaultHoldOffTime = SC.GetValue<int>("Metal.CellFlowFaultHoldOffTime");
  89. _minPumpFlow = SC.GetValue<double>("Metal.MinPumpFlow");
  90. if(!_pumpOn)
  91. {
  92. _cellFlowFaultHoldOffTime = 0;
  93. }
  94. MetalItem metalItem = MetalItemManager.Instance.GetMetalItem(Module);
  95. if (metalItem != null && metalItem.DepPump)
  96. {
  97. _isSignalPump = true;
  98. }
  99. return Runner.Start(Module.ToString(), "Cell Pump");
  100. }
  101. }
  102. }