AbstractAcquirer_Cymometer.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using Uestc.Auto6.Dso.ComModel;
  5. namespace Uestc.Auto6.Dso.Hardware.Driver
  6. {
  7. #region CymometerGateTime
  8. /// <summary>
  9. /// 闸门时间可选列表
  10. /// </summary>
  11. public enum CymometerGateTime
  12. {
  13. Time_4us = 0,
  14. Time_4ms = 1,
  15. Time_1s = 2,
  16. Time_10s = 3,
  17. };
  18. #endregion
  19. /// <summary>
  20. /// 频率计
  21. /// </summary>
  22. public class AbstractAcquirer_Cymometer : AbstractAcquirer
  23. {
  24. internal CymometerGateTime _GateTime = CymometerGateTime.Time_1s;
  25. private const UInt32 MIN_FREQ_200HZ = 200;
  26. private const UInt32 MIN_PERIOD_200MS = 200000000;
  27. private const UInt32 FREQ_4NS_CLK = 4;
  28. internal override void Init()
  29. {
  30. Hd.currProduct?.AcqBd?.WriteToAllFpga(AcqBdReg.W.Cymometer_GateTimeReset, (UInt32)_GateTime);
  31. Hd.currProduct?.AcqBd?.WriteToAllFpga(AcqBdReg.W.Cymometer_CymometerReset, 1);
  32. Hd.currProduct?.AcqBd?.WriteToAllFpga(AcqBdReg.W.Cymometer_CymometerReset, 0);
  33. }
  34. internal override bool ReadAcqData()
  35. {
  36. return true;
  37. }
  38. internal void DoConfig()
  39. {
  40. Hd.currProduct?.AcqBd?.WriteToAllFpga(AcqBdReg.W.Cymometer_GateTimeReset, (UInt32)_GateTime);
  41. Hd.currProduct?.AcqBd?.WriteToAllFpga(AcqBdReg.W.Cymometer_CymometerReset, 1);
  42. Hd.currProduct?.AcqBd?.WriteToAllFpga(AcqBdReg.W.Cymometer_CymometerReset, 0);
  43. }
  44. internal double readbackData = 0;
  45. private bool ReadData(int whichChannel = 0)
  46. {
  47. //int channel = (int)(Hd.CurrHdMessage?.Cymometer.Source ?? ChannelId.C1);
  48. var channelAcqBdAdcInputCorresponding = Hd.currProduct!.Acquirer_AnalogChannel!.GetChannelAcqBdAdcInputCorresponding(whichChannel);
  49. AcqBdNo acqBdNo = (channelAcqBdAdcInputCorresponding == null) ? AcqBdNo.B1 : channelAcqBdAdcInputCorresponding.BdNo;
  50. UInt32 status = 0;
  51. status = (uint)(Hd.currProduct!.AcqBd!.ReadReg(AcqBdReg.R.Cymometer_MeansureDoneFlag, acqBdNo));
  52. UInt32 count_l = 0, count_h = 0;
  53. UInt32 count = 0;
  54. UInt32 stdcount_l = 0, stdcount_h = 0;
  55. UInt32 stdcount = 0, count_period = 0;
  56. UInt32 count_period_l = 0, count_period_h = 0;
  57. if ((status & 0x0003) != 0)
  58. {
  59. count_l = (uint)(Hd.currProduct!.AcqBd!.ReadReg(AcqBdReg.R.Cymometer_FrequenceCountL, acqBdNo));
  60. count_h = (uint)(Hd.currProduct!.AcqBd!.ReadReg(AcqBdReg.R.Cymometer_FrequenceCountH, acqBdNo));
  61. count = (0x0000FFFF & count_l) | ((0x0000FFFF & count_h) << 16);
  62. count *= 1;
  63. stdcount_l = (uint)(Hd.currProduct!.AcqBd!.ReadReg(AcqBdReg.R.Cymometer_StandardFrequenceCountL, acqBdNo));
  64. stdcount_h = (uint)(Hd.currProduct!.AcqBd!.ReadReg(AcqBdReg.R.Cymometer_StandardFrequenceCountH, acqBdNo));
  65. stdcount = (0x0000FFFF & stdcount_l) | ((0x0000FFFF & stdcount_h) << 16);
  66. count_period_l = (uint)(Hd.currProduct!.AcqBd!.ReadReg(AcqBdReg.R.Cymometer_PeriodCountL, acqBdNo));
  67. count_period_h = (uint)(Hd.currProduct!.AcqBd!.ReadReg(AcqBdReg.R.Cymometer_PeriodCountH, acqBdNo));
  68. count_period = (0x0000FFFF & count_period_l) | ((count_period_h & 0x0FFFF) << 16);
  69. }
  70. else
  71. return false;
  72. if (count < 6249/*MIN_FREQ_200HZ / 8*/)
  73. {
  74. if ((status & 0x0002) != 0)
  75. {
  76. if ((count_period < MIN_PERIOD_200MS / FREQ_4NS_CLK * 25) && (count_period > 0))
  77. {
  78. readbackData = 250.0 * 25 / count_period * Math.Pow(10, 6);
  79. }
  80. else
  81. {
  82. readbackData = 0.0;
  83. }
  84. }
  85. else
  86. return false;
  87. }
  88. else
  89. {
  90. if ((status & 0x0001) != 0)
  91. {
  92. readbackData = count / ((stdcount) * 4.0) * Math.Pow(10, 9);
  93. }
  94. else
  95. {
  96. readbackData = readbackData;
  97. return false;
  98. }
  99. }
  100. return true;
  101. }
  102. /// <summary>
  103. /// 读取以Hz为单位的频率数。
  104. /// </summary>
  105. /// <param name="whichChannel">如果存在多个频率计,则读取指定通道的频率计。-1表示触发通道</param>
  106. /// <returns>如果读取失败,返回Double.NaN。以Hz为单位</returns>
  107. public double GetFrequencyByHz(int whichChannel = 0)
  108. {
  109. if (ReadData(whichChannel))
  110. {
  111. DoConfig();
  112. return readbackData;
  113. }
  114. else
  115. return readbackData;
  116. }
  117. public Int32 GateTime
  118. {
  119. get { return (Int32)_GateTime; }
  120. set
  121. {
  122. _GateTime = (CymometerGateTime)value;
  123. DoConfig();
  124. }
  125. }
  126. internal static void Config() => Hd.currProduct?.Acquirer_Cymometer?.DoConfig();
  127. }
  128. }