IoPressureMeter.cs 3.2 KB

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