IoPressureMeter.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. using System;
  2. using System.Xml;
  3. using Aitex.Core.Common.DeviceData;
  4. using Aitex.Core.RT.DataCenter;
  5. using Aitex.Core.RT.Device;
  6. using Aitex.Core.RT.IOCore;
  7. using Aitex.Core.RT.SCCore;
  8. using Aitex.Core.Util;
  9. namespace Aitex.Core.RT.Device.Unit
  10. {
  11. public class IoPressureMeter : BaseDevice, IDevice
  12. {
  13. public enum UnitType
  14. {
  15. Torr,
  16. Pascal,
  17. Mbar,
  18. Pascal972B,
  19. mTorr,
  20. }
  21. [Subscription("GaugeAlarm")]
  22. public bool GaugeAlarm
  23. {
  24. get { return _diGaugeFail != null ? _diGaugeFail.Value : false; }
  25. }
  26. [Subscription("ProcessPressureOffset")]
  27. public double ProcessPressureOffset
  28. {
  29. get
  30. {
  31. if (_scProcessPressureOffset != null)
  32. return _scProcessPressureOffset.DoubleValue;
  33. return 0;
  34. }
  35. }
  36. public double Value
  37. {
  38. get
  39. {
  40. if (Name == "ProcessGauge")
  41. {
  42. //byte[] highProcessGauge = BitConverter.GetBytes(_ai.Buffer[_ai.Index]);
  43. //byte[] lowProcessGauge = BitConverter.GetBytes(_ai.Buffer[_ai.Index + 1]);
  44. //float pressureProcessGauge = BitConverter.ToSingle(new[] { highProcessGauge[0], highProcessGauge[1], lowProcessGauge[0], lowProcessGauge[1] }, 0);
  45. float pressureProcessGauge = _ai.FloatValue;
  46. return pressureProcessGauge + ProcessPressureOffset > 10000 ? 10000 : pressureProcessGauge + ProcessPressureOffset;
  47. }
  48. //byte[] high = BitConverter.GetBytes(_ai.Buffer[_ai.Index]);
  49. //byte[] low = BitConverter.GetBytes(_ai.Buffer[_ai.Index + 1]);
  50. //float pressure = BitConverter.ToSingle(new[] { high[0], high[1], low[0], low[1] }, 0);
  51. float pressure = _ai.FloatValue;
  52. return pressure;
  53. }
  54. }
  55. public string Unit { get; set; }
  56. private readonly AIAccessor _ai = null;
  57. private readonly DIAccessor _diGaugeFail = null;
  58. private SCConfigItem _scProcessPressureOffset;
  59. //private double rangeMin = Int16.MinValue * 0.1;
  60. //private double rangeMax = Int16.MaxValue * 0.9;
  61. private readonly double min = short.MinValue * 0.1;
  62. private readonly double max = short.MaxValue * 0.9;
  63. public IoPressureMeter(string module, XmlElement node, string ioModule = "")
  64. {
  65. base.Module = module;
  66. Name = node.GetAttribute("id");
  67. Display = node.GetAttribute("display");
  68. DeviceID = node.GetAttribute("schematicId");
  69. Unit = node.GetAttribute("unit");
  70. _ai = ParseAiNode("aiValue", node, ioModule);
  71. _diGaugeFail = ParseDiNode("diGaugeFail", node, ioModule);
  72. _scProcessPressureOffset = SC.GetConfigItem($"{Module}.ProcessPressureOffset");
  73. //Full Scale 0-10V
  74. this.min = short.MaxValue * min / 10.0;
  75. this.max = short.MaxValue * max / 10.0;
  76. }
  77. public bool Initialize()
  78. {
  79. DATA.Subscribe($"{Module}.{Name}.Value", () => Value);
  80. DATA.Subscribe($"{Module}.{Name}", () =>
  81. {
  82. AITPressureMeterData data = new AITPressureMeterData()
  83. {
  84. DeviceName = Name,
  85. DeviceSchematicId = DeviceID,
  86. DisplayName = Display,
  87. FeedBack = Value,
  88. Unit = Unit,
  89. GaugeAlarm = GaugeAlarm,
  90. FormatString = "F1",
  91. };
  92. return data;
  93. }, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  94. return true;
  95. }
  96. public void Terminate()
  97. {
  98. }
  99. public void Monitor()
  100. {
  101. }
  102. public void Reset()
  103. {
  104. }
  105. }
  106. }