123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- 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.RT.SCCore;
- using Aitex.Core.Util;
- namespace Aitex.Core.RT.Device.Unit
- {
- public class IoPressureMeter : BaseDevice, IDevice
- {
- public enum UnitType
- {
- Torr,
- Pascal,
- Mbar,
- Pascal972B,
- mTorr,
- }
- [Subscription("GaugeAlarm")]
- public bool GaugeAlarm
- {
- get { return _diGaugeFail != null ? _diGaugeFail.Value : false; }
- }
- [Subscription("ProcessPressureOffset")]
- public double ProcessPressureOffset
- {
- get
- {
- if (_scProcessPressureOffset != null)
- return _scProcessPressureOffset.DoubleValue;
- return 0;
- }
- }
- public double Value
- {
- get
- {
- if (Name == "ProcessGauge")
- {
- //byte[] highProcessGauge = BitConverter.GetBytes(_ai.Buffer[_ai.Index]);
- //byte[] lowProcessGauge = BitConverter.GetBytes(_ai.Buffer[_ai.Index + 1]);
- //float pressureProcessGauge = BitConverter.ToSingle(new[] { highProcessGauge[0], highProcessGauge[1], lowProcessGauge[0], lowProcessGauge[1] }, 0);
- float pressureProcessGauge = _ai.FloatValue;
- return pressureProcessGauge + ProcessPressureOffset > 10000 ? 10000 : pressureProcessGauge + ProcessPressureOffset;
- }
- //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);
- float pressure = _ai.FloatValue;
- return pressure;
- }
- }
- public string Unit { get; set; }
- private readonly AIAccessor _ai = null;
- private readonly DIAccessor _diGaugeFail = null;
- private SCConfigItem _scProcessPressureOffset;
- //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);
- _diGaugeFail = ParseDiNode("diGaugeFail", node, ioModule);
- _scProcessPressureOffset = SC.GetConfigItem($"{Module}.ProcessPressureOffset");
- //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,
- GaugeAlarm = GaugeAlarm,
- FormatString = "F1",
- };
- return data;
- }, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- return true;
- }
- public void Terminate()
- {
- }
- public void Monitor()
- {
- }
- public void Reset()
- {
- }
- }
- }
|