| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 | using System;using System.Xml;using Aitex.Core.Common.DeviceData;using Aitex.Core.RT.DataCenter;using Aitex.Core.RT.IOCore;using Aitex.Core.Util;namespace Aitex.Core.RT.Device.Unit{    public class IoPressureMeter : BaseDevice, IDevice    {        public enum UnitType        {            Torr,            Pascal,            Mbar,            Pascal972B,            mTorr,        }        public double Value        {            get            {                if (unitType == UnitType.Torr)                    return GetTorr();                else if (unitType == UnitType.mTorr)                    return ai.Value;                else if (unitType == UnitType.Pascal)                    return GetPascal();                else if (unitType == UnitType.Pascal972B)                    return GetPascal972B();                else                    return GetMbar();            }        }        public string Unit { get; set; }        private AIAccessor ai = null;        //private SCConfigItem _scMinFlow;        //private SCConfigItem _scMaxFlow;        private RD_TRIG _trigValveOpenClose = new RD_TRIG();        private UnitType unitType = UnitType.Pascal;        //        private double rangeMin = Int16.MinValue * 0.1;        private double rangeMax = Int16.MaxValue * 0.9;        private double min = Int16.MinValue * 0.1;        private double max = Int16.MaxValue * 0.9;        public IoPressureMeter(string module, XmlElement node, string ioModule = "")        {            base.Module = module;            Name        = node.GetAttribute("id");            Display     = node.GetAttribute("display");            DeviceID    = node.GetAttribute("schematicId");            Unit = node.GetAttribute("unit");            if (Enum.TryParse(this.Unit, true, out UnitType ut))            {                unitType = ut;            }            ai = ParseAiNode("aiValue", node, ioModule);            //string[] range = node.GetAttribute("range").Split(',');            //double.TryParse(range[0], out rangeMin);            //double.TryParse(range[1], out rangeMax);            //Full Scale 0-10V            this.min = Int16.MaxValue * min / 10.0;            this.max = Int16.MaxValue * max / 10.0;        }        public bool Initialize()        {            DATA.Subscribe($"{Module}.{Name}.Value", () => Value);            DATA.Subscribe($"{Module}.{Name}", () =>            {                AITPressureMeterData data = new AITPressureMeterData()                {                    DeviceName        = Name,                    DeviceSchematicId = DeviceID,                    DisplayName       = Display,                    FeedBack          = Value,                    Unit              = Unit,                };                return data;            }, SubscriptionAttribute.FLAG.IgnoreSaveDB);            return true;        }        public void Terminate()        {        }        public void Monitor()        {        }        public void Reset()        {        }        public static double Voltage(double pressure)        {            double logic = 4.0 + Math.Log10(pressure);            double min = Int16.MaxValue * 1 / 10.0;            double max = Int16.MaxValue * 9 / 10.0;            return Converter.Logic2Phy(logic, 1, 9, min, max);        }        public static double Voltage2(double pressure)        {            return Converter.Logic2Phy(pressure, 0, 1333 * 100, 0x0000, 0x5B6D);        }        private double GetPascal()        {            double voltage = Converter.Phy2Logic(ai.Value, rangeMin, rangeMax, min, max);            return Math.Pow(10.0, voltage - 4.0);      //pascal        }        private double GetPascal972B()        {            double voltage = Converter.Phy2Logic(ai.Value, rangeMin, rangeMax, min, max);            return Math.Pow(10.0, 2 * voltage - 9);      //pascal        }        private double GetMbar()        {            double voltage = Converter.Phy2Logic(ai.Value, rangeMin, rangeMax, min, max);            return Math.Pow(10.0, voltage - 6.0);      //mbar        }        private double GetTorr()        {            double voltage = Converter.Phy2Logic(ai.Value, rangeMin, rangeMax, min, max);            return Math.Pow(10.0, voltage - 6.125);      //torr        }        private double GetAIScale()        {            return Converter.Phy2Logic(ai.Value, 0, 1333, 0x0000, 0x7fff);        }    }}
 |