ExamplePollPwaDataΒΆ

 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
// ExamplePollPwaData is similar to ExamplePollDemodSample,
// but it subscribes and polls periodic waveform analyzer
// data from a device with the Boxcar option.
public static void ExamplePollPwaData(string dev = DEFAULT_DEVICE) // Timeout(10000)
{
  ziDotNET daq = connect(dev);
  // The PWA example only works for devices with installed Boxcar (BOX) option
  if (hasOption(daq, dev, "BOX"))
  {
    String enablePath = String.Format("/{0}/inputpwas/0/enable", dev);
    daq.setInt(enablePath, 1);
    String path = String.Format("/{0}/inputpwas/0/wave", dev);
    daq.subscribe(path);
    Lookup lookup = daq.poll(1, 100, 0, 1);
    UInt64 timeStamp = lookup[path][0].pwaWaves[0].timeStamp;
    UInt64 sampleCount = lookup[path][0].pwaWaves[0].sampleCount;
    UInt32 inputSelect = lookup[path][0].pwaWaves[0].inputSelect;
    UInt32 oscSelect = lookup[path][0].pwaWaves[0].oscSelect;
    UInt32 harmonic = lookup[path][0].pwaWaves[0].harmonic;
    Double frequency = lookup[path][0].pwaWaves[0].frequency;
    Byte type = lookup[path][0].pwaWaves[0].type;
    Byte mode = lookup[path][0].pwaWaves[0].mode;
    Byte overflow = lookup[path][0].pwaWaves[0].overflow;
    Byte commensurable = lookup[path][0].pwaWaves[0].commensurable;
    double[] grid = lookup[path][0].pwaWaves[0].binPhase;
    double[] x = lookup[path][0].pwaWaves[0].x;
    double[] y = lookup[path][0].pwaWaves[0].y;
    String fileName = Environment.CurrentDirectory + "/pwa.txt";
    System.IO.StreamWriter file = new System.IO.StreamWriter(fileName);
    file.WriteLine("TimeStamp: {0}", timeStamp);
    file.WriteLine("Sample Count: {0}", sampleCount);
    file.WriteLine("Input Select: {0}", inputSelect);
    file.WriteLine("Osc Select: {0}", oscSelect);
    file.WriteLine("Frequency: {0}", frequency);
    for (int i = 0; i < grid.Length; ++i)
    {
      file.WriteLine("{0} {1} {2}", grid[i], x[i], y[i]);
    }
    file.Close();

    AssertNotEqual(0ul, timeStamp);
    AssertNotEqual(0ul, sampleCount);
    AssertNotEqual(0, grid.Length);
  }
  daq.disconnect();
}