SunWaySignalLight.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. using Aitex.Core.RT.Log;
  2. using Aitex.Core.Util;
  3. using MECF.Framework.Common.Device.Bases;
  4. using CyberX8_RT.Devices.EFEM;
  5. using CyberX8_RT.Modules;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using MECF.Framework.Common.IOCore;
  12. using System.Runtime.InteropServices;
  13. using MECF.Framework.Common.Beckhoff.ModuleIO;
  14. using static Mono.Security.X509.X520;
  15. namespace CyberX8_RT.Devices.SignalLight
  16. {
  17. public class SunWaySignalLight : SignalLightBase
  18. {
  19. #region 常量
  20. private const string LIGHTER_TOWER = "LightTower";
  21. private const string BUZZER = "Buzzer";
  22. private const string RED_LIGHT = "RedLight";
  23. private const string YELLOW_LIGHT = "YellowLight";
  24. private const string GREEN_LIGHT = "GreenLight";
  25. private const string BLUE_LIGHT = "BlueLight";
  26. #endregion
  27. public MECF.Framework.Common.Device.Bases.LightType Type { get; set; }
  28. private F_TRIG _trigError = new F_TRIG();
  29. private bool _isInit;
  30. private TowerLightStatus _preState = TowerLightStatus.Unknown;
  31. //IoSignalTower _SignalTower;
  32. public SunWaySignalLight(string module, string name, EfemBase _efem) : base(module, name)
  33. {
  34. _isInit = true;
  35. //EfemController = _efem;
  36. }
  37. protected override void SetOn()
  38. {
  39. SetLight(TowerLightStatus.On);
  40. }
  41. protected override void SetOff()
  42. {
  43. SetLight(TowerLightStatus.Off);
  44. }
  45. protected override void SetBlinking(bool token)
  46. {
  47. SetLight(token?TowerLightStatus.On:TowerLightStatus.Off);
  48. }
  49. private bool SetSignalLight(MECF.Framework.Common.Device.Bases.LightType type, TowerLightStatus setpoint)
  50. {
  51. LightType lightType;
  52. switch (type)
  53. {
  54. case MECF.Framework.Common.Device.Bases.LightType.Red:
  55. lightType = LightType.RED;
  56. break;
  57. case MECF.Framework.Common.Device.Bases.LightType.Yellow:
  58. lightType = LightType.YELLOW;
  59. break;
  60. case MECF.Framework.Common.Device.Bases.LightType.Green:
  61. lightType = LightType.GREEN;
  62. break;
  63. case MECF.Framework.Common.Device.Bases.LightType.White:
  64. lightType = LightType.WHITE;
  65. break;
  66. case MECF.Framework.Common.Device.Bases.LightType.Blue:
  67. lightType = LightType.BLUE;
  68. break;
  69. case MECF.Framework.Common.Device.Bases.LightType.Buzzer:
  70. case MECF.Framework.Common.Device.Bases.LightType.Buzzer1:
  71. lightType = LightType.BUZZER1;
  72. break;
  73. default:
  74. lightType = LightType.BUZZER1;
  75. break;
  76. }
  77. LightStatus lightSetpoint;
  78. switch (setpoint)
  79. {
  80. case TowerLightStatus.Blinking:
  81. lightSetpoint = LightStatus.BLINK;
  82. //lightState = LightState.Blink;
  83. break;
  84. case TowerLightStatus.On:
  85. lightSetpoint = LightStatus.ON;
  86. break;
  87. case TowerLightStatus.Off:
  88. lightSetpoint = LightStatus.OFF;
  89. break;
  90. default:
  91. lightSetpoint = LightStatus.OFF;
  92. break;
  93. }
  94. bool lightValue=lightSetpoint==LightStatus.ON?true:false;
  95. string ioLight = GetIOLight(lightType);
  96. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName(ioLight);
  97. if (!string.IsNullOrEmpty(ioName))
  98. {
  99. return IOModuleManager.Instance.WriteIoValue(ioName, lightValue);
  100. }
  101. return false;
  102. }
  103. private string GetIOLight(LightType lightType)
  104. {
  105. switch (lightType)
  106. {
  107. case LightType.RED:
  108. return $"{LIGHTER_TOWER}.{RED_LIGHT}";
  109. case LightType.GREEN:
  110. return $"{LIGHTER_TOWER}.{GREEN_LIGHT}";
  111. case LightType.BLUE:
  112. return $"{LIGHTER_TOWER}.{BLUE_LIGHT}";
  113. case LightType.YELLOW:
  114. return $"{LIGHTER_TOWER}.{YELLOW_LIGHT}";
  115. case LightType.BUZZER1:
  116. return $"{LIGHTER_TOWER}.{BUZZER}";
  117. default:
  118. return $"{LIGHTER_TOWER}.{BUZZER}";
  119. }
  120. }
  121. private void SetLight(TowerLightStatus setpoint)
  122. {
  123. try
  124. {
  125. if (setpoint != _preState || _isInit)
  126. {
  127. _trigError.CLK = SetSignalLight(Type, setpoint);
  128. //if (_trigError.Q)
  129. //{
  130. // //EV.PostWarningLog(Module, $"Set {Type} signal light {setpoint} error, {reason}");
  131. //}
  132. if (_trigError.M)
  133. {
  134. _isInit = false;
  135. _preState = setpoint;
  136. }
  137. }
  138. }
  139. catch (Exception ex)
  140. {
  141. LOG.WriteExeption(ex);
  142. }
  143. }
  144. public void ResetData()
  145. {
  146. _isInit = true;
  147. }
  148. public override void Reset()
  149. {
  150. _trigError.RST = true;
  151. base.Reset();
  152. }
  153. }
  154. }