ExampleImpedanceCompensationΒΆ

 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
51
52
53
54
// ExampleImpedanceCompensation does a user compensation
// of the impedance analyser.
public static void ExampleImpedanceCompensation(string dev = DEFAULT_DEVICE) // Timeout(30000)
{
  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);
  ziModule calib = daq.impedanceModule();
  calib.execute();
  calib.setByte("device", dev);
  System.Threading.Thread.Sleep(200);
  calib.setInt("mode", 4);
  calib.setDouble("loads/2/r", 1000.0);
  calib.setDouble("loads/2/c", 0.0);
  calib.setDouble("freq/start", 100.0);
  calib.setDouble("freq/stop", 500e3);
  calib.setDouble("freq/samplecount", 21);

  daq.setInt(String.Format("/{0}/imps/0/demod/order", dev), 8);
  daq.setInt(String.Format("/{0}/imps/0/demod/oscselect", dev), 0);
  daq.sync();


  calib.setInt("step", 2);
  calib.setInt("calibrate", 1);
  while (true)
  {
    System.Threading.Thread.Sleep(100);
    double progress = calib.progress() * 100;
    System.Diagnostics.Trace.WriteLine(progress, "Progress");
    Int64 calibrate = calib.getInt("calibrate");
    if (calibrate == 0)
    {
      break;
    }
  }
  String message = calib.getString("message");
  System.Diagnostics.Trace.WriteLine(message, "Message");
  AssertNotEqual(0, calib.progress());

  calib.clear();  // Release module resources. Especially important if modules are created
                  // inside a loop to prevent excessive resource consumption.
  daq.disconnect();
}