// ExampleAutorangingImpedance shows how to perform a manually triggered autoranging for impedance while working in manual range mode.
public static void ExampleAutorangingImpedance(string dev = DEFAULT_DEVICE) // Timeout(25000)
{
ziDotNET daq = connect(dev);
// check device type, option
SkipRequiresOption(daq, dev, "IA");
resetDeviceToDefault(daq, dev);
// Create instrument configuration: disable all outputs, demods and scopes.
daq.setInt(String.Format("/{0}/demods/*/enable", dev), 0);
daq.setInt(String.Format("/{0}/demods/*/trigger", dev), 0);
daq.setInt(String.Format("/{0}/sigouts/*/enables/*", dev), 0);
daq.setInt(String.Format("/{0}/scopes/*/enable", dev), 0);
daq.setInt(String.Format("/{0}/imps/*/enable", dev), 0);
daq.sync();
int imp = 0;
long curr = daq.getInt(String.Format("/{0}/imps/{1}/current/inputselect", dev, imp));
long volt = daq.getInt(String.Format("/{0}/imps/{1}/voltage/inputselect", dev, imp));
double manCurrRange = 10e-3;
double manVoltRange = 10e-3;
// Now configure the instrument for this experiment. The following channels and indices work on all devices with IA option.
// The values below may be changed if the instrument has multiple IA modules.
daq.setInt(String.Format("/{0}/imps/{1}/enable", dev, imp), 1);
daq.setInt(String.Format("/{0}/imps/{1}/mode", dev, imp), 0);
daq.setInt(String.Format("/{0}/imps/{1}/auto/output", dev, imp), 1);
daq.setInt(String.Format("/{0}/imps/{1}/auto/bw", dev, imp), 1);
daq.setDouble(String.Format("/{0}/imps/{1}/freq", dev, imp), 500);
daq.setInt(String.Format("/{0}/imps/{1}/auto/inputrange", dev, imp), 0);
daq.setDouble(String.Format("/{0}/currins/{1}/range", dev, curr), manCurrRange);
daq.setDouble(String.Format("/{0}/sigins/{1}/range", dev, volt), manVoltRange);
daq.sync();
// After setting the device in manual ranging mode we want to trigger manually a one time auto ranging to find a suitable range.
// Therefore, we trigger the auto ranging for the current input as well as for the voltage input.
daq.setInt(String.Format("/{0}/currins/{1}/autorange", dev, curr), 1);
daq.setInt(String.Format("/{0}/sigins/{1}/autorange", dev, volt), 1);
// The auto ranging takes some time. We do not want to continue before the best range is found.
// Therefore, we implement a loop to check if the auto ranging is finished.
int count = 0;
System.Threading.Thread.Sleep(100);
bool finished = false;
var watch = System.Diagnostics.Stopwatch.StartNew();
while (!finished)
{
++count;
System.Threading.Thread.Sleep(500);
finished = (daq.getInt(String.Format("/{0}/currins/{1}/autorange", dev, curr)) == 0 &&
daq.getInt(String.Format("/{0}/sigins/{1}/autorange", dev, volt)) == 0);
}
watch.Stop();
System.Diagnostics.Trace.WriteLine(
String.Format("Auto ranging finished after {0} s.", watch.ElapsedMilliseconds / 1e3));
double autoCurrRange = daq.getDouble(String.Format("/{0}/currins/{1}/range", dev, curr));
double autoVoltRange = daq.getDouble(String.Format("/{0}/sigins/{1}/range", dev, volt));
System.Diagnostics.Trace.WriteLine(
String.Format("Current range changed from {0} A to {1} A.", manCurrRange, autoCurrRange));
System.Diagnostics.Trace.WriteLine(
String.Format("Voltage range changed from {0} A to {1} A.", manVoltRange, autoVoltRange));
Debug.Assert(count > 1);
}