| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 | using Aitex.Core.Common.DeviceData;using Aitex.Core.RT.DataCenter;using Aitex.Core.RT.Device;using Aitex.Core.RT.Event;using Aitex.Core.RT.IOCore;using Aitex.Core.RT.SCCore;using Aitex.Core.RT.Tolerance;using Aitex.Core.Util;using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Xml;namespace Aitex.Core.RT.Device.Unit{    public class IoFlowMeter2 : BaseDevice, IDevice    {        public double Feedback        {            get            {                if (_aiFlowValue != null)                {                    //double aiValue = _isFloatAioType ? _aiFlow.FloatValue : _aiFlow.Value;                    var phy = _aiFlowValue == null ? 0 : (_isFloatAioType ? _aiFlowValue.FloatValue : _aiFlowValue.Value);                    if (phy < _phyScaleMin)                        phy = (float)_phyScaleMin;                    else if (phy > _phyScaleMax)                        phy = (float)_phyScaleMax;                    return Converter.Phy2Logic(phy, _scaleMin, _scaleMax, _phyScaleMin, _phyScaleMax);                    //return _maxScale != 0 ? aiValue * Scale / _maxScale : aiValue;                }                return 0;            }        }        private AITWaterFlowMeterData DeviceData        {            get            {                AITWaterFlowMeterData data = new AITWaterFlowMeterData()                {                    DeviceName = Name,                    DeviceSchematicId = DeviceID,                    DisplayName = Display,                    FeedBack = Feedback,                    Unit = Unit,                };                return data;            }        }        public string Unit { get; set; }        private AIAccessor _aiFlowValue = null;        private double _scaleMin;        private double _scaleMax;        private double _phyScaleMin;        private double _phyScaleMax;        private bool _isFloatAioType = false;        public IoFlowMeter2(string module, XmlElement node, string ioModule = "")        {            var attrModule = node.GetAttribute("module");            base.Module = string.IsNullOrEmpty(attrModule) ? module : attrModule;            Name = node.GetAttribute("id");            Display = node.GetAttribute("display");            DeviceID = node.GetAttribute("schematicId");            Unit = node.GetAttribute("unit");            _aiFlowValue = ParseAiNode("aiFeedback", node, ioModule);            var scale = node.GetAttribute("scale").Split(',');            if (scale.Length > 1)            {                double.TryParse(scale[0], out _scaleMin);                double.TryParse(scale[1], out _scaleMax);            }            else            {                _scaleMin = 0;                double.TryParse(scale[0], out _scaleMax);            }            var physcale = node.GetAttribute("physical").Split(',');            if (physcale.Length > 1)            {                double.TryParse(physcale[0], out _phyScaleMin);                double.TryParse(physcale[1], out _phyScaleMax);            }            else            {                _phyScaleMin = 0;                double.TryParse(physcale[0], out _phyScaleMax);            }            _isFloatAioType = !string.IsNullOrEmpty(node.GetAttribute("aioType")) && (node.GetAttribute("aioType") == "float");        }        public bool Initialize()        {            DATA.Subscribe($"{Module}.{Name}.DeviceData", () => DeviceData);            DATA.Subscribe($"{Module}.{Name}.Feedback", () => Feedback);            return true;        }        public void Terminate()        {        }        public void Monitor()        {        }        public void Reset()        {        }    }}
 |