ExamplePollImpedanceSampleΒΆ

 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
// ExamplePollImpedanceSample connects to the device,
// subscribes to a impedance stream, polls the data for 0.1 s
// and returns the data.
public static void ExamplePollImpedanceSample(string dev = DEFAULT_DEVICE)
{
  ziDotNET daq = connect(dev);
  // This example only works for devices with installed
  // Impedance Analyzer (IA) option.
  if (!hasOption(daq, dev, "IA"))
  {
    daq.disconnect();
    Skip("Not supported by device.");
  }
  resetDeviceToDefault(daq, dev);
  // Enable impedance control
  daq.setInt(String.Format("/{0}/imps/0/enable", dev), 1);
  // Return R and Cp
  daq.setInt(String.Format("/{0}/imps/0/model", dev), 0);
  // Enable user compensation
  daq.setInt(String.Format("/{0}/imps/0/calib/user/enable", dev), 1);
  // Wait until auto ranging has settled
  System.Threading.Thread.Sleep(4000);
  // Subscribe to the impedance data stream
  String path = String.Format("/{0}/imps/0/sample", dev);
  daq.subscribe(path);
  // After the subscribe, poll() can be executed continuously within a loop.
  // Arguments to poll() are:
  // - 'duration': poll duration in seconds
  // - 'timeOutMilliseconds': timeout to wait for any packet from data server
  // - 'flags': combination of poll flags that determine the
  //   behavior upon sample loss (see e.g., Python API for more information)
  // - 'bufferSize': should be provided as 1 and will be removed in a
  //   future version
  Lookup lookup = daq.poll(0.1, 100, 0, 1);
  Dictionary<String, Chunk[]> nodes = lookup.nodes;  // Iterable nodes
  Chunk[] chunks = lookup[path];  // Iterable chunks
  Chunk chunk = lookup[path][0];  // Single chunk
                                  // Vector of samples
  ZIImpedanceSample[] impedanceSamples = lookup[path][0].impedanceSamples;
  // Single sample
  ZIImpedanceSample impedanceSample0 = lookup[path][0].impedanceSamples[0];
  // Extract the R||C representation values
  System.Diagnostics.Trace.WriteLine(
          String.Format("Impedance Resistor value: {0} Ohm.", impedanceSample0.param0));
  System.Diagnostics.Trace.WriteLine(
          String.Format("Impedance Capacitor value: {0} F.", impedanceSample0.param1));
  daq.disconnect();

  AssertNotEqual(0ul, impedanceSample0.timeStamp);
}