using Aitex.Core.RT.Event; using Aitex.Core.RT.IOCore; using Aitex.Core.RT.Log; using Aitex.Core.Util; using MECF.Framework.Common.Device.Bases; using MECF.Framework.Common.Equipment; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Xml; namespace FurnaceRT.Equipments.Systems { public class FurnaceSingalLight : SignalLightBase { public LightType Type { get; set; } private F_TRIG _trigError = new F_TRIG(); public DOAccessor LightDO { get; set; } public DOAccessor LightDOFlash { get; set; } public FurnaceSingalLight(string module, string name) : base(module, name) { } public FurnaceSingalLight(string module, XmlElement node, string ioModule = "") : base(module, module) { base.Module = string.IsNullOrEmpty(node.GetAttribute("module")) ? module : node.GetAttribute("module"); base.Name = node.GetAttribute("id"); base.Display = node.GetAttribute("display"); base.DeviceID = node.GetAttribute("schematicId"); LightDO = ParseDoNode("doLight", node, ioModule); LightDOFlash = ParseDoNode("doFlashLight", node, ioModule); } protected override void SetOn() { SetLight(TowerLightStatus.On); } protected override void SetOff() { SetLight(TowerLightStatus.Off); } protected override void SetBlinking(bool token) { SetLight(TowerLightStatus.Blinking); } public override void SetLight(TowerLightStatus setpoint) { try { string reason = string.Empty; _trigError.CLK = (LightDO != null && LightDO.SetValue(setpoint == TowerLightStatus.On ? true : false, out reason)) || (LightDOFlash != null && LightDOFlash.SetValue(setpoint == TowerLightStatus.Blinking ? true : false, out reason)); if (_trigError.Q) { EV.PostWarningLog(Module, $"Set {Type} signal light {setpoint} error, {reason}"); } } catch (Exception ex) { LOG.Write(ex); } } public override void Reset() { _trigError.RST = true; base.Reset(); } } public class FurnaceSignalTower : SignalTowerBase { private Dictionary _lightDoDic; public FurnaceSignalTower(string module, XmlElement node, string ioModule = "") : base(module, module) { base.Module = string.IsNullOrEmpty(node.GetAttribute("module")) ? module : node.GetAttribute("module"); base.Name = node.GetAttribute("id"); base.Display = node.GetAttribute("display"); base.DeviceID = node.GetAttribute("schematicId"); _lightDoDic = new Dictionary(); DOAccessor doRed = ParseDoNode("doRed", node, ioModule); if (doRed != null) { _lightDoDic.Add(LightType.Red.ToString(), doRed); } DOAccessor doYellow = ParseDoNode("doYellow", node, ioModule); if (doYellow != null) { _lightDoDic.Add(LightType.Yellow.ToString(), doYellow); } DOAccessor doGreen = ParseDoNode("doGreen", node, ioModule); if (doGreen != null) { _lightDoDic.Add(LightType.Green.ToString(), doGreen); } DOAccessor doBlue = ParseDoNode("doBlue", node, ioModule); if (doBlue != null) { _lightDoDic.Add(LightType.Blue.ToString(), doBlue); } DOAccessor doWhite = ParseDoNode("doWhite", node, ioModule); if (doWhite != null) { _lightDoDic.Add(LightType.White.ToString(), doWhite); } DOAccessor doBuzzer1 = ParseDoNode("doBuzzer1", node, ioModule); if (doBuzzer1 != null) { _lightDoDic.Add(LightType.Buzzer1.ToString(), doBuzzer1); } DOAccessor doBuzzer2 = ParseDoNode("doBuzzer2", node, ioModule); if (doBuzzer2 != null) { _lightDoDic.Add(LightType.Buzzer2.ToString(), doBuzzer2); } DOAccessor doRedFlash = ParseDoNode("doRedFlash", node, ioModule); if (doRed != null) { _lightDoDic.Add(LightType.Red.ToString() + "Flash", doRedFlash); } DOAccessor doYellowFlash = ParseDoNode("doYellowFlash", node, ioModule); if (doYellow != null) { _lightDoDic.Add(LightType.Yellow.ToString() + "Flash", doYellowFlash); } DOAccessor doGreenFlash = ParseDoNode("doGreenFlash", node, ioModule); if (doGreen != null) { _lightDoDic.Add(LightType.Green.ToString() + "Flash", doGreenFlash); } DOAccessor doBlueFlash = ParseDoNode("doBlueFlash", node, ioModule); if (doBlue != null) { _lightDoDic.Add(LightType.Blue.ToString() + "Flash", doBlueFlash); } } public override bool Initialize() { CustomSignalTower(); return base.Initialize(); } public override SignalLightBase CreateLight(LightType type) { if (!_lightDoDic.ContainsKey(type.ToString())) { return null; } return new FurnaceSingalLight(ModuleName.System.ToString(), $"SignalLight{type}") { Type = type, LightDO = _lightDoDic[type.ToString()], LightDOFlash = _lightDoDic.ContainsKey(type.ToString() + "Flash") ? _lightDoDic[type.ToString() + "Flash"] : null, }; } public bool SetLight(LightType type, TowerLightStatus setpoint) { if(_lights == null || !_lights.ContainsKey(type)) { return false; } (_lights[type] as FurnaceSingalLight)?.SetLight(setpoint); return true; } } }