/// <summary>
        /// Configures common settings for power meter.
        /// </summary>
        /// <param name="sensor">Specifies a reference to the instrument.</param>
        /// <param name="commonConfiguration">Specifies the settings for power meter.</param>
        public static void ConfigureCommon(ni568x sensor, CommonConfiguration commonConfiguration)
        {
            sensor.ConfigureAcquisitionMode(commonConfiguration.Channel_Name, commonConfiguration.Measurement_Mode);
            sensor.ConfigureUnits(commonConfiguration.Units);
            sensor.ConfigureTriggerSource(commonConfiguration.Trigger_Source);

            if (commonConfiguration.Trigger_Source == ni568xConstants.Internal)
            {
                sensor.ConfigureInternalTrigger(commonConfiguration.Channel_Name, commonConfiguration.Slope);
                sensor.ConfigureInternalTriggerLevel(commonConfiguration.Trigger_Level);
            }

            sensor.ConfigureRangeAutoEnabled(commonConfiguration.Channel_Name, true);
            sensor.ConfigureCorrectionFrequency(commonConfiguration.Channel_Name, commonConfiguration.Frequency);
            if (commonConfiguration.AveragingAutoEnabled)
            {
                sensor.ConfigureAveragingAutoEnabled(commonConfiguration.Channel_Name, commonConfiguration.AveragingAutoEnabled);
            }
            else
            {
                sensor.ConfigureAveragingCount(commonConfiguration.Channel_Name, commonConfiguration.Count);
            }

            sensor.SetDouble(ni568xProperties.ApertureTime, commonConfiguration.ApertureTime);
        }
        /// <summary>
        /// Initiates a measurement, waits until the measurement is complete and NI-568x returns to the Idle state, and then returns the measurement result in the result parameter.
        /// </summary>
        /// <param name="sensor">Specifies a reference to the instrument.</param>
        /// <param name="timeout">Specifies the maximum length of time, in milliseconds, to allow the read measurement operation to complete.</param>
        /// <returns>The measurement results, in dBm.</returns>
        public static double ReadMeasurement(ni568x sensor, int timeout)
        {
            double result = 0.0;

            sensor.Read(timeout, out result);
            return(result);
        }
        public void Run()
        {
            NIRfsg nIRfsg = new NIRfsg(resourceName, false, false);

            ConfigureInstrument(nIRfsg, instrConfig);
            Waveform waveform = LoadWaveformFromTDMS(filePath);

            DownloadWaveform(nIRfsg, waveform);
            ConfigureContinuousGeneration(nIRfsg, waveform, "PXI_Trig0");

            ni568x sensor = new ni568x(powerMeterResourceName, true, true);

            PowerMeter.ConfigureCommon(sensor, commonConfiguration);

            bool   measuredPowerInRange;
            double measuredPower         = 0.0;
            double maximumDutOutputPower = paOutputPower_dBm + designedAccuracy_dB;
            double minimumDutOutputPower = paOutputPower_dBm - designedAccuracy_dB;

            Console.WriteLine("\n------------------------Servo Started ---------------------\n");

            for (int currentServoStep = 1; currentServoStep <= maximumSteps; currentServoStep++)
            {
                nIRfsg.Initiate();

                measuredPower = PowerMeter.ReadMeasurement(sensor, 10000) + Coupling_dB;
                Console.WriteLine("Servo step:                               {0}", currentServoStep);
                Console.WriteLine("Measured power (dBm):                     {0:0.00}", measuredPower);

                AbortGeneration(nIRfsg);

                measuredPowerInRange = (measuredPower >= minimumDutOutputPower) && (measuredPower <= maximumDutOutputPower);
                if (measuredPowerInRange && (currentServoStep >= minimumSteps))
                {
                    servoFailed = false;
                    break;
                }
                else
                {
                    instrConfig.DutAverageInputPower_dBm += ((paOutputPower_dBm - measuredPower) * 0.95);
                    ConfigureInstrument(nIRfsg, instrConfig);
                }
            }
            PrintServoResults(measuredPower);

            CloseInstrument(nIRfsg);
            sensor.Dispose();
        }