ExamplePollVectorDataΒΆ

 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
// ExamplePollVectorData connects to the device, requests data from
// vector nodes, and polls until data is received.
public static void ExamplePollVectorData(string dev = DEFAULT_DEVICE)
{
  ziDotNET daq = connect(dev);

  // This example only works for devices with the AWG option
  if (hasOption(daq, dev, "AWG") || isDeviceFamily(daq, dev, "UHFQA") || isDeviceFamily(daq, dev, "UHFAWG") || isDeviceFamily(daq, dev, "HDAWG"))
  {
    resetDeviceToDefault(daq, dev);

    // Request vector node from device
    String path = String.Format("/{0}/awgs/0/waveform/waves/0", dev);
    daq.getAsEvent(path);

    // Poll until the node path is found in the result data
    double timeout = 20;
    double poll_time = 0.1;
    Lookup lookup = null;
    for (double time = 0; ; time += poll_time)
    {
      lookup = daq.poll(poll_time, 100, 0, 1);
      if (lookup.nodes.ContainsKey(path))
        break;
      if (time > timeout)
        Fail("Vector node data not received within timeout");
    }

    Chunk[] chunks = lookup[path]; // Iterable chunks
    Chunk chunk = chunks[0];       // Single chunk
    ZIVectorData vectorData = chunk.vectorData[0];

    // The vector attribute of a ZIVectorData object holds a ZIVector object,
    // which can contain a String or arrays of the following types:
    // byte, UInt16, Uint32, Uint64, float, double

    // Waveform vector data is stored as 32-bit unsigned integer
    if (vectorData.vector != null)  // Check for empty container
    {
      UInt32[] vector = vectorData.vector.data as UInt32[];
    }

    AssertNotEqual(0ul, vectorData.timeStamp);
  }
  daq.disconnect();
}