FurnaceSignalTower.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. using Aitex.Core.RT.Event;
  2. using Aitex.Core.RT.IOCore;
  3. using Aitex.Core.RT.Log;
  4. using Aitex.Core.Util;
  5. using MECF.Framework.Common.Device.Bases;
  6. using MECF.Framework.Common.Equipment;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Xml;
  13. namespace FurnaceRT.Equipments.Systems
  14. {
  15. public class FurnaceSingalLight : SignalLightBase
  16. {
  17. public LightType Type { get; set; }
  18. private F_TRIG _trigError = new F_TRIG();
  19. public DOAccessor LightDO { get; set; }
  20. public DOAccessor LightDOFlash { get; set; }
  21. public FurnaceSingalLight(string module, string name) : base(module, name)
  22. {
  23. }
  24. public FurnaceSingalLight(string module, XmlElement node, string ioModule = "") : base(module, module)
  25. {
  26. base.Module = string.IsNullOrEmpty(node.GetAttribute("module")) ? module : node.GetAttribute("module");
  27. base.Name = node.GetAttribute("id");
  28. base.Display = node.GetAttribute("display");
  29. base.DeviceID = node.GetAttribute("schematicId");
  30. LightDO = ParseDoNode("doLight", node, ioModule);
  31. LightDOFlash = ParseDoNode("doFlashLight", node, ioModule);
  32. }
  33. protected override void SetOn()
  34. {
  35. SetLight(TowerLightStatus.On);
  36. }
  37. protected override void SetOff()
  38. {
  39. SetLight(TowerLightStatus.Off);
  40. }
  41. protected override void SetBlinking(bool token)
  42. {
  43. SetLight(TowerLightStatus.Blinking);
  44. }
  45. public override void SetLight(TowerLightStatus setpoint)
  46. {
  47. try
  48. {
  49. string reason = string.Empty;
  50. _trigError.CLK = LightDO != null && LightDO.SetValue(setpoint == TowerLightStatus.On ? true : false, out reason);
  51. if (_trigError.Q)
  52. {
  53. EV.PostWarningLog(Module, $"Set {Type} signal light {setpoint} error, {reason}");
  54. }
  55. }
  56. catch (Exception ex)
  57. {
  58. LOG.Write(ex);
  59. }
  60. }
  61. public override void Reset()
  62. {
  63. _trigError.RST = true;
  64. base.Reset();
  65. }
  66. }
  67. public class FurnaceSignalTower : SignalTowerBase
  68. {
  69. private Dictionary<string, DOAccessor> _lightDoDic;
  70. public FurnaceSignalTower(string module, XmlElement node, string ioModule = "") : base(module, module)
  71. {
  72. base.Module = string.IsNullOrEmpty(node.GetAttribute("module")) ? module : node.GetAttribute("module");
  73. base.Name = node.GetAttribute("id");
  74. base.Display = node.GetAttribute("display");
  75. base.DeviceID = node.GetAttribute("schematicId");
  76. _lightDoDic = new Dictionary<string, DOAccessor>();
  77. DOAccessor doRed = ParseDoNode("doRed", node, ioModule);
  78. if (doRed != null)
  79. {
  80. _lightDoDic.Add(LightType.Red.ToString(), doRed);
  81. }
  82. DOAccessor doYellow = ParseDoNode("doYellow", node, ioModule);
  83. if (doYellow != null)
  84. {
  85. _lightDoDic.Add(LightType.Yellow.ToString(), doYellow);
  86. }
  87. DOAccessor doGreen = ParseDoNode("doGreen", node, ioModule);
  88. if (doGreen != null)
  89. {
  90. _lightDoDic.Add(LightType.Green.ToString(), doGreen);
  91. }
  92. DOAccessor doBlue = ParseDoNode("doBlue", node, ioModule);
  93. if (doBlue != null)
  94. {
  95. _lightDoDic.Add(LightType.Blue.ToString(), doBlue);
  96. }
  97. DOAccessor doWhite = ParseDoNode("doWhite", node, ioModule);
  98. if (doWhite != null)
  99. {
  100. _lightDoDic.Add(LightType.White.ToString(), doWhite);
  101. }
  102. DOAccessor doBuzzer1 = ParseDoNode("doBuzzer1", node, ioModule);
  103. if (doBuzzer1 != null)
  104. {
  105. _lightDoDic.Add(LightType.Buzzer1.ToString(), doBuzzer1);
  106. }
  107. DOAccessor doBuzzer2 = ParseDoNode("doBuzzer2", node, ioModule);
  108. if (doBuzzer2 != null)
  109. {
  110. _lightDoDic.Add(LightType.Buzzer2.ToString(), doBuzzer2);
  111. }
  112. DOAccessor doRedFlash = ParseDoNode("doRedFlash", node, ioModule);
  113. if (doRed != null)
  114. {
  115. _lightDoDic.Add(LightType.Red.ToString() + "Flash", doRedFlash);
  116. }
  117. DOAccessor doYellowFlash = ParseDoNode("doYellowFlash", node, ioModule);
  118. if (doYellow != null)
  119. {
  120. _lightDoDic.Add(LightType.Yellow.ToString() + "Flash", doYellowFlash);
  121. }
  122. DOAccessor doGreenFlash = ParseDoNode("doGreenFlash", node, ioModule);
  123. if (doGreen != null)
  124. {
  125. _lightDoDic.Add(LightType.Green.ToString() + "Flash", doGreenFlash);
  126. }
  127. DOAccessor doBlueFlash = ParseDoNode("doBlueFlash", node, ioModule);
  128. if (doBlue != null)
  129. {
  130. _lightDoDic.Add(LightType.Blue.ToString() + "Flash", doBlueFlash);
  131. }
  132. }
  133. public override bool Initialize()
  134. {
  135. CustomSignalTower();
  136. return base.Initialize();
  137. }
  138. public override SignalLightBase CreateLight(LightType type)
  139. {
  140. if (!_lightDoDic.ContainsKey(type.ToString()))
  141. {
  142. return null;
  143. }
  144. return new FurnaceSingalLight(ModuleName.System.ToString(), $"SignalLight{type}")
  145. {
  146. Type = type,
  147. LightDO = _lightDoDic[type.ToString()],
  148. LightDOFlash = _lightDoDic.ContainsKey(type.ToString() + "Flash") ? _lightDoDic[type.ToString() + "Flash"] : null,
  149. };
  150. }
  151. public bool SetLight(LightType type, TowerLightStatus setpoint)
  152. {
  153. if (_lights == null || !_lights.ContainsKey(type))
  154. {
  155. return false;
  156. }
  157. (_lights[type] as FurnaceSingalLight)?.SetLight(setpoint);
  158. return true;
  159. }
  160. }
  161. }