IoPressureMeter.cs 3.6 KB

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