ExampleSpectrum#

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