IoPressureMeter.cs 4.2 KB

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