IoFlowMeter2.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. using Aitex.Core.Common.DeviceData;
  2. using Aitex.Core.RT.DataCenter;
  3. using Aitex.Core.RT.Device;
  4. using Aitex.Core.RT.Event;
  5. using Aitex.Core.RT.IOCore;
  6. using Aitex.Core.RT.SCCore;
  7. using Aitex.Core.RT.Tolerance;
  8. using Aitex.Core.Util;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. using System.Xml;
  15. namespace Aitex.Core.RT.Device.Unit
  16. {
  17. public class IoFlowMeter2 : BaseDevice, IDevice
  18. {
  19. public double Feedback
  20. {
  21. get
  22. {
  23. if (_aiFlowValue != null)
  24. {
  25. //double aiValue = _isFloatAioType ? _aiFlow.FloatValue : _aiFlow.Value;
  26. var phy = _aiFlowValue == null ? 0 : (_isFloatAioType ? _aiFlowValue.FloatValue : _aiFlowValue.Value);
  27. if (phy < _phyScaleMin)
  28. phy = (float)_phyScaleMin;
  29. else if (phy > _phyScaleMax)
  30. phy = (float)_phyScaleMax;
  31. return Converter.Phy2Logic(phy, _scaleMin, _scaleMax, _phyScaleMin, _phyScaleMax);
  32. //return _maxScale != 0 ? aiValue * Scale / _maxScale : aiValue;
  33. }
  34. return 0;
  35. }
  36. }
  37. private AITWaterFlowMeterData DeviceData
  38. {
  39. get
  40. {
  41. AITWaterFlowMeterData data = new AITWaterFlowMeterData()
  42. {
  43. DeviceName = Name,
  44. DeviceSchematicId = DeviceID,
  45. DisplayName = Display,
  46. FeedBack = Feedback,
  47. Unit = Unit,
  48. };
  49. return data;
  50. }
  51. }
  52. public string Unit { get; set; }
  53. private AIAccessor _aiFlowValue = null;
  54. private double _scaleMin;
  55. private double _scaleMax;
  56. private double _phyScaleMin;
  57. private double _phyScaleMax;
  58. private bool _isFloatAioType = false;
  59. public IoFlowMeter2(string module, XmlElement node, string ioModule = "")
  60. {
  61. var attrModule = node.GetAttribute("module");
  62. base.Module = string.IsNullOrEmpty(attrModule) ? module : attrModule;
  63. Name = node.GetAttribute("id");
  64. Display = node.GetAttribute("display");
  65. DeviceID = node.GetAttribute("schematicId");
  66. Unit = node.GetAttribute("unit");
  67. _aiFlowValue = ParseAiNode("aiFeedback", node, ioModule);
  68. var scale = node.GetAttribute("scale").Split(',');
  69. if (scale.Length > 1)
  70. {
  71. double.TryParse(scale[0], out _scaleMin);
  72. double.TryParse(scale[1], out _scaleMax);
  73. }
  74. else
  75. {
  76. _scaleMin = 0;
  77. double.TryParse(scale[0], out _scaleMax);
  78. }
  79. var physcale = node.GetAttribute("physical").Split(',');
  80. if (physcale.Length > 1)
  81. {
  82. double.TryParse(physcale[0], out _phyScaleMin);
  83. double.TryParse(physcale[1], out _phyScaleMax);
  84. }
  85. else
  86. {
  87. _phyScaleMin = 0;
  88. double.TryParse(physcale[0], out _phyScaleMax);
  89. }
  90. _isFloatAioType = !string.IsNullOrEmpty(node.GetAttribute("aioType")) && (node.GetAttribute("aioType") == "float");
  91. }
  92. public bool Initialize()
  93. {
  94. DATA.Subscribe($"{Module}.{Name}.DeviceData", () => DeviceData);
  95. DATA.Subscribe($"{Module}.{Name}.Feedback", () => Feedback);
  96. return true;
  97. }
  98. public void Terminate()
  99. {
  100. }
  101. public void Monitor()
  102. {
  103. }
  104. public void Reset()
  105. {
  106. }
  107. }
  108. }