ExamplePollImpedanceSample#

 1// ExamplePollImpedanceSample connects to the device,
 2// subscribes to a impedance stream, polls the data for 0.1 s
 3// and returns the data.
 4public static void ExamplePollImpedanceSample(string dev = DEFAULT_DEVICE)
 5{
 6  ziDotNET daq = connect(dev);
 7  // This example only works for devices with installed
 8  // Impedance Analyzer (IA) option.
 9  if (!hasOption(daq, dev, "IA"))
10  {
11    daq.disconnect();
12    Skip("Not supported by device.");
13  }
14  resetDeviceToDefault(daq, dev);
15  // Enable impedance control
16  daq.setInt(String.Format("/{0}/imps/0/enable", dev), 1);
17  // Return R and Cp
18  daq.setInt(String.Format("/{0}/imps/0/model", dev), 0);
19  // Enable user compensation
20  daq.setInt(String.Format("/{0}/imps/0/calib/user/enable", dev), 1);
21  // Wait until auto ranging has settled
22  System.Threading.Thread.Sleep(4000);
23  // Subscribe to the impedance data stream
24  String path = String.Format("/{0}/imps/0/sample", dev);
25  daq.subscribe(path);
26  // After the subscribe, poll() can be executed continuously within a loop.
27  // Arguments to poll() are:
28  // - 'duration': poll duration in seconds
29  // - 'timeOutMilliseconds': timeout to wait for any packet from data server
30  // - 'flags': combination of poll flags that determine the
31  //   behavior upon sample loss (see e.g., Python API for more information)
32  // - 'bufferSize': should be provided as 1 and will be removed in a
33  //   future version
34  Lookup lookup = daq.poll(0.1, 100, 0, 1);
35  Dictionary<String, Chunk[]> nodes = lookup.nodes;  // Iterable nodes
36  Chunk[] chunks = lookup[path];  // Iterable chunks
37  Chunk chunk = lookup[path][0];  // Single chunk
38                                  // Vector of samples
39  ZIImpedanceSample[] impedanceSamples = lookup[path][0].impedanceSamples;
40  // Single sample
41  ZIImpedanceSample impedanceSample0 = lookup[path][0].impedanceSamples[0];
42  // Extract the R||C representation values
43  System.Diagnostics.Trace.WriteLine(
44          String.Format("Impedance Resistor value: {0} Ohm.", impedanceSample0.param0));
45  System.Diagnostics.Trace.WriteLine(
46          String.Format("Impedance Capacitor value: {0} F.", impedanceSample0.param1));
47  daq.disconnect();
48
49  AssertNotEqual(0ul, impedanceSample0.timeStamp);
50}