IoPressureMeter2.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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 IoPressureMeter2 : BaseDevice, IDevice
  10. {
  11. public enum UnitType
  12. {
  13. Torr,
  14. Pascal,
  15. Mbar,
  16. Pascal972B,
  17. }
  18. public double UnitValue
  19. {
  20. get
  21. {
  22. if (unitType == UnitType.Torr)
  23. return GetTorr();
  24. else if (unitType == UnitType.Pascal)
  25. return GetPascal();
  26. else if (unitType == UnitType.Pascal972B)
  27. return GetPascal972B();
  28. else
  29. return GetMbar();
  30. }
  31. }
  32. //Torr unit
  33. public double PressureValue
  34. {
  35. get
  36. {
  37. if (_type == "MKS.901P")
  38. return PressureValue901P;
  39. if (_type == "MKS.974B")
  40. return PressureValue974B;
  41. return RawValue;
  42. }
  43. }
  44. private double PressureValue901P
  45. {
  46. get
  47. {
  48. var voltage = Converter.Phy2Logic(RawValue, 1, 9, 3276.7, 29490.3);
  49. var torValue = Math.Pow(10.0, voltage - 6.0);
  50. return Unit == "mTorr" ? torValue * 1000 : torValue;
  51. }
  52. }
  53. private double PressureValue974B
  54. {
  55. get
  56. {
  57. var voltage = Converter.Phy2Logic(RawValue, 1.5, 7, 4915.05, 22936.9);
  58. var torValue = Math.Pow(10.0, 2 * voltage - 11.0);
  59. return Unit == "mTorr" ? torValue * 1000 : torValue;
  60. }
  61. }
  62. public short RawValue
  63. {
  64. get { return BitConverter.ToInt16(new byte[] { (byte)_aiLow.Value, (byte)_aiHigh.Value }, 0); }
  65. }
  66. private AITPressureMeterData DeviceData
  67. {
  68. get
  69. {
  70. AITPressureMeterData data = new AITPressureMeterData()
  71. {
  72. DeviceName = Name,
  73. DeviceSchematicId = DeviceID,
  74. DisplayName = Display,
  75. FeedBack = PressureValue,
  76. Unit = Unit,
  77. };
  78. return data;
  79. }
  80. }
  81. public string Unit { get; set; }
  82. private AIAccessor _aiLow = null;
  83. private AIAccessor _aiHigh = null;
  84. //private SCConfigItem _scMinFlow;
  85. //private SCConfigItem _scMaxFlow;
  86. private UnitType unitType = UnitType.Pascal;
  87. private string _type = string.Empty;
  88. //
  89. private double rangeMin = Int16.MinValue * 0.1;
  90. private double rangeMax = Int16.MaxValue * 0.9;
  91. private double min = Int16.MinValue * 0.1;
  92. private double max = Int16.MaxValue * 0.9;
  93. public IoPressureMeter2(string module, XmlElement node, string ioModule = "")
  94. {
  95. base.Module = module;
  96. Name = node.GetAttribute("id");
  97. Display = node.GetAttribute("display");
  98. DeviceID = node.GetAttribute("schematicId");
  99. Unit = node.GetAttribute("unit");
  100. _aiLow = ParseAiNode("aiLow", node, ioModule);
  101. _aiHigh = ParseAiNode("aiHigh", node, ioModule);
  102. _type = node.GetAttribute("type");
  103. //Full Scale 0-10V
  104. this.min = Int16.MaxValue * min / 10.0;
  105. this.max = Int16.MaxValue * max / 10.0;
  106. }
  107. public bool Initialize()
  108. {
  109. DATA.Subscribe($"{Module}.{Name}.Value", () => UnitValue);
  110. DATA.Subscribe($"{Module}.{Name}.DeviceData", () => DeviceData);
  111. return true;
  112. }
  113. public void Terminate()
  114. {
  115. }
  116. public void Monitor()
  117. {
  118. }
  119. public void Reset()
  120. {
  121. }
  122. public static double Voltage(double pressure)
  123. {
  124. double logic = 4.0 + Math.Log10(pressure);
  125. double min = Int16.MaxValue * 1 / 10.0;
  126. double max = Int16.MaxValue * 9 / 10.0;
  127. return Converter.Logic2Phy(logic, 1, 9, min, max);
  128. }
  129. public static double Voltage2(double pressure)
  130. {
  131. return Converter.Logic2Phy(pressure, 0, 1333 * 100, 0x0000, 0x5B6D);
  132. }
  133. private double GetPascal()
  134. {
  135. double voltage = Converter.Phy2Logic(RawValue, rangeMin, rangeMax, min, max);
  136. return Math.Pow(10.0, voltage - 4.0); //pascal
  137. }
  138. private double GetPascal972B()
  139. {
  140. double voltage = Converter.Phy2Logic(RawValue, rangeMin, rangeMax, min, max);
  141. return Math.Pow(10.0, 2 * voltage - 9); //pascal
  142. }
  143. private double GetMbar()
  144. {
  145. double voltage = Converter.Phy2Logic(RawValue, rangeMin, rangeMax, min, max);
  146. return Math.Pow(10.0, voltage - 6.0); //mbar
  147. }
  148. private double GetTorr()
  149. {
  150. double voltage = Converter.Phy2Logic(RawValue, rangeMin, rangeMax, min, max);
  151. return Math.Pow(10.0, voltage - 6.125); //torr
  152. }
  153. private double GetAIScale()
  154. {
  155. return Converter.Phy2Logic(RawValue, 0, 1333, 0x0000, 0x7fff);
  156. }
  157. }
  158. }