SrdCommonLiftUpRoutine.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using Aitex.Core.RT.Device;
  2. using Aitex.Core.RT.Log;
  3. using Aitex.Core.RT.Routine;
  4. using Aitex.Core.RT.SCCore;
  5. using CyberX8_Core;
  6. using MECF.Framework.Common.Beckhoff.ModuleIO;
  7. using MECF.Framework.Common.IOCore;
  8. using MECF.Framework.Common.Routine;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. namespace CyberX8_RT.Devices.SRD
  15. {
  16. public class SrdCommonLiftUpRoutine : RoutineBase, IRoutine
  17. {
  18. #region 常量
  19. private const string LIFT_UP = "LiftUp";
  20. #endregion
  21. private enum LiftUpStep
  22. {
  23. LiftUp,
  24. End
  25. }
  26. #region 内部变量
  27. private bool _liftUp;
  28. private SrdCommonDevice _srdCommon;
  29. private int _timeout = 1000;
  30. #endregion
  31. /// <summary>
  32. /// 构造函数
  33. /// </summary>
  34. /// <param name="module"></param>
  35. public SrdCommonLiftUpRoutine(string module) : base(module)
  36. {
  37. }
  38. public void Abort()
  39. {
  40. Runner.Stop("Manual Abort");
  41. }
  42. public RState Monitor()
  43. {
  44. Runner.Run(LiftUpStep.LiftUp, LiftUp, CheckLiftUpStatus, _timeout)
  45. .End(LiftUpStep.End, NullFun, 100);
  46. return Runner.Status;
  47. }
  48. private bool LiftUp()
  49. {
  50. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{LIFT_UP}");
  51. return IOModuleManager.Instance.WriteIoValue(ioName, _liftUp);
  52. }
  53. private bool CheckLiftUpStatus()
  54. {
  55. if (_srdCommon.CommonData.LiftUpStatus == _liftUp)
  56. {
  57. LOG.WriteLog(eEvent.INFO_SRD, Module, $"LiftUp Sensor is {_liftUp}");
  58. return true;
  59. }
  60. else
  61. {
  62. LOG.WriteLog(eEvent.INFO_SRD, Module, $"LiftUp Sensor is {_liftUp}");
  63. return false;
  64. }
  65. }
  66. public RState Start(params object[] objs)
  67. {
  68. _liftUp = (bool)objs[0];
  69. _srdCommon = DEVICE.GetDevice<SrdCommonDevice>($"{Module}.Common");
  70. if (_liftUp)
  71. {
  72. return Runner.Start(Module, "Lift Up On");
  73. }
  74. else
  75. {
  76. return Runner.Start(Module, "Lift Up Off");
  77. }
  78. }
  79. }
  80. }