public void TestLoop()
        {
            //public bool SaGetPeakFreq(out double peak_freq, out float peak_pwr, double begin_freq, double end_freq, double rbw)
            Double PeakFreq = new Double();
            float  peak_pwr = new float();

            SaDev.CloseDevice();
            SaDev.OpenDevice();
            AddLog("Opened sa device.\r\n");

            while (true)
            {
                Thread.Sleep(10);
                if (test_status.MeasureRange == TestStatus.MeaRange_t.mr_full)
                {
                    test_status.FoundPeak = false;

                    if (test_status.ReferenceSource == TestStatus.ReferenceSource_t.External)
                    {
                        if (SaDev.ExternalReferenceSource())
                        {
                            AddLog("Switch to external reference done.\r\n");
                        }
                        else
                        {
                            AddLog("External reference error.\r\n");
                            test_status.ReferenceSource = TestStatus.ReferenceSource_t.Internal;
                            ButtonReferenceSourceText(test_status.GetText(test_status.ReferenceSource));
                        }
                    }

                    StatusText("1/3");
                    AddLog("Full range scan, may take about 10 secends.\r\n");

                    SaDev.SaGetPeakFreq(out PeakFreq, out peak_pwr, test_status);
                    if (peak_pwr < -40)
                    {
                        AddLog("Not found a signal over -40dbm.\r\n");
                    }
                    else
                    {
                        FrequencyDataFormatter DataFormat = new FrequencyDataFormatter((ulong)PeakFreq, peak_pwr);
                        FreqText(DataFormat.FreqStr);
                        PwrText(DataFormat.PwrStr);
                        test_status.MeasureRange    = TestStatus.MeaRange_t.mr_1m;
                        test_status.CenterFrequency = PeakFreq;
                        test_status.FoundPeak       = true;
                        AddLog("Found peak in full range.\r\n");
                    }
                    Thread.Sleep(100);
                }

                if (test_status.MeasureRange == TestStatus.MeaRange_t.mr_1m)
                {
                    StatusText("2/3");
                    SaDev.SaGetPeakFreq(out PeakFreq, out peak_pwr, test_status);
                    if (peak_pwr < -40)
                    {
                        test_status.MeasureRange = TestStatus.MeaRange_t.mr_full;
                        //test_status.FoundPeak = false;
                        AddLog("Miss peak in 1MHz range.\r\n");
                    }
                    else
                    {
                        FrequencyDataFormatter DataFormat = new FrequencyDataFormatter((ulong)PeakFreq, peak_pwr);
                        FreqText(DataFormat.FreqStr);
                        PwrText(DataFormat.PwrStr);
                        test_status.MeasureRange    = TestStatus.MeaRange_t.mr_1k;
                        test_status.CenterFrequency = PeakFreq;
                        //test_status.FoundPeak = true;
                        AddLog("Found peak in 1MHz range.\r\n");
                    }
                }

                while (test_status.MeasureRange == TestStatus.MeaRange_t.mr_1k)
                {
                    StatusText("3/3");
                    SaDev.SaGetPeakFreq(out PeakFreq, out peak_pwr, test_status);

                    if (peak_pwr < -40)
                    {
                        test_status.MeasureRange = TestStatus.MeaRange_t.mr_1m;
                        //test_status.FoundPeak = false;
                        AddLog("Miss peak in 1KHz range.\r\n");
                    }
                    else
                    {
                        FrequencyDataFormatter DataFormat = new FrequencyDataFormatter((ulong)PeakFreq, peak_pwr);
                        FreqText(DataFormat.FreqStr);
                        PwrText(DataFormat.PwrStr);
                        test_status.CenterFrequency = PeakFreq;
                        //test_status.FoundPeak = true;
                        AddLog("Found peak in 1KHz range.\r\n");
                    }
                }
            }
        }
        public void TestLoop()
        {
            //public bool SaGetPeakFreq(out double peak_freq, out float peak_pwr, double begin_freq, double end_freq, double rbw)
            Double PeakFreq = new Double();
            float peak_pwr = new float();

            SaDev.CloseDevice();
            SaDev.OpenDevice();
            AddLog("Opened sa device.\r\n");

            while (true)
            {
                Thread.Sleep(10);
                if (test_status.MeasureRange == TestStatus.MeaRange_t.mr_full)
                {
                    test_status.FoundPeak = false;

                    if (test_status.ReferenceSource == TestStatus.ReferenceSource_t.External)
                    {
                        if (SaDev.ExternalReferenceSource())
                        {
                            AddLog("Switch to external reference done.\r\n");
                        }
                        else
                        {
                            AddLog("External reference error.\r\n");
                            test_status.ReferenceSource = TestStatus.ReferenceSource_t.Internal;
                            ButtonReferenceSourceText(test_status.GetText(test_status.ReferenceSource));

                        }
                    }

                    StatusText("1/3");
                    AddLog("Full range scan, may take about 10 secends.\r\n");

                    SaDev.SaGetPeakFreq( out PeakFreq, out peak_pwr, test_status);
                    if (peak_pwr < -40)
                    {
                        AddLog("Not found a signal over -40dbm.\r\n");
                    }
                    else
                    {
                        FrequencyDataFormatter DataFormat = new FrequencyDataFormatter((ulong)PeakFreq, peak_pwr);
                        FreqText(DataFormat.FreqStr);
                        PwrText(DataFormat.PwrStr);
                        test_status.MeasureRange = TestStatus.MeaRange_t.mr_1m;
                        test_status.CenterFrequency = PeakFreq;
                        test_status.FoundPeak = true;
                        AddLog("Found peak in full range.\r\n");
                    }
                    Thread.Sleep(100);
                }

                if (test_status.MeasureRange == TestStatus.MeaRange_t.mr_1m)
                {
                    StatusText("2/3");
                    SaDev.SaGetPeakFreq(out PeakFreq, out peak_pwr, test_status);
                    if (peak_pwr < -40)
                    {
                        test_status.MeasureRange = TestStatus.MeaRange_t.mr_full;
                        //test_status.FoundPeak = false;
                        AddLog("Miss peak in 1MHz range.\r\n");
                    }
                    else
                    {
                        FrequencyDataFormatter DataFormat = new FrequencyDataFormatter((ulong)PeakFreq, peak_pwr);
                        FreqText(DataFormat.FreqStr);
                        PwrText(DataFormat.PwrStr);
                        test_status.MeasureRange = TestStatus.MeaRange_t.mr_1k;
                        test_status.CenterFrequency = PeakFreq;
                        //test_status.FoundPeak = true;
                        AddLog("Found peak in 1MHz range.\r\n");
                    }

                }

                while (test_status.MeasureRange == TestStatus.MeaRange_t.mr_1k)
                {
                    StatusText("3/3");
                    SaDev.SaGetPeakFreq(out PeakFreq, out peak_pwr, test_status);

                    if (peak_pwr < -40)
                    {
                        test_status.MeasureRange = TestStatus.MeaRange_t.mr_1m;
                        //test_status.FoundPeak = false;
                        AddLog("Miss peak in 1KHz range.\r\n");
                    }
                    else
                    {
                        FrequencyDataFormatter DataFormat = new FrequencyDataFormatter((ulong)PeakFreq, peak_pwr);
                        FreqText(DataFormat.FreqStr);
                        PwrText(DataFormat.PwrStr);
                        test_status.CenterFrequency = PeakFreq;
                        //test_status.FoundPeak = true;
                        AddLog("Found peak in 1KHz range.\r\n");
                    }
                }
            }
        }