SrdCommonDoorCloseRoutine.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using Aitex.Core.RT.Device;
  2. using Aitex.Core.RT.Routine;
  3. using MECF.Framework.Common.Beckhoff.ModuleIO;
  4. using MECF.Framework.Common.Routine;
  5. using MECF.Framework.Common.TwinCat;
  6. using CyberX8_Core;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using MECF.Framework.Common.IOCore;
  13. namespace CyberX8_RT.Devices.SRD
  14. {
  15. public class SrdCommonDoorCloseRoutine : RoutineBase, IRoutine
  16. {
  17. #region 常量
  18. private const string DOOR_CLOSE = "DoorClose";
  19. #endregion
  20. private enum CloseStep
  21. {
  22. DoorClose,
  23. End
  24. }
  25. #region 内部变量
  26. private bool _closeValue;
  27. private SrdCommonDevice _srdCommon;
  28. private int _timeout = 2000;
  29. #endregion
  30. /// <summary>
  31. /// 构造函数
  32. /// </summary>
  33. /// <param name="module"></param>
  34. public SrdCommonDoorCloseRoutine(string module) : base(module)
  35. {
  36. }
  37. public void Abort()
  38. {
  39. Runner.Stop("Manual Abort");
  40. }
  41. public RState Monitor()
  42. {
  43. Runner.Run(CloseStep.DoorClose, DoorClose, CheckDoorStatus, _timeout)
  44. .End(CloseStep.End, NullFun, 100);
  45. return Runner.Status;
  46. }
  47. private bool DoorClose()
  48. {
  49. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{DOOR_CLOSE}");
  50. return IOModuleManager.Instance.WriteIoValue(ioName, _closeValue);
  51. }
  52. private bool CheckDoorStatus()
  53. {
  54. return _srdCommon.CommonData.DoorClosed == _closeValue && _srdCommon.CommonData.DoorOpened == !_closeValue;
  55. }
  56. public RState Start(params object[] objs)
  57. {
  58. _closeValue = (bool)objs[0];
  59. _srdCommon = DEVICE.GetDevice<SrdCommonDevice>($"{Module}.Common");
  60. if (_closeValue)
  61. {
  62. return Runner.Start(Module, "Door Close");
  63. }
  64. else
  65. {
  66. return Runner.Start(Module, "Door Open");
  67. }
  68. }
  69. }
  70. }