ExampleScopeModuleΒΆ

 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
// ExampleScopeModule instantiates a scope module.
public static void ExampleScopeModule(string dev = DEFAULT_DEVICE) // Timeout(20000)
{
  ziDotNET daq = connect(dev);
  if (isDeviceFamily(daq, dev, "HDAWG"))
  {
    daq.disconnect();
    Skip("Not supported by device.");
  }
  resetDeviceToDefault(daq, dev);
  ziModule scopeModule = daq.scopeModule();
  String path = String.Format("/{0}/scopes/0/wave", dev);
  scopeModule.subscribe(path);
  scopeModule.execute();
  // The HF2 devices do not have a single event functionality.
  if (!isDeviceFamily(daq, dev, "HF2"))
  {
    daq.setInt(String.Format("/{0}/scopes/0/single", dev), 1);
    daq.setInt(String.Format("/{0}/scopes/0/trigenable", dev), 0);
  }
  daq.setInt(String.Format("/{0}/scopes/0/enable", dev), 1);

  Lookup lookup;
  bool allSegments = false;
  do
  {
    System.Threading.Thread.Sleep(100);
    double progress = scopeModule.progress() * 100;
    System.Diagnostics.Trace.WriteLine(progress, "Progress");
    lookup = scopeModule.read();
    if (lookup.nodes.ContainsKey(path))
    {
      ZIScopeWave[] scopeWaves = lookup[path][0].scopeWaves;
      UInt64 totalSegments = scopeWaves[0].header.totalSegments;
      UInt64 segmentNumber = scopeWaves[0].header.segmentNumber;
      allSegments = (totalSegments == 0) ||
                    (segmentNumber >= totalSegments - 1);
    }
  } while (!allSegments);
  ZIScopeWave[] scopeWaves1 = lookup[path][0].scopeWaves;
  float[,] wave = SimpleValue.getFloatVec2D(scopeWaves1[0].wave);
  // ...
  System.Diagnostics.Trace.WriteLine(wave.Length, "Wave Size");
  AssertNotEqual(0, wave.Length);

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