private void WindowLoaded()
        {
            ApplicationVM appvm = App.Current.MainWindow.DataContext as ApplicationVM;
            _spectrumMeter = appvm.TabSpectrum.Spectrum;

            if (_spectrumMeter != null)
            {
                this.Spectrum = new SettingsSpectrumModel(_spectrumMeter);
                _log.Debug(_logTarget + "Loaded");

                if (Spectrum != null)
                    Spectrum.FillInSettings();
                _spectrumSettings.AllowSend = true; //settings have been set, allow writing new settings
            }
            else
            {
                _log.Info(_logTarget + "No SpectrumAnalyzer found for settingmenu");
                //and close window
                throw new System.NotImplementedException("No SpectrumAnalyzer found for settingmenu");
            }
        }
 /// <summary>
 /// Sets or queries the start frequency.
 /// </summary>
 /// <param name="s"></param>
 /// <returns>Specifies the stop frequency. For the setting range, refer to Table 2--52 on page 2--428</returns>
 public static string GetFreqStop(SpectrumMeterModel s)
 {
     string res = String.Empty;
     try { res = s.WriteCommandRes(FREQ_STOP + "?"); }
     catch (Exception e) { Log.Error(_logTarget + "Get FREQ_STOP: " + e.ToString(), e); }
     return res;
 }
        /// <summary>
        /// 
        /// </summary>
        private void CreateMeter()
        {
            System.Threading.ThreadPool.QueueUserWorkItem(
                o =>
                {
                    DispatcherHelper.CheckBeginInvokeOnUI(() => { _log.Info(_logTarget + "Creating new SpectrumAnalyzer"); });
                    Spectrum = new SpectrumMeterModel();
                    Spectrum.Ip = SetIP();
                    Spectrum.TimeOut = 60000;

                    if (Spectrum.VisaAddress == null)
                    {
                        DispatcherHelper.CheckBeginInvokeOnUI(() => { _log.Info(_logTarget + "IP for SpectrumAnalyze not set!"); });
                        Messenger.Default.Send(new NotificationMessage(Messages.Messages.SETTINGSIP_LAUNCH));
                    }
                    else
                    {
                        try
                        {
                            Spectrum.StartConnection();
                            DispatcherHelper.CheckBeginInvokeOnUI(() => { _log.Info(_logTarget + "Connection successful"); });
                            GetSettings();
                        }
                        catch (Exception e)
                        {
                            DispatcherHelper.CheckBeginInvokeOnUI(() => { _log.Error(_logTarget + "Connection failed: {0}" + e.Message, e); });
                        }
                    }
                }
            );
        }
 /// <summary>
 /// Determines whether to use the continuous mode to acquire the input signal
 /// OFF or 0 specifies that the single mode, rather than the continuous mode, is used for data acquisition. To initiate the acquisition, use the :INITiate[:IMMediate]
 /// To stop the acquisition because the trigger is not generated in single mode, send the following command: :INITiate:CONTinuous OFF
 /// ON or 1 initiates data acquisition in the continuous mode.
 /// To stop the acquisition in the continuous mode, send the following command::INITiate:CONTinuous OFF
 /// NOTE: When the analyzer receives a :FETCh command while operating in the continuous mode, it returns an execution error. 
 /// If you want to run a :FETCh, use the :INITiate[:IMMediate] command.
 /// </summary>
 /// <param name="s"></param>
 public static void SetInitContOn(SpectrumMeterModel s)
 {
     s.WriteCommand(REPEAT_CONTINUOUS);
 }
 /// <summary>
 /// Sets or queries the start frequency.
 /// </summary>
 /// <param name="s"></param>
 /// <param name="par">specifies the stop frequency. For the setting range, refer to Table 2--52 on page 2--428</param>
 public static void SetFreqStop(SpectrumMeterModel s, string par)
 {
     s.WriteCommand(FREQ_STOP + " " + par + "hz");
 }
 /// <summary>
 /// Selects the channel table. The query command returns the selected channel table.
 /// </summary>
 /// <param name="s"></param>
 /// <param name="par">specifies a channel table. 
 /// The table name is represented with the communication standard name followed by “-FL” (forward link), “-RL” (reverse link), “-UL” (uplink), or “-DL” (downlink).</param>
 public static void SetFreqChanCat(SpectrumMeterModel s, string par)
 {
     s.WriteCommand(FREQ_CHAN_TAB_SEL + " " + par);
 }
 /// <summary>
 /// Sets or queries the step size (amount per click by which the up and down keys change a setting value) of the center frequency when [:SENSe]:FREQuency:CENTer:STEP:AUTO is OFF.
 /// Note: doesn't affect frontpanel
 /// </summary>
 /// <param name="s"></param>
 /// <param name="par">the step size of the center frequency</param>
 public static void SetFreqCenterStepAutoIncr(SpectrumMeterModel s, string par)
 {
     s.WriteCommand(STEP_AUTO_INCR + " " + par);
 }
 /// <summary>
 /// Selects or queries the FFT window function. This command is valid when [:SENSe]:SPECtrum:BANDwidth|:BWIDth:STATe is OFF.
 /// </summary>
 /// <param name="s"></param>
 /// <param name="par">{ BH3A | BH3B | BH4A | BH4B | BLACkman | HAMMing | HANNing | PARZen | ROSenfield | WELCh | SLOBe | SCUBed | ST4T | FLATtop | RECT }</param>
 public static void SetFFTWindowType(SpectrumMeterModel s, string par)
 {
     s.WriteCommand(FFT_WINDOW_TYPE + " " + par);
 }
 /// <summary>
 /// Adjusts amplitude automatically for the best system performance using the input signal as a guide.
 /// </summary>
 /// <param name="s"></param>
 public static void SetAmplAutoLvl(SpectrumMeterModel s)
 {
     s.WriteCommand(AMP_REF_LEVEL);
 }
 /// <summary>
 /// Determines whether to automatically set the input attenuation according to the reference level
 /// ON or 1 specifies that the input attenuation is set automatically.
 /// </summary>
 /// <param name="s"></param>
 public static void SetAmplAutoAttOn(SpectrumMeterModel s)
 {
     s.WriteCommand(AMP_ATT_AUTO_ON);
 }
 /// <summary>
 /// Obtains the results of the carrier frequency measurement in the S/A mode.
 /// </summary>
 /// <param name="s"></param>
 /// <returns><cfreq>::=<NRf> is the measured value of the carrier frequency in Hz.</returns>
 public static string ReadSpectrumCHP(SpectrumMeterModel s)
 {
     string res = String.Empty;
     try { res = s.WriteCommandRes(READ_SPECTRUM_CHP); }
     catch (Exception e) { Log.Error(_logTarget + "Get READ_SPECTRUM_CHP: " + e.ToString(), e); }
     return res;
 }
 /// <summary>
 /// Determines whether to perform the resolution bandwidth (RBW) process
 /// </summary>
 /// <param name="s"></param>
 /// <returns>OFF or 0 specifies that the RBW process is not performed so that a spectrum immediately after the FFT process is displayed on screen.
 /// ON or 1 specifies that the RBW process is performed.</returns>
 public static string GetRBWState(SpectrumMeterModel s)
 {
     string res = String.Empty;
     try { res = s.WriteCommandRes(RBW_STATE); }
     catch (Exception e) { Log.Error(_logTarget + "Get RBW_STATE: " + e.ToString(), e); }
     return res;
 }
 /// <summary>
 /// Selects and runs the measurement item in the S/A (spectrum analysis) mode. The query version of this command returns the current measurement item.
 /// </summary>
 /// <param name="s"></param>
 /// <returns></returns>
 public static string GetMeas(SpectrumMeterModel s)
 {
     string res = String.Empty;
     try { res = s.WriteCommandRes(MEAS + "?"); }
     catch (Exception e) { Log.Error(_logTarget + "Get MEAS: " + e.ToString(), e); }
     return res;
 }
 /// <summary>
 /// Selects or queries the measurement mode
 /// NOTE. If you want to change the measurement mode, stop the data acquisition with the :INITiate:CONTinuous OFF command.
 /// </summary>
 /// <param name="s"></param>
 /// <returns></returns>
 public static string GetInstrumentSelect(SpectrumMeterModel s)
 {
     string res = String.Empty;
     try { res = s.WriteCommandRes(INSTRUMENT_SELECT + "?"); }
     catch (Exception e) { Log.Error(_logTarget + "Get INSTRUMENT_SELECT: " + e.ToString(), e); }
     return res;
 }
 /// <summary>
 /// Determines whether to use the continuous mode to acquire the input signal
 /// OFF or 0 specifies that the single mode, rather than the continuous mode, is used for data acquisition. To initiate the acquisition, use the :INITiate[:IMMediate]
 /// To stop the acquisition because the trigger is not generated in single mode, send the following command: :INITiate:CONTinuous OFF
 /// ON or 1 initiates data acquisition in the continuous mode.
 /// To stop the acquisition in the continuous mode, send the following command::INITiate:CONTinuous OFF
 /// NOTE. When the analyzer receives a :FETCh command while operating in the continuous mode, it returns an execution error. If you want to run a :FETCh, use the :INITiate[:IMMediate] command.
 /// </summary>
 /// <param name="s"></param>
 /// <returns>OFF or 0 = single mode, ON or 1 = continuous mode</returns>
 public static string GetInitCont(SpectrumMeterModel s)
 {
     string res = String.Empty;
     try { res = s.WriteCommandRes(INIT_CONT + "?"); }
     catch (Exception e) { Log.Error(_logTarget + "Get INIT_CONT: " + e.ToString(), e); }
     return res;
 }
 /// <summary>
 /// Determines whether to enable the extended resolution that eliminates the limit on the number of FFT points (it is normally limited internally).
 /// ON or 1 allows you to set the number of FFT points up to 65536. Use the [:SENSe]:SPECtrum:FFT:LENGth command to set the number.
 /// </summary>
 /// <param name="s"></param>
 public static void SetExtendedOn(SpectrumMeterModel s)
 {
     s.WriteCommand(FFT_EXTENDED_ON);
 }
 /// <summary>
 /// Sets or queries the number of FFT points. This command is valid when [:SENSe]:SPECtrum:BANDwidth|:BWIDth:STATe is OFF.
 /// </summary>
 /// <param name="s"></param>
 /// <param name="par">sets the number of FFT points. Range: 64 to 65536 in powers of 2.</param>
 public static void SetFFTPoints(SpectrumMeterModel s, string par)
 {
     s.WriteCommand(FFT_POINTS + " " + par);
 }
 /// <summary>
 /// When you have selected OFF or 0 in the :INPut:ATTenuation:AUTO command, use this command to set the input attenuation. The query version of this command returns the input attenuation setting.
 /// </summary>
 /// <param name="s"></param>
 /// <param name="par">specifies the input attenuation. The valid settings depend on the measurement frequency band as shown in Table 2--41.</param>
 public static void SetAmplRefAtt(SpectrumMeterModel s, string par)
 {
     s.WriteCommand(AMP_RF_ATT_DB + " " + par);
 }
 /// <summary>
 /// Sets or queries the center frequency. 
 /// </summary>
 /// <param name="s"></param>
 /// <param name="par"><freq>::=<NRf> specifies the center frequency. For the setting range</param>
 public static void SetFreqCenter(SpectrumMeterModel s, string par)
 {
     try { s.WriteCommand(FREQ_CENTER + " " + par + "hz"); }
     catch (Exception e) { Log.Error(_logTarget + "Set FREQ_CENTER: " + e.ToString(), e); }
 }
 /// <summary>
 /// Sets or queries the reference level. Using this command to set the reference level is equivalent to pressing the AMPLITUDE key and then the Ref Level side key on the front panel.
 /// </summary>
 /// <param name="s"></param>
 /// <param name="par">specifies the reference level. The valid settings depend on the measurement frequency band as shown in Table 2--43</param>
 public static void SetAmplRefLvl(SpectrumMeterModel s, string par)
 {
     s.WriteCommand(AMP_REF_LEVEL + " " + par);
 }
 /// <summary>
 /// Determines whether to automatically set the step size (amount per click by which the up and down keys change a setting value) of the center frequency by the span setting.
 /// OFF or 0 specifies that the step size of the center frequency is not set automatically. 
 /// To set it, use the [:SENSe]:FREQuency:CENTer:STEP[:INCRement] command. 
 /// ON or 1 specifies that the step size of the center frequency is set automatically by the span.
 /// </summary>
 /// <param name="s"></param>
 public static void SetFreqCenterStepAutoOn(SpectrumMeterModel s)
 {
     s.WriteCommand(FREQ_STEP_AUTO_ON);
 }
 /// <summary>
 /// Selects or queries the mixer level.
 /// To set the mixer level, you must have selected On in the :INPut:ATTenuation:AUTO command.
 /// </summary>
 /// <param name="s"></param>
 /// <param name="par">specifies the mixer level. The valid settings depend on the measurement frequency band as shown in Table 2--42.</param>
 public static void SetAmpMixerLvl(SpectrumMeterModel s, string par)
 {
     s.WriteCommand(AMP_MIX_LVL + " " + par);
 }
 /// <summary>
 /// Sets or queries the span.
 /// </summary>
 /// <param name="s"></param>
 /// <param name="par">specifies the span. The valid range depends on the measurement mode as listed in Table 2--53</param>
 public static void SetFreqSpan(SpectrumMeterModel s, string par)
 {
     s.WriteCommand(SPAN + " " + par + "hz");
 }
 /// <summary>
 /// Sets or queries the vertical, or amplitude, scale (per division) in the spectrum view.
 /// </summary>
 /// <param name="s"></param>
 /// <param name="par">specifies the horizontal scale in the spectrum view. Range: 0 to 10 dB/div.</param>
 public static void SetAmpVertScale(SpectrumMeterModel s, string par)
 {
     s.WriteCommand(AMP_VERT_SCALE + " " + par);
 }
 /// <summary>
 /// Determines whether to use the continuous mode to acquire the input signal
 /// OFF or 0 specifies that the single mode, rather than the continuous mode, is used for data acquisition. To initiate the acquisition, use the :INITiate[:IMMediate]
 /// To stop the acquisition because the trigger is not generated in single mode, send the following command: :INITiate:CONTinuous OFF
 /// ON or 1 initiates data acquisition in the continuous mode.
 /// To stop the acquisition in the continuous mode, send the following command::INITiate:CONTinuous OFF
 /// </summary>
 /// <param name="s"></param>
 public static void SetInitContOff(SpectrumMeterModel s)
 {
     s.WriteCommand(REPEAT_SINGLE);
 }
 /// <summary>
 /// Sets or queries the channel bandwidth for the channel power measurement (seeFigure 2--18).
 /// </summary>
 /// <param name="s"></param>
 /// <param name="par">specifies the channel bandwidth for the channel power measurement. Range: (Bin bandwidth)×8 to full span [Hz]</param>
 public static void SetChannelBand(SpectrumMeterModel s, string par)
 {
     s.WriteCommand(CHP_BANDWIDTH + " " + par + "hz");
 }
 /// <summary>
 /// 
 /// </summary>
 private void CloseMeter()
 {
     if (Spectrum != null)
     {
         Spectrum.CloseConnestion();
         Spectrum = null;
     }
 }
 /// <summary>
 /// Selects or queries the filter for the channel power measurement
 /// </summary>
 /// <param name="s"></param>
 /// <param name="par">RECTangle selects the rectangular filter. 
 /// GAUSsian selects the Gaussian filter.
 /// NYQuist selects the Nyquist filter (default).
 /// RNYQuist selects the Root Nyquist filter.</param>
 public static void SetCHPFilterType(SpectrumMeterModel s, string par)
 {
     s.WriteCommand(CHP_FILTER_TYPE + " " + par);
 }
 /// <summary>
 /// Selects or queries the filter for the channel power measurement
 /// Sets or queries the roll-off rate of the filter for the channel power measurement when you have selected either NYQuist (Nyquist filter) or RNYQuist (Root Nyquist filter) in the [:SENSe]:CHPower:FILTer:TYPE command
 /// </summary>
 /// <param name="s"></param>
 /// <param name="par">Range: 0.0001 to 1</param>
 public static void SetCHPRollOff(SpectrumMeterModel s, string par)
 {
     s.WriteCommand(CHP_ROLLOFF + " " + par);
 }
 /// <summary>
 /// Selects the channel table. The query command returns the selected channel table.
 /// </summary>
 /// <param name="s"></param>
 /// <returns>specifies a channel table. 
 /// The table name is represented with the communication standard name followed by “-FL” (forward link), “-RL” (reverse link), “-UL” (uplink), or “-DL” (downlink).</returns>
 public static string GetFreqChanCatSelected(SpectrumMeterModel s)
 {
     string res = String.Empty;
     try { res = s.WriteCommandRes(FREQ_CHAN_TAB_SEL + "?"); }
     catch (Exception e) { Log.Error(_logTarget + "Get FREQ_CHAN_TAB_SEL: " + e.ToString(), e); }
     return res;
 }