IoPressureMeter2.cs 6.3 KB

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