| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 | 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<string, DOAccessor> _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<string, DOAccessor>();            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;        }    }}
 |