ExampleSpectrumΒΆ

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// ExampleSpectrum instantiates the spectrum module,
// reads the data and writes the result in to a file.
public static void ExampleSpectrum(string dev = DEFAULT_DEVICE) // Timeout(20000)
{
  ziDotNET daq = connect(dev);
  SkipForDeviceFamily(daq, dev, "HDAWG");
  resetDeviceToDefault(daq, dev);
  ziModule spectrum = daq.spectrum();
  spectrum.setByte("device", dev);
  spectrum.setInt("bit", 10);
  String path = String.Format("/{0}/demods/0/sample", dev);
  spectrum.subscribe(path);
  spectrum.execute();
  while (!spectrum.finished())
  {
    System.Threading.Thread.Sleep(100);
    double progress = spectrum.progress() * 100;
    System.Diagnostics.Trace.WriteLine(progress, "Progress");
  }
  Lookup lookup = spectrum.read();
  double[] grid = lookup[path][0].spectrumWaves[0].grid;
  double[] x = lookup[path][0].spectrumWaves[0].x;
  double[] y = lookup[path][0].spectrumWaves[0].y;
  String fileName = Environment.CurrentDirectory + "/spectrum.txt";
  System.IO.StreamWriter file = new System.IO.StreamWriter(fileName);
  for (int i = 0; i < grid.Length; ++i)
  {
    file.WriteLine("{0} {1} {2}", grid[i], x[i], y[i]);
  }
  file.Close();

  AssertEqual(1.0, spectrum.progress());
  AssertNotEqual(0, grid.Length);

  spectrum.clear();  // Release module resources. Especially important if modules are created
                     // inside a loop to prevent excessive resource consumption.
  daq.disconnect();
}