| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 | using System.Xml;using Aitex.Core.RT.DataCenter;using Aitex.Core.RT.IOCore;namespace Aitex.Core.RT.Device.Unit{    public class IoTrigger : BaseDevice, IDevice    {        private DIAccessor _diFeedback = null;        private DOAccessor _doTrigger = null;        private AOAccessor _aoTrigger = null;        public DOAccessor DoTrigger => _doTrigger;        public IoTrigger(string module, XmlElement node, string ioModule = "")        {            base.Module = module;            base.Name = node.GetAttribute("id");            base.Display = node.GetAttribute("display");            base.DeviceID = node.GetAttribute("schematicId");            _diFeedback = ParseDiNode("diFeedback", node, ioModule);            _doTrigger = ParseDoNode("doTrigger", node, ioModule);            _aoTrigger = ParseAoNode("aoTrigger", node, ioModule);        }        public bool Value        {            get            {                if (_diFeedback != null)                    return _diFeedback.Value;                if (_doTrigger != null)                    return _doTrigger.Value;                if (_aoTrigger != null)                    return _aoTrigger.FloatValue > 0;                return false;            }        }        public float AOValue        {            get            {                if (_aoTrigger != null)                    return _aoTrigger.FloatValue;                return 0f;            }        }        public bool SetPulseTrigger(bool value, out string reason)        {            reason = "";            _doTrigger?.SetPulseValue(value, 1500);            return true;        }        public bool SetTrigger(bool value, out string reason)        {            reason = "";            _doTrigger?.SetValue(value, out reason);            if(_aoTrigger != null)                _aoTrigger.FloatValue = value ? 1 : 0;            return true;        }        public bool SetAOTrigger(float value, out string reason)        {            reason = "";            if (_aoTrigger != null)                _aoTrigger.FloatValue = value;            return true;        }        public bool Initialize()        {            if (_aoTrigger != null)                DATA.Subscribe($"{Module}.{Name}.AOValue", () => AOValue);            return true;        }        public void Terminate()        {        }        public void Monitor()        {         }        public void Reset()        {         }    }}
 |