private void UpdateDialogFromDevice()
 {
     m_sAnalyzerBottomAmplitude.Text = ConvertToCurrentAmplitudeString(m_objRFEAnalyzer.AmplitudeBottomDBM);
     m_sAnalyzerTopAmplitude.Text    = ConvertToCurrentAmplitudeString(m_objRFEAnalyzer.AmplitudeTopDBM);
     m_sAnalyzerStartFreq.Text       = m_objRFEAnalyzer.StartFrequencyMHZ.ToString("f3");
     m_sAnalyzerEndFreq.Text         = m_objRFEAnalyzer.CalculateEndFrequencyMHZ().ToString("f3");
     m_sAnalyzerCenterFreq.Text      = m_objRFEAnalyzer.CalculateCenterFrequencyMHZ().ToString("f3");
     m_sAnalyzerFreqSpan.Text        = m_objRFEAnalyzer.CalculateFrequencySpanMHZ().ToString("f3");
 }
        /// <summary>
        /// During this time process, user can write on the keyboard if it is active and it is checking keyboard.
        /// If there is any new setting, it will sending it to the device
        /// If bCountActive is active and g_nTotalFiles, number of files .csv created is equal to 0, then the function ends.
        /// </summary>
        /// <param name="nSeconds"></param>
        /// <param name="bCheckKeyboard"></param>
        /// <param name="bCountActive"> This means "/count:" is an argument. False by default </param>
        static void WaitAndProcess(int nSeconds, bool bCheckKeyboard = true, bool bCountActive = false)
        {
            bool bRunForever = false;

            if (nSeconds == -1)
            {
                bRunForever = true;
            }

            DateTime objTimeStart = DateTime.Now;

            do
            {
                string sDummy; //we do not use the string in this loop
                //Process all pending messages received from device
                g_objRFE.ProcessReceivedString(true, out sDummy);

                if (bCountActive && g_nTotalFiles == 0)
                {
                    break;
                }
                //check if user pressed any key
                if (bCheckKeyboard && Console.KeyAvailable)
                {
                    ConsoleKeyInfo cki = new ConsoleKeyInfo();
                    cki = Console.ReadKey(true);
                    bool   bChangeSettings = false;
                    double fStartMHz       = g_objRFE.StartFrequencyMHZ;
                    double fSpanMHZ        = g_objRFE.CalculateFrequencySpanMHZ();
                    switch (cki.Key)
                    {
                    case ConsoleKey.Escape:
                    case ConsoleKey.Q:
                        //finish function and therefore end up closing the application
                        Trace.WriteLine("<Q> - Closing the application...");
                        return;

                    case ConsoleKey.LeftArrow:
                        Trace.WriteLine("<LEFT> - Updating scan to lower frequency...");
                        Trace.WriteLine("Current configuration - Start:" + g_objRFE.StartFrequencyMHZ.ToString("f3") + "MHZ, Stop: " + g_objRFE.StopFrequencyMHZ.ToString("f3") + "MHz, Span:" + fSpanMHZ.ToString("f3"));
                        //Set new start frequency, keeping same span
                        fStartMHz = fStartMHz - fSpanMHZ;
                        //Check start frequency is in valid device range
                        if (fStartMHz < g_objRFE.MinFreqMHZ)
                        {
                            fStartMHz = g_objRFE.MinFreqMHZ;
                        }
                        bChangeSettings = true;
                        break;

                    case ConsoleKey.RightArrow:
                        Trace.WriteLine("<RIGHT> - Updating scan to higher frequency...");
                        Trace.WriteLine("Current configuration - Start:" + g_objRFE.StartFrequencyMHZ.ToString("f3") + "MHZ, Stop: " + g_objRFE.StopFrequencyMHZ.ToString("f3") + "MHz, Span:" + fSpanMHZ.ToString("f3"));
                        //Set new start frequency, keeping same span
                        fStartMHz = fStartMHz + fSpanMHZ;
                        //Check start frequency is in valid device range
                        if ((fStartMHz + fSpanMHZ) > g_objRFE.MaxFreqMHZ)
                        {
                            fStartMHz = g_objRFE.MaxFreqMHZ - fSpanMHZ;
                        }
                        bChangeSettings = true;
                        break;

                    default:
                        Trace.WriteLine("Ignored key.");
                        break;
                    }
                    if (bChangeSettings)
                    {
                        //Send new configuration
                        g_fStartMHZ = fStartMHz; //change flag value to recognize when new configuration is already in place
                        g_fStopMHZ  = fStartMHz + fSpanMHZ;
                        Trace.WriteLine("New configuration - Start:" + g_fStartMHZ.ToString("f3") + "MHZ, Stop: " + g_fStopMHZ.ToString("f3") + "MHz");
                        g_bIgnoreSweeps = true;
                        g_objRFE.UpdateDeviceConfig(fStartMHz, g_fStopMHZ, g_objRFE.AmplitudeTopDBM, g_objRFE.AmplitudeBottomDBM);
                    }
                }
            } while ((bRunForever || ((DateTime.Now - objTimeStart).TotalSeconds < nSeconds)));
            //save file before closing, if any.
            SaveRFEFile();
        }