using System; using System.Xml; using Aitex.Core.Common.DeviceData; using Aitex.Core.RT.DataCenter; using Aitex.Core.RT.Device; using Aitex.Core.RT.IOCore; using Aitex.Core.Util; namespace Virgo_DRT.Devices.IODevices { public class IoPressureMeter : BaseDevice, IDevice { public enum UnitType { Torr, Pascal, Mbar, Pascal972B, mTorr, } public double Value { get { byte[] high = BitConverter.GetBytes(_ai.Buffer[_ai.Index]); byte[] low = BitConverter.GetBytes(_ai.Buffer[_ai.Index + 1]); float pressure = BitConverter.ToSingle(new[] { high[0], high[1], low[0], low[1] }, 0); return pressure; } } public string Unit { get; set; } private readonly AIAccessor _ai = null; //private double rangeMin = Int16.MinValue * 0.1; //private double rangeMax = Int16.MaxValue * 0.9; private readonly double min = short.MinValue * 0.1; private readonly double max = short.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"); _ai = ParseAiNode("aiValue", node, ioModule); //Full Scale 0-10V this.min = short.MaxValue * min / 10.0; this.max = short.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, FormatString = "F0", }; return data; }, SubscriptionAttribute.FLAG.IgnoreSaveDB); return true; } public void Terminate() { } public void Monitor() { } public void Reset() { } } }