| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313 | using System;using System.Xml;using Aitex.Core.Common.DeviceData;using Aitex.Core.RT.DataCenter;using Aitex.Core.RT.Event;using Aitex.Core.RT.IOCore;using Aitex.Core.RT.OperationCenter;using Aitex.Core.Util;namespace Aitex.Core.RT.Device.Unit{    public class IoHeater : BaseDevice, IDevice    {        public double SetPointLimit        {            get            {                if (_aoSetPointLimit != null)                    return _aoSetPointLimit.Value;                return 100;            }        }        [Subscription(AITHeaterPropertyName.MonitorTcFeedback)]        public float MonitorTcFeedback        {            get            {                if (_aiMonitorTcFeedback != null)                    return _aiMonitorTcFeedback.Value;                return 0;            }        }        [Subscription(AITHeaterPropertyName.ControlTcFeedback)]        public float ControlTcFeedback        {            get            {                if (_aiControlTcFeedback != null)                    return _aiControlTcFeedback.Value;                return 0;            }        }        [Subscription(AITHeaterPropertyName.ControlTcSetPoint)]        public float ControlTcSetPoint        {            get            {                if (_aoSetPoint != null)                    return _aoSetPoint.Value;                return 0;            }        }        [Subscription(AITHeaterPropertyName.IsMonitorTcBroken)]        public bool IsMonitorTcBroken        {            get            {                if (_diMonitorTcBroken != null)                    return _diMonitorTcBroken.Value;                return false;            }        }        [Subscription(AITHeaterPropertyName.IsControlTcBroken)]        public bool IsControlTcBroken        {            get            {                if (_diControlTcBroken != null)                    return _diControlTcBroken.Value;                return false;            }        }         [Subscription(AITHeaterPropertyName.IsPowerOnFeedback)]        public bool IsPowerOnFeedback        {            get            {                if (_diPowerOnFeedback != null)                    return _diPowerOnFeedback.Value;                if (_doPowerOn != null)                    return _doPowerOn.Value;                return false;            }        }        [Subscription(AITHeaterPropertyName.IsPowerOnSetPoint)]        public bool IsPowerOnSetPoint        {            get            {                if (_doPowerOn != null)                    return _doPowerOn.Value;                return false;            }        }        public string Unit        {            get; set;        }        /*               doPowerOn="DO_Chamber_heater_power_contactor__coil"               diPowerOnFeedback="DI_Chamber_heater_power_fb"               diControlTcBroken="DI_chamber_wall_control_tc_broken"               diMonitorTcBroken="DI_chamber_wall_monitor_tc_broken"               aoSetPoint="AO_chamber_wall_temp_setpotint"               aiFeedback="AI_Chamber_wall_control_tc_fb"               aoSetPointLimit="AO_chamber_wall_temp_limit_setpotint"               aiMonitor="AI_chamber_wall_monitor_tc_fb"/>         *          */        private DIAccessor _diPowerOnFeedback = null;        private DIAccessor _diControlTcBroken;        private DIAccessor _diMonitorTcBroken;        private DOAccessor _doPowerOn = null;        private AIAccessor _aiControlTcFeedback = null;        private AIAccessor _aiMonitorTcFeedback = null;        private AOAccessor _aoSetPoint = null;        private AOAccessor _aoSetPointLimit = null;        private R_TRIG _trigMonitorTcBroken = new R_TRIG();        private R_TRIG _trigControlTcBroken = new R_TRIG();         public IoHeater(string module, XmlElement node, string ioModule = "")        {            base.Module = module;            base.Name = node.GetAttribute("id");            base.Display = node.GetAttribute("display");            base.DeviceID = node.GetAttribute("schematicId");                        Unit = node.GetAttribute("unit");            _diPowerOnFeedback = ParseDiNode("diPowerOnFeedback", node, ioModule);            _diControlTcBroken = ParseDiNode("diControlTcBroken", node, ioModule);            _diMonitorTcBroken = ParseDiNode("diMonitorTcBroken", node, ioModule);            _doPowerOn = ParseDoNode("doPowerOn", node, ioModule);            _aiControlTcFeedback = ParseAiNode("aiFeedback", node, ioModule);            _aiMonitorTcFeedback = ParseAiNode("aiMonitor", node, ioModule);            _aoSetPoint = ParseAoNode("aoSetPoint", node, ioModule);            _aoSetPointLimit = ParseAoNode("aoSetPointLimit", node, ioModule);         }        public void UpdateConfig(double setPointLimit)        {            if (_aoSetPointLimit != null)                _aoSetPointLimit.Value = (short)setPointLimit;        }        public bool Initialize()        {                                DATA.Subscribe(string.Format("{0}.{1}.DeviceData", Module ,  Name), () =>                    {                        AITHeaterData data = new AITHeaterData()                        {                            Module = Module,                            DeviceName =  Name,                            DeviceSchematicId =  DeviceID,                            DisplayName =  Display,                                                        FeedBack =  ControlTcFeedback,                            MonitorTcFeedBack = MonitorTcFeedback,                             Scale =  SetPointLimit,                            SetPoint =  ControlTcSetPoint,                                                        IsPowerOn = IsPowerOnFeedback,                            IsPowerOnSetPoint = IsPowerOnSetPoint,                            IsControlTcBroken = IsControlTcBroken,                            IsMonitorTcBroken = IsMonitorTcBroken,                                                        Unit = Unit,                        };                        return data;                    }, SubscriptionAttribute.FLAG.IgnoreSaveDB);            OP.Subscribe($"{Module}.{Name}.{AITHeaterOperation.SetPowerOnOff}", (  string functionName,  object[] param) =>            {                bool isEnable = Convert.ToBoolean((string)param[0]);                if (!_doPowerOn.SetValue(isEnable, out string reason))                {                    EV.PostWarningLog(Module, reason);                    return false;                }                     EV.PostInfoLog(Module, string.Format("Set Heater {0} Power {1}", Name, isEnable ? "On" : "Off"));                 return true;            });            OP.Subscribe($"{Module}.{Name}.{AITHeaterOperation.Ramp}", (string functionName, object[] param) =>            {                float setpoint = (float)Convert.ToDouble((string)param[0]);                if (!RampTemp(setpoint)) return false;                return true;            });            DEVICE.Register(String.Format("{0}.{1}", Name, AITHeaterOperation.SetPowerOnOff), (out string reason, int time, object[] param) =>                                                                                              {                                                                                                  reason = "";                bool isEnable =  Convert.ToBoolean((string)param[0]);                bool result = true;                if (_doPowerOn != null)                {                    result &= _doPowerOn.SetValue(isEnable, out reason);                }                if (result)                    reason = string.Format("Set Heater {0} Power {1}", Name, isEnable ? "On" : "Off");                return result;            });            DEVICE.Register(String.Format("{0}.{1}", Name, AITHeaterOperation.Ramp), (out string reason, int time, object[] param) =>{                float setpoint = (float) Convert.ToDouble( (string) param[0]);                if (setpoint > SetPointLimit || setpoint < 0)                {                    reason = string.Format("Heater {0} temperature setpoint {1} is not valid, should be (0, {2})", Display, setpoint, SetPointLimit);                }                if (_aoSetPoint != null)                    _aoSetPoint.Value = (short)setpoint;                 reason = string.Format("Heater {0} Set to {1}", Display, setpoint);                return true;            });            return true;        }        public bool RampTemp(float setpoint)        {            if (setpoint > SetPointLimit || setpoint < 0)            {                EV.PostWarningLog(Module,                    $"Heater {Name} temperature setpoint {setpoint} is not valid, should be (0, {SetPointLimit})");                return false;            }            if (_aoSetPoint != null)                _aoSetPoint.Value = (short) setpoint;            EV.PostInfoLog(Module, string.Format("Heater {0} Set to {1}", Display, setpoint));            return true;        }        public void Stop()        {            if (_aoSetPoint != null)            {                _aoSetPoint.Value = 0;            }        }        public void Terminate()        {        }        public void Monitor()        {            _trigControlTcBroken.CLK = IsControlTcBroken;            if (_trigControlTcBroken.Q)            {                EV.PostMessage(Module, EventEnum.DefaultAlarm, string.Format("{0}, found control TC broken", Display));            }            _trigMonitorTcBroken.CLK = IsMonitorTcBroken;            if (_trigMonitorTcBroken.Q)            {                EV.PostMessage(Module, EventEnum.DefaultAlarm, string.Format("{0}, found monitor TC broken", Display));            }        }                public void Reset()        {            _trigControlTcBroken.RST = true;            _trigMonitorTcBroken.RST = true;        }    }}
 |