TransporterUnlockRoutine.cs 2.9 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.CommonData.PUF;
  6. using MECF.Framework.Common.Equipment;
  7. using MECF.Framework.Common.Routine;
  8. using MECF.Framework.Common.TwinCat;
  9. using CyberX8_Core;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. using MECF.Framework.Common.IOCore;
  16. namespace CyberX8_RT.Devices.TransPorter
  17. {
  18. public class TransporterUnlockRoutine : RoutineBase, IRoutine
  19. {
  20. private enum LockStep
  21. {
  22. WriteLock,
  23. End
  24. }
  25. #region 常量
  26. private const string UNLOCK = "Unlock";
  27. #endregion
  28. #region 内部变量
  29. private int _timeout = 5000;
  30. private TransporterCommon _transporterCommon;
  31. #endregion
  32. /// <summary>
  33. /// 构造函数
  34. /// </summary>
  35. /// <param name="module"></param>
  36. public TransporterUnlockRoutine(string module) : base(module)
  37. {
  38. }
  39. /// <summary>
  40. /// 中止
  41. /// </summary>
  42. public void Abort()
  43. {
  44. Runner.Stop("Manual Abort");
  45. }
  46. /// <summary>
  47. /// 监控
  48. /// </summary>
  49. /// <returns></returns>
  50. public RState Monitor()
  51. {
  52. Runner.Run(LockStep.WriteLock, WriteLock, CheckLock,_timeout)
  53. .End(LockStep.End,NullFun,100);
  54. return Runner.Status;
  55. }
  56. /// <summary>
  57. /// 写入Lock数值
  58. /// </summary>
  59. /// <returns></returns>
  60. private bool WriteLock()
  61. {
  62. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{UNLOCK}");
  63. if(!string.IsNullOrEmpty(ioName))
  64. {
  65. return IOModuleManager.Instance.WriteIoValue(ioName, true);
  66. }
  67. else
  68. {
  69. return false;
  70. }
  71. }
  72. /// <summary>
  73. /// 检验 Lock状态
  74. /// </summary>
  75. /// <returns></returns>
  76. private bool CheckLock()
  77. {
  78. return _transporterCommon.TransporterData.Unlocked1 && _transporterCommon.TransporterData.Unlocked2;
  79. }
  80. /// <summary>
  81. /// 启动
  82. /// </summary>
  83. /// <param name="objs"></param>
  84. /// <returns></returns>
  85. public RState Start(params object[] objs)
  86. {
  87. if (SC.ContainsItem($"Transporter.{Module}.UnlockCheckTime"))
  88. {
  89. _timeout = SC.GetValue<int>($"Transporter.{Module}.UnlockCheckTime") * 1000;
  90. }
  91. _transporterCommon = DEVICE.GetDevice<TransporterCommon>($"{Module}.Common");
  92. return Runner.Start(Module, "Unlock");
  93. }
  94. }
  95. }