IoPressureMeter.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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.Util;
  8. namespace Virgo_DRT.Devices.IODevices
  9. {
  10. public class IoPressureMeter : BaseDevice, IDevice
  11. {
  12. public enum UnitType
  13. {
  14. Torr,
  15. Pascal,
  16. Mbar,
  17. Pascal972B,
  18. mTorr,
  19. }
  20. public double Value
  21. {
  22. get
  23. {
  24. byte[] high = BitConverter.GetBytes(_ai.Buffer[_ai.Index]);
  25. byte[] low = BitConverter.GetBytes(_ai.Buffer[_ai.Index + 1]);
  26. float pressure = BitConverter.ToSingle(new[] { high[0], high[1], low[0], low[1] }, 0);
  27. return pressure;
  28. }
  29. }
  30. public string Unit { get; set; }
  31. private readonly AIAccessor _ai = null;
  32. //private double rangeMin = Int16.MinValue * 0.1;
  33. //private double rangeMax = Int16.MaxValue * 0.9;
  34. private readonly double min = short.MinValue * 0.1;
  35. private readonly double max = short.MaxValue * 0.9;
  36. public IoPressureMeter(string module, XmlElement node, string ioModule = "")
  37. {
  38. base.Module = module;
  39. Name = node.GetAttribute("id");
  40. Display = node.GetAttribute("display");
  41. DeviceID = node.GetAttribute("schematicId");
  42. Unit = node.GetAttribute("unit");
  43. _ai = ParseAiNode("aiValue", node, ioModule);
  44. //Full Scale 0-10V
  45. this.min = short.MaxValue * min / 10.0;
  46. this.max = short.MaxValue * max / 10.0;
  47. }
  48. public bool Initialize()
  49. {
  50. DATA.Subscribe($"{Module}.{Name}.Value", () => Value);
  51. DATA.Subscribe($"{Module}.{Name}", () =>
  52. {
  53. AITPressureMeterData data = new AITPressureMeterData()
  54. {
  55. DeviceName = Name,
  56. DeviceSchematicId = DeviceID,
  57. DisplayName = Display,
  58. FeedBack = Value,
  59. Unit = Unit,
  60. FormatString = "F0",
  61. };
  62. return data;
  63. }, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  64. return true;
  65. }
  66. public void Terminate()
  67. {
  68. }
  69. public void Monitor()
  70. {
  71. }
  72. public void Reset()
  73. {
  74. }
  75. }
  76. }