ExampleDataAcquisitionΒΆ

 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// ExampleDataAcquisition uses the new data acquisition module to record data
// and writes the result in to a file.
public static void ExampleDataAcquisition(string dev = DEFAULT_DEVICE) // Timeout(20000)
{
  ziDotNET daq = connect(dev);

  SkipForDeviceFamilyAndOption(daq, dev, "MF", "MD");
  SkipForDeviceFamilyAndOption(daq, dev, "HF2", "MD");
  SkipForDeviceFamily(daq, dev, "HDAWG");

  resetDeviceToDefault(daq, dev);
  daq.setInt(String.Format("/{0}/demods/0/oscselect", dev), 0);
  daq.setInt(String.Format("/{0}/demods/1/oscselect", dev), 1);
  daq.setDouble(String.Format("/{0}/oscs/0/freq", dev), 2e6);
  daq.setDouble(String.Format("/{0}/oscs/1/freq", dev), 2.0001e6);
  daq.setInt(String.Format("/{0}/sigouts/0/enables/*", dev), 0);
  daq.setInt(String.Format("/{0}/sigouts/0/enables/0", dev), 1);
  daq.setInt(String.Format("/{0}/sigouts/0/enables/1", dev), 1);
  daq.setInt(String.Format("/{0}/sigouts/0/on", dev), 1);
  daq.setDouble(String.Format("/{0}/sigouts/0/amplitudes/0", dev), 0.2);
  daq.setDouble(String.Format("/{0}/sigouts/0/amplitudes/1", dev), 0.2);
  ziModule trigger = daq.dataAcquisitionModule();
  trigger.setInt("grid/mode", 4);
  double demodRate = daq.getDouble(String.Format("/{0}/demods/0/rate", dev));
  double duration = trigger.getDouble("duration");
  Int64 sampleCount = System.Convert.ToInt64(demodRate * duration);
  trigger.setInt("grid/cols", sampleCount);
  trigger.setByte("device", dev);
  trigger.setInt("type", 1);
  trigger.setDouble("level", 0.1);
  trigger.setDouble("hysteresis", 0.01);
  trigger.setDouble("bandwidth", 0.0);
  String path = String.Format("/{0}/demods/0/sample.r", dev);
  trigger.subscribe(path);
  String triggerPath = String.Format("/{0}/demods/0/sample.R", dev);
  trigger.setByte("triggernode", triggerPath);
  trigger.execute();
  while (!trigger.finished())
  {
    System.Threading.Thread.Sleep(100);
    double progress = trigger.progress() * 100;
    System.Diagnostics.Trace.WriteLine(progress, "Progress");
  }
  Lookup lookup = trigger.read();
  ZIDoubleData[] demodSample = lookup[path][0].doubleData;
  String fileName = Environment.CurrentDirectory + "/dataacquisition.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);
  file.WriteLine("Flags: {0}", header.flags);
  file.WriteLine("Name: {0}", header.name);
  file.WriteLine("Status: {0}", header.status);
  file.WriteLine("Group Index: {0}", header.groupIndex);
  file.WriteLine("Color: {0}", header.color);
  file.WriteLine("Active Row: {0}", header.activeRow);
  file.WriteLine("Trigger Number: {0}", header.triggerNumber);
  file.WriteLine("Grid Rows: {0}", header.gridRows);
  file.WriteLine("Grid Cols: {0}", header.gridCols);
  file.WriteLine("Grid Mode: {0}", header.gridMode);
  file.WriteLine("Grid Operation: {0}", header.gridOperation);
  file.WriteLine("Grid Direction: {0}", header.gridDirection);
  file.WriteLine("Grid Repetitions: {0}", header.gridRepetitions);
  file.WriteLine("Grid Col Delta: {0}", header.gridColDelta);
  file.WriteLine("Grid Col Offset: {0}", header.gridColOffset);
  file.WriteLine("Bandwidth: {0}", header.bandwidth);
  file.WriteLine("Center: {0}", header.center);
  file.WriteLine("NENBW: {0}", header.nenbw);
  for (int i = 0; i < demodSample.Length; ++i)
  {
    file.WriteLine("{0}", demodSample[i].value);
  }
  file.Close();

  AssertEqual(1, trigger.progress());
  AssertNotEqual(0, demodSample.Length);

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