InstrumentInteract_Factory.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Runtime.InteropServices;
  6. using System.Threading;
  7. using System.Threading.Tasks;
  8. using Uestc.Auto6.Dso.ComModel;
  9. using Uestc.Auto6.Dso.Hardware.Calibration.Data.Base;
  10. namespace Uestc.Auto6.Dso.Hardware.Calibration.Tool
  11. {
  12. public partial class InstrumentInteract
  13. {
  14. public static List<ushort[]> Factory_WaveData_Adc(IInstrumentSession instrument)
  15. {
  16. if (instrument == null)
  17. return null;
  18. string scpiCmd = GetCmdStr(ScpiCmd.Factory_WaveData_Adc);
  19. scpiCmd += " ?";
  20. instrument.WriteString(scpiCmd);
  21. Thread.Sleep(100);
  22. byte[] recvedByteData = new byte[ServerDomainConstants.AnalogChannelCount * ServerDomainConstants.PerAnaChannelAdcCount * ServerDomainConstants.PerAdcCoreCount * sizeof(ushort) * ServerDomainConstants.PerAdcCoreDataCount];
  23. int recvedBytes = instrument.ReadBinData(ref recvedByteData);
  24. if (recvedBytes < recvedByteData.Length)
  25. return null;
  26. List<ushort[]> returnData = new List<ushort[]>();
  27. int posIndex = 0;
  28. for (int adcIndex = 0; adcIndex < ServerDomainConstants.PerAnaChannelAdcCount * ServerDomainConstants.AnalogChannelCount; adcIndex++)
  29. {
  30. for (int coreIndex = 0; coreIndex < ServerDomainConstants.PerAdcCoreCount; coreIndex++)
  31. {
  32. ushort[] coreData = new ushort[ServerDomainConstants.PerAdcCoreDataCount];
  33. for (int i = 0; i < ServerDomainConstants.PerAdcCoreDataCount; i++)
  34. {
  35. coreData[i] = BitConverter.ToUInt16(recvedByteData, posIndex);
  36. posIndex += 2;
  37. }
  38. returnData.Add(coreData);
  39. }
  40. }
  41. return returnData;
  42. }
  43. public static List<ushort[]> Factory_WaveData_Channel(IInstrumentSession instrument)
  44. {
  45. if (instrument == null)
  46. return null;
  47. string scpiCmd = GetCmdStr(ScpiCmd.Factory_WaveData_Channel);
  48. scpiCmd += " ?";
  49. instrument.WriteString(scpiCmd);
  50. Thread.Sleep(100);
  51. byte[] recvedByteData = new byte[Constants.CHNL_DATA_NUM * sizeof(ushort) * ChannelIdExt.AnaChnlNum];
  52. int recvedBytes = instrument.ReadBinData(ref recvedByteData);
  53. if (recvedBytes < recvedByteData.Length)
  54. return null;
  55. List<ushort[]> returnData = new List<ushort[]>();
  56. int posIndex = 0;
  57. for (int channelIndex = 0; channelIndex < ChannelIdExt.AnaChnlNum; channelIndex++)
  58. {
  59. ushort[] perChannelData = new ushort[Constants.CHNL_DATA_NUM];
  60. for (int i = 0; i < Constants.CHNL_DATA_NUM; i++)
  61. {
  62. perChannelData[i] = BitConverter.ToUInt16(recvedByteData, posIndex);
  63. posIndex += 2;
  64. }
  65. returnData.Add(perChannelData);
  66. }
  67. return returnData;
  68. }
  69. public static List<AdcRegisterDataFormat>? Factory_Cali_Specail_ReadbackAdcRegisterValue(IInstrumentSession instrument)
  70. {
  71. string scpiCmd = GetCmdStr(ScpiCmd.Factory_Cali_Special_ReadbackAdcRegisterValue);
  72. scpiCmd += " ?";
  73. instrument.WriteString(scpiCmd);
  74. Thread.Sleep(100);
  75. string readback = instrument.ReadString();
  76. if (readback.Trim() != "")
  77. return System.Text.Json.JsonSerializer.Deserialize<List<AdcRegisterDataFormat>>(readback);
  78. else
  79. return null;
  80. }
  81. public static string Factory_ReadbackFPGAVersionInfo(IInstrumentSession instrument)
  82. {
  83. string scpiCmd = GetCmdStr(ScpiCmd.Factory_FPGAVersionInfo);
  84. scpiCmd += " ?";
  85. instrument.WriteString(scpiCmd);
  86. Thread.Sleep(100);
  87. return instrument.ReadString();
  88. }
  89. public static string Factory_ReadbackFPGAWritedRegisterValue(IInstrumentSession instrument)
  90. {
  91. string scpiCmd = GetCmdStr(ScpiCmd.Factory_FPGAAllWriteRegisterValueReadback);
  92. scpiCmd += " ?";
  93. instrument.WriteString(scpiCmd);
  94. Thread.Sleep(100);
  95. string result = instrument.ReadString();
  96. return result;
  97. }
  98. }
  99. }