FutureSignalTower.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Xml;
  7. using Aitex.Core.RT.Device;
  8. using Aitex.Core.RT.Log;
  9. using Aitex.Core.Util;
  10. using MECF.Framework.Common.Device.Bases;
  11. using MECF.Framework.Common.Equipment;
  12. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Efems;
  13. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Efems.Rorzes;
  14. namespace FutureEfemLib.SignalTowers
  15. {
  16. class RorzeSingalLight : SignalLightBase
  17. {
  18. public LightType Type { get; set; }
  19. public IEfemController EfemController { get; set; }
  20. private F_TRIG _trigError = new F_TRIG();
  21. private bool _isInit;
  22. private TowerLightStatus _preState = TowerLightStatus.Unknown;
  23. public RorzeSingalLight(string module, string name) : base(module, name)
  24. {
  25. _isInit = true;
  26. }
  27. protected override void SetOn()
  28. {
  29. SetLight(TowerLightStatus.On);
  30. }
  31. protected override void SetOff()
  32. {
  33. SetLight(TowerLightStatus.Off);
  34. }
  35. protected override void SetBlinking(bool token)
  36. {
  37. SetLight(TowerLightStatus.Blinking);
  38. }
  39. private void SetLight(TowerLightStatus setpoint)
  40. {
  41. try
  42. {
  43. if (setpoint != _preState || _isInit)
  44. {
  45. _trigError.CLK = EfemController.SetSignalLight(Type, setpoint, out string reason);
  46. if (_trigError.Q)
  47. {
  48. //EV.PostWarningLog(Module, $"Set {Type} signal light {setpoint} error, {reason}");
  49. }
  50. if (_trigError.M)
  51. {
  52. _isInit = false;
  53. _preState = setpoint;
  54. }
  55. }
  56. }
  57. catch (Exception ex)
  58. {
  59. LOG.Write(ex);
  60. }
  61. }
  62. public void ResetData()
  63. {
  64. _isInit = true;
  65. }
  66. public override void Reset()
  67. {
  68. _trigError.RST = true;
  69. base.Reset();
  70. }
  71. }
  72. public class FutureSignalTower : SignalTowerBase, IEfemSignalTowerCallback
  73. {
  74. private string _efemName;
  75. private IRorzeEfemController _efem;
  76. private List<RorzeSingalLight> _lstLight = new List<RorzeSingalLight>();
  77. public FutureSignalTower(string module, XmlElement node, string ioModule) : base("", "")
  78. {
  79. var attrModule = node.GetAttribute("module");
  80. base.Module = string.IsNullOrEmpty(attrModule) ? module : attrModule;
  81. base.Name = node.GetAttribute("id");
  82. base.Display = node.GetAttribute("display");
  83. base.DeviceID = node.GetAttribute("schematicId");
  84. _efemName = node.GetAttribute("efem");
  85. }
  86. public FutureSignalTower(string module, string name, string efemName) : base("", "")
  87. {
  88. base.Module = module;
  89. base.Name = name;
  90. _efemName = efemName;
  91. }
  92. public override bool Initialize()
  93. {
  94. base.Initialize();
  95. if (_efem == null && !string.IsNullOrEmpty(_efemName))
  96. {
  97. _efem = DEVICE.GetDevice<RorzeEfem>(_efemName);
  98. _efem.SetSignalTowerCallback(ModuleHelper.Converter(Module), this);
  99. }
  100. CustomSignalTower();
  101. return true;
  102. }
  103. //重新连接EFEM之后,需要重置灯塔
  104. public void ResetData()
  105. {
  106. foreach (var rorzeSingalLight in _lstLight)
  107. {
  108. rorzeSingalLight.ResetData();
  109. }
  110. }
  111. public override SignalLightBase CreateLight(LightType type)
  112. {
  113. var light = new RorzeSingalLight(ModuleName.System.ToString(), $"SignalLight{type}")
  114. { Type = type, EfemController = _efem };
  115. _lstLight.Add(light);
  116. return light;
  117. }
  118. }
  119. }