// ExampleSweeper instantiates a sweeper module and executes a sweep
// over 100 data points from 1kHz to 100kHz and writes the result into a file.
public static void ExampleSweeper(string dev = DEFAULT_DEVICE) // Timeout(40000)
{
ziDotNET daq = connect(dev);
SkipForDeviceFamily(daq, dev, "HDAWG");
resetDeviceToDefault(daq, dev);
ziModule sweep = daq.sweeper();
sweep.setByte("device", dev);
sweep.setDouble("start", 1e3);
sweep.setDouble("stop", 1e5);
sweep.setDouble("samplecount", 100);
String path = String.Format("/{0}/demods/0/sample", dev);
sweep.subscribe(path);
sweep.execute();
while (!sweep.finished())
{
System.Threading.Thread.Sleep(100);
double progress = sweep.progress() * 100;
System.Diagnostics.Trace.WriteLine(progress, "Progress");
}
Lookup lookup = sweep.read();
double[] grid = lookup[path][0].sweeperDemodWaves[0].grid;
double[] x = lookup[path][0].sweeperDemodWaves[0].x;
double[] y = lookup[path][0].sweeperDemodWaves[0].y;
String fileName = Environment.CurrentDirectory + "/sweep.txt";
System.IO.StreamWriter file = new System.IO.StreamWriter(fileName);
ZIChunkHeader header = lookup[path][0].header;
// Raw system time is the number of microseconds since linux epoch
file.WriteLine("Raw System Time: {0}", header.systemTime);
// Use the utility function ziSystemTimeToDateTime to convert to DateTime of .NET
file.WriteLine("Converted System Time: {0}", ziUtility.ziSystemTimeToDateTime(lookup[path][0].header.systemTime));
file.WriteLine("Created Timestamp: {0}", header.createdTimeStamp);
file.WriteLine("Changed Timestamp: {0}", header.changedTimeStamp);
for (int i = 0; i < grid.Length; ++i)
{
file.WriteLine("{0} {1} {2}", grid[i], x[i], y[i]);
}
file.Close();
AssertEqual(1.0, sweep.progress());
AssertNotEqual(0, grid.Length);
sweep.clear(); // Release module resources. Especially important if modules are created
// inside a loop to prevent excessive resource consumption.
daq.disconnect();
}