ClamShellCloseRoutine.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 MECF.Framework.Common.Beckhoff.ModuleIO;
  6. using MECF.Framework.Common.CommonData.PlatingCell;
  7. using MECF.Framework.Common.IOCore;
  8. using MECF.Framework.Common.Routine;
  9. using PunkHPX8_Core;
  10. using PunkHPX8_RT.Devices.SRD;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Linq;
  14. using System.Text;
  15. using System.Threading;
  16. using System.Threading.Tasks;
  17. namespace PunkHPX8_RT.Devices.PlatingCell
  18. {
  19. public class ClamShellCloseRoutine : RoutineBase, IRoutine
  20. {
  21. private enum ClamshellClose
  22. {
  23. ClamShellClose,
  24. End
  25. }
  26. #region 常量
  27. private const string CLAMSHELL_CLOSE = "ClamShellClose";
  28. #endregion
  29. #region 内部变量
  30. private bool _close;
  31. private PlatingCellDevice _device;
  32. private int _openSensor = 55;
  33. private int _closeSensor = 5;
  34. private int _sensorCheckTime = 1000;
  35. #endregion
  36. /// <summary>
  37. /// 构造函数
  38. /// </summary>
  39. /// <param name="module"></param>
  40. public ClamShellCloseRoutine(string module):base(module)
  41. {
  42. }
  43. public void Abort()
  44. {
  45. Runner.Stop("Manual Abort");
  46. }
  47. public RState Monitor()
  48. {
  49. Runner.Run(ClamshellClose.ClamShellClose, ClamShellClose, CheckClamShellClose, _sensorCheckTime)
  50. .End(ClamshellClose.End, NullFun, 100);
  51. return Runner.Status;
  52. }
  53. private bool ClamShellClose()
  54. {
  55. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{CLAMSHELL_CLOSE}");
  56. return IOModuleManager.Instance.WriteIoValue(ioName, _close);
  57. }
  58. private bool CheckClamShellClose()
  59. {
  60. if (_close)
  61. {
  62. if (_device.PlatingCellDeviceData.ClamShellDistance <= _closeSensor)
  63. {
  64. LOG.WriteLog(eEvent.INFO_PLATINGCELL, Module, $"ClamShell is Closed");
  65. //_device.PlatingCellDeviceData.ClamShellClosed = true;
  66. //_device.PlatingCellDeviceData.ClamShellOpened = false;
  67. return true;
  68. }
  69. else
  70. {
  71. return false;
  72. }
  73. }
  74. else
  75. {
  76. if (_device.PlatingCellDeviceData.ClamShellDistance > _openSensor)
  77. {
  78. LOG.WriteLog(eEvent.INFO_PLATINGCELL, Module, $"ClamShell is Opened");
  79. //_device.PlatingCellDeviceData.ClamShellClosed = false;
  80. //_device.PlatingCellDeviceData.ClamShellOpened = true;
  81. return true;
  82. }
  83. else
  84. {
  85. return false;
  86. }
  87. }
  88. }
  89. public RState Start(params object[] objs)
  90. {
  91. _close = (bool)objs[0];
  92. _device = DEVICE.GetDevice<PlatingCellDevice>($"{Module}");
  93. _openSensor = SC.GetValue<int>("PlatingCell.ClamShellOpenDistanceThreshold");
  94. _closeSensor = SC.GetValue<int>("PlatingCell.ClamShellCloseDistanceThreshold");
  95. _sensorCheckTime = SC.GetValue<int>("PlatingCell.ClamShellOpenCheckDelay");
  96. if (_close)
  97. {
  98. return Runner.Start(Module, "ClamShell Close");
  99. }
  100. else
  101. {
  102. return Runner.Start(Module, "ClamShell Open");
  103. }
  104. }
  105. }
  106. }