SunWaySignalLight.cs 4.3 KB

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