ExampleSwTriggerΒΆ

 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
// ExampleSwTrigger uses the software trigger to record data
// and writes the result in to a file.
public static void ExampleSwTrigger(string dev = DEFAULT_DEVICE) // Timeout(20000)
{
  ziDotNET daq = connect(dev);
  SkipForDeviceFamily(daq, dev, "HDAWG");
  SkipForDeviceFamilyAndOption(daq, dev, "MF", "MD");
  SkipForDeviceFamilyAndOption(daq, dev, "HF2", "HF2");


  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.swTrigger();
  trigger.setByte("device", dev);
  trigger.setInt("/0/type", 1);
  trigger.setDouble("/0/level", 0.1);
  trigger.setDouble("/0/hysteresis", 0.01);
  trigger.setDouble("/0/bandwidth", 0.0);
  String path = String.Format("/{0}/demods/0/sample", dev);
  trigger.subscribe(path);
  String triggerPath = String.Format("/{0}/demods/0/sample.R", dev);
  trigger.setByte("/0/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();
  ZIDemodSample[] demodSample = lookup[path][0].demodSamples;
  String fileName = Environment.CurrentDirectory + "/swtrigger.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} {1} {2}",
      demodSample[i].frequency,
      demodSample[i].x,
      demodSample[i].y);
  }
  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();
}