SrdCommonFlipperRoutine.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. using Aitex.Core.Common;
  2. using Aitex.Core.RT.Device;
  3. using Aitex.Core.RT.Log;
  4. using Aitex.Core.RT.Routine;
  5. using Aitex.Core.UI.Control;
  6. using CyberX8_Core;
  7. using MECF.Framework.Common.Beckhoff.ModuleIO;
  8. using MECF.Framework.Common.IOCore;
  9. using MECF.Framework.Common.Routine;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading;
  15. using System.Threading.Tasks;
  16. namespace CyberX8_RT.Devices.SRD
  17. {
  18. public class SrdCommonFlipperRoutine : RoutineBase, IRoutine
  19. {
  20. #region 常量
  21. private const string FLIPPERS_IN_100 = "FlippersIn100";
  22. private const string FLIPPERS_IN_150 = "FlippersIn150";
  23. private const string FLIPPERS_IN_200 = "FlippersIn200";
  24. #endregion
  25. private enum FlipperStep
  26. {
  27. Flipper,
  28. Delay,
  29. CheckFlipperStatus,
  30. End
  31. }
  32. #region 内部变量
  33. private bool _flipperIn;
  34. private int _waferSize = 200;
  35. private SrdCommonDevice _srdCommon;
  36. private int _timeout = 3000;
  37. #endregion
  38. /// <summary>
  39. /// 构造函数
  40. /// </summary>
  41. /// <param name="module"></param>
  42. public SrdCommonFlipperRoutine(string module) : base(module)
  43. {
  44. }
  45. public void Abort()
  46. {
  47. Runner.Stop("Manual Abort");
  48. }
  49. public RState Monitor()
  50. {
  51. Runner.Run(FlipperStep.Flipper, FlipperPosition, _delay_1ms)
  52. .DelayIf(FlipperStep.Delay, !_flipperIn, 500)
  53. .Run(FlipperStep.CheckFlipperStatus, NullFun, CheckFlipperOutEndStatus, _timeout)
  54. .End(FlipperStep.End, NullFun, 100);
  55. return Runner.Status;
  56. }
  57. public RState Start(params object[] objs)
  58. {
  59. if (objs.Length < 2) return RState.Failed;
  60. _flipperIn = (bool)objs[0];
  61. _waferSize = (int)objs[1];
  62. _srdCommon = DEVICE.GetDevice<SrdCommonDevice>($"{Module}.Common");
  63. if (_flipperIn)
  64. {
  65. return Runner.Start(Module, "Flippers In");
  66. }
  67. else
  68. {
  69. return Runner.Start(Module, "Flippers Out");
  70. }
  71. }
  72. /// <summary>
  73. /// Flipper Position
  74. /// </summary>
  75. /// <returns></returns>
  76. private bool FlipperPosition()
  77. {
  78. string variableName;
  79. switch (_waferSize)
  80. {
  81. case 100:
  82. variableName = FLIPPERS_IN_100;
  83. break;
  84. case 150:
  85. variableName = FLIPPERS_IN_150;
  86. break;
  87. case 200:
  88. variableName = FLIPPERS_IN_200;
  89. break;
  90. default:
  91. NotifyError(eEvent.ERR_SRD, $"Wafer Size {_waferSize} is invalid", 0);
  92. return false;
  93. }
  94. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{variableName}");
  95. return IOModuleManager.Instance.WriteIoValue(ioName, _flipperIn);
  96. }
  97. /// <summary>
  98. /// CheckFlipperOutStatus
  99. /// </summary>
  100. /// <returns></returns>
  101. private bool CheckFlipperOutEndStatus()
  102. {
  103. bool result = false;
  104. switch (_waferSize)
  105. {
  106. case 100:
  107. result = _flipperIn ? (!_srdCommon.CommonData.Flipper1Out100Status && !_srdCommon.CommonData.Flipper2Out100Status && !_srdCommon.CommonData.Flipper3Out100Status)
  108. : (_srdCommon.CommonData.Flipper1Out100Status && _srdCommon.CommonData.Flipper2Out100Status && _srdCommon.CommonData.Flipper3Out100Status);
  109. break;
  110. case 150:
  111. result = _flipperIn ? (!_srdCommon.CommonData.Flipper1Out150Status && !_srdCommon.CommonData.Flipper2Out150Status && !_srdCommon.CommonData.Flipper3Out150Status)
  112. : (_srdCommon.CommonData.Flipper1Out150Status && _srdCommon.CommonData.Flipper2Out150Status && _srdCommon.CommonData.Flipper3Out150Status);
  113. break;
  114. case 200:
  115. result = _flipperIn ? (!_srdCommon.CommonData.Flipper1Out200Status && !_srdCommon.CommonData.Flipper2Out200Status && !_srdCommon.CommonData.Flipper3Out200Status)
  116. : (_srdCommon.CommonData.Flipper1Out200Status && _srdCommon.CommonData.Flipper2Out200Status && _srdCommon.CommonData.Flipper3Out200Status);
  117. break;
  118. default:
  119. NotifyError(eEvent.WARN_SRD, $"Wafer Size {_waferSize} is invalid", 0);
  120. result = false;
  121. break;
  122. }
  123. return result;
  124. }
  125. }
  126. }