SunWaySignalLight.cs 5.6 KB

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