IoPressureMeter.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. using System;
  2. using System.Xml;
  3. using Aitex.Core.Common.DeviceData;
  4. using Aitex.Core.RT.DataCenter;
  5. using Aitex.Core.RT.IOCore;
  6. using Aitex.Core.Util;
  7. namespace Aitex.Core.RT.Device.Unit
  8. {
  9. public class IoPressureMeter : BaseDevice, IDevice
  10. {
  11. public enum UnitType
  12. {
  13. Torr,
  14. Pascal,
  15. Mbar,
  16. Pascal972B,
  17. mTorr,
  18. }
  19. public double Value
  20. {
  21. get
  22. {
  23. if (unitType == UnitType.Torr)
  24. return GetTorr();
  25. else if (unitType == UnitType.mTorr)
  26. return ai.Value;
  27. else if (unitType == UnitType.Pascal)
  28. return GetPascal();
  29. else if (unitType == UnitType.Pascal972B)
  30. return GetPascal972B();
  31. else
  32. return GetMbar();
  33. }
  34. }
  35. public string Unit { get; set; }
  36. private AIAccessor ai = null;
  37. //private SCConfigItem _scMinFlow;
  38. //private SCConfigItem _scMaxFlow;
  39. private RD_TRIG _trigValveOpenClose = new RD_TRIG();
  40. private UnitType unitType = UnitType.Pascal;
  41. //
  42. private double rangeMin = Int16.MinValue * 0.1;
  43. private double rangeMax = Int16.MaxValue * 0.9;
  44. private double min = Int16.MinValue * 0.1;
  45. private double max = Int16.MaxValue * 0.9;
  46. public IoPressureMeter(string module, XmlElement node, string ioModule = "")
  47. {
  48. base.Module = module;
  49. Name = node.GetAttribute("id");
  50. Display = node.GetAttribute("display");
  51. DeviceID = node.GetAttribute("schematicId");
  52. Unit = node.GetAttribute("unit");
  53. if (Enum.TryParse(this.Unit, true, out UnitType ut))
  54. {
  55. unitType = ut;
  56. }
  57. ai = ParseAiNode("aiValue", node, ioModule);
  58. //string[] range = node.GetAttribute("range").Split(',');
  59. //double.TryParse(range[0], out rangeMin);
  60. //double.TryParse(range[1], out rangeMax);
  61. //Full Scale 0-10V
  62. this.min = Int16.MaxValue * min / 10.0;
  63. this.max = Int16.MaxValue * max / 10.0;
  64. }
  65. public bool Initialize()
  66. {
  67. DATA.Subscribe($"{Module}.{Name}.Value", () => Value);
  68. DATA.Subscribe($"{Module}.{Name}", () =>
  69. {
  70. AITPressureMeterData data = new AITPressureMeterData()
  71. {
  72. DeviceName = Name,
  73. DeviceSchematicId = DeviceID,
  74. DisplayName = Display,
  75. FeedBack = Value,
  76. Unit = Unit,
  77. };
  78. return data;
  79. }, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  80. return true;
  81. }
  82. public void Terminate()
  83. {
  84. }
  85. public void Monitor()
  86. {
  87. }
  88. public void Reset()
  89. {
  90. }
  91. public static double Voltage(double pressure)
  92. {
  93. double logic = 4.0 + Math.Log10(pressure);
  94. double min = Int16.MaxValue * 1 / 10.0;
  95. double max = Int16.MaxValue * 9 / 10.0;
  96. return Converter.Logic2Phy(logic, 1, 9, min, max);
  97. }
  98. public static double Voltage2(double pressure)
  99. {
  100. return Converter.Logic2Phy(pressure, 0, 1333 * 100, 0x0000, 0x5B6D);
  101. }
  102. private double GetPascal()
  103. {
  104. double voltage = Converter.Phy2Logic(ai.Value, rangeMin, rangeMax, min, max);
  105. return Math.Pow(10.0, voltage - 4.0); //pascal
  106. }
  107. private double GetPascal972B()
  108. {
  109. double voltage = Converter.Phy2Logic(ai.Value, rangeMin, rangeMax, min, max);
  110. return Math.Pow(10.0, 2 * voltage - 9); //pascal
  111. }
  112. private double GetMbar()
  113. {
  114. double voltage = Converter.Phy2Logic(ai.Value, rangeMin, rangeMax, min, max);
  115. return Math.Pow(10.0, voltage - 6.0); //mbar
  116. }
  117. private double GetTorr()
  118. {
  119. double voltage = Converter.Phy2Logic(ai.Value, rangeMin, rangeMax, min, max);
  120. return Math.Pow(10.0, voltage - 6.125); //torr
  121. }
  122. private double GetAIScale()
  123. {
  124. return Converter.Phy2Logic(ai.Value, 0, 1333, 0x0000, 0x7fff);
  125. }
  126. }
  127. }