ExampleSweeper#

 1// ExampleSweeper instantiates a sweeper module and executes a sweep
 2// over 100 data points from 1kHz to 100kHz and writes the result into a file.
 3public static void ExampleSweeper(string dev = DEFAULT_DEVICE) // Timeout(40000)
 4{
 5  ziDotNET daq = connect(dev);
 6  SkipForDeviceFamily(daq, dev, "HDAWG");
 7
 8  resetDeviceToDefault(daq, dev);
 9  ziModule sweep = daq.sweeper();
10  sweep.setByte("device", dev);
11  sweep.setDouble("start", 1e3);
12  sweep.setDouble("stop", 1e5);
13  sweep.setDouble("samplecount", 100);
14  String path = String.Format("/{0}/demods/0/sample", dev);
15  sweep.subscribe(path);
16  sweep.execute();
17  while (!sweep.finished())
18  {
19    System.Threading.Thread.Sleep(100);
20    double progress = sweep.progress() * 100;
21    System.Diagnostics.Trace.WriteLine(progress, "Progress");
22  }
23  Lookup lookup = sweep.read();
24  double[] grid = lookup[path][0].sweeperDemodWaves[0].grid;
25  double[] x = lookup[path][0].sweeperDemodWaves[0].x;
26  double[] y = lookup[path][0].sweeperDemodWaves[0].y;
27  String fileName = Environment.CurrentDirectory + "/sweep.txt";
28  System.IO.StreamWriter file = new System.IO.StreamWriter(fileName);
29  ZIChunkHeader header = lookup[path][0].header;
30  // Raw system time is the number of microseconds since linux epoch
31  file.WriteLine("Raw System Time: {0}", header.systemTime);
32  // Use the utility function ziSystemTimeToDateTime to convert to DateTime of .NET
33  file.WriteLine("Converted System Time: {0}", ziUtility.ziSystemTimeToDateTime(lookup[path][0].header.systemTime));
34  file.WriteLine("Created Timestamp: {0}", header.createdTimeStamp);
35  file.WriteLine("Changed Timestamp: {0}", header.changedTimeStamp);
36  for (int i = 0; i < grid.Length; ++i)
37  {
38    file.WriteLine("{0} {1} {2}", grid[i], x[i], y[i]);
39  }
40  file.Close();
41
42  AssertEqual(1.0, sweep.progress());
43  AssertNotEqual(0, grid.Length);
44
45  sweep.clear();  // Release module resources. Especially important if modules are created
46                  // inside a loop to prevent excessive resource consumption.
47  daq.disconnect();
48}