// 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);
}