IoPressureMeter.cs 3.8 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 VirgoRT.Devices.IODevices
  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. return pressureProcessGauge + ProcessPressureOffset > 10000 ? 10000 : pressureProcessGauge + ProcessPressureOffset;
  46. }
  47. byte[] high = BitConverter.GetBytes(_ai.Buffer[_ai.Index]);
  48. byte[] low = BitConverter.GetBytes(_ai.Buffer[_ai.Index + 1]);
  49. float pressure = BitConverter.ToSingle(new[] { high[0], high[1], low[0], low[1] }, 0);
  50. return pressure;
  51. }
  52. }
  53. public string Unit { get; set; }
  54. private readonly AIAccessor _ai = null;
  55. private readonly DIAccessor _diGaugeFail = null;
  56. private SCConfigItem _scProcessPressureOffset;
  57. //private double rangeMin = Int16.MinValue * 0.1;
  58. //private double rangeMax = Int16.MaxValue * 0.9;
  59. private readonly double min = short.MinValue * 0.1;
  60. private readonly double max = short.MaxValue * 0.9;
  61. public IoPressureMeter(string module, XmlElement node, string ioModule = "")
  62. {
  63. base.Module = module;
  64. Name = node.GetAttribute("id");
  65. Display = node.GetAttribute("display");
  66. DeviceID = node.GetAttribute("schematicId");
  67. Unit = node.GetAttribute("unit");
  68. _ai = ParseAiNode("aiValue", node, ioModule);
  69. _diGaugeFail = ParseDiNode("diGaugeFail", node, ioModule);
  70. _scProcessPressureOffset = SC.GetConfigItem($"{Module}.ProcessPressureOffset");
  71. //Full Scale 0-10V
  72. this.min = short.MaxValue * min / 10.0;
  73. this.max = short.MaxValue * max / 10.0;
  74. }
  75. public bool Initialize()
  76. {
  77. DATA.Subscribe($"{Module}.{Name}.Value", () => Value);
  78. DATA.Subscribe($"{Module}.{Name}", () =>
  79. {
  80. AITPressureMeterData data = new AITPressureMeterData()
  81. {
  82. DeviceName = Name,
  83. DeviceSchematicId = DeviceID,
  84. DisplayName = Display,
  85. FeedBack = Value,
  86. Unit = Unit,
  87. GaugeAlarm = GaugeAlarm,
  88. FormatString = "F1",
  89. };
  90. return data;
  91. }, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  92. return true;
  93. }
  94. public void Terminate()
  95. {
  96. }
  97. public void Monitor()
  98. {
  99. }
  100. public void Reset()
  101. {
  102. }
  103. }
  104. }