private void ExecutePauseMeasurCommand()
        {
            try
            {
                if (_TestStatus == FreqTestStatus.testing)
                {
                    BtnPauseText = "继续";
                    _TestStatus  = FreqTestStatus.pause;
                    Sensor.SendStopWbqexCmd();
                }
                else
                {
                    BtnPauseText = "暂停";
                    _TestStatus  = FreqTestStatus.testing;
                    endFreq      = Convert.ToDouble(RoadTestInfor.EndFreq) * 1000 * 1000.0;
                    _proc        = CallBack;
                    AgilentDll.Sensor.SendWbqexCmd(RoadTestInfor.StartFreq * 1000000.0, RoadTestInfor.EndFreq * 1000000.0, RoadTestInfor.Bandwidth * 1000.0, _proc);
                }

                UpdateTextBlockEnable();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
        void ExecuteStartMeasurCommand()
        {
            if (!_CollectionDataSave.IsConnectionOpen)
            {
                _CollectionDataSave.openSQLiteConnection();
            }
            CurrentTestTableName = GetFreqTableName();
            if (DbHelper.CreateFreqTable(CurrentTestTableName))
            {
                RoadTestInfor.FreqDataTable = CurrentTestTableName;
            }
            DbHelper.CreateCdma1xTable(CurrentTestTableName);

            if (Sensor.IsUseSensor)
            {
                //存储任务信息
                RoadTest rt = new RoadTest();
                rt.Bandwidth = Convert.ToInt32(RoadTestInfor.Bandwidth * 1000);
                rt.CarPlate  = RoadTestInfor.CarPlate;
                //rt.EndFreq = RoadTestInfor.EndFreq;
                rt.ReciverIp    = RoadTestInfor.ReciverIp;
                rt.RoadTestName = RoadTestInfor.RoadTestName;
                //rt.StartFreq = RoadTestInfor.StartFreq;
                rt.TestDateTime  = DateTime.Now;
                rt.TestSample    = RoadTestInfor.TestSample;
                rt.TestStaffName = RoadTestInfor.TestStaffName;
                rt.Bz            = "";
                rt.ReciverPort   = 0;
                rt.FreqDataTable = RoadTestInfor.FreqDataTable;

                //if (EntityQuery<RoadTest>.Instance.Insert(rt) > 0)
                {
                    //Clear()
                    _LineChartViewModel.Clear();
                    FreqMeasureId                 = 0;
                    FreqMeasurePakageId           = 0;
                    FreqDataIndex                 = 0;
                    _TestStatus                   = FreqTestStatus.testing;
                    _CollectionDataSave.MeasureID = "Measure" + DateTime.Now.ToString("yyyyMMddHHmmss");
                    IsRecordFreqCount             = true;
                    endFreq = Convert.ToDouble(RoadTestInfor.EndFreq) * 1000 * 1000.0;
                    _proc   = CallBack;
                    AgilentDll.Sensor.SendWbqexCmd(RoadTestInfor.StartFreq * 1000000.0, RoadTestInfor.EndFreq * 1000000.0, RoadTestInfor.Bandwidth * 1000.0, _proc);
                }
                collectTime = DateTime.Now;
                UpdateTextBlockEnable();
                return;
            }
        }
        void ExecuteStartRealTimeMonitorCommand()
        {
            //CurrentTestTableName = GetFreqTableName();
            //if (DbHelper.CreateFreqTable(CurrentTestTableName))
            //{
            //    RoadTestInfor.FreqDataTable = CurrentTestTableName;
            //}
            //DbHelper.CreateCdma1xTable(CurrentTestTableName);

            if (Sensor.IsUseSensor)
            {
                //存储任务信息
                RoadTest rt = new RoadTest();
                rt.Bandwidth = Convert.ToInt32(RoadTestInfor.Bandwidth * 1000);
                rt.CarPlate  = RoadTestInfor.CarPlate;
                //rt.EndFreq = RoadTestInfor.EndFreq;
                rt.ReciverIp    = RoadTestInfor.ReciverIp;
                rt.RoadTestName = RoadTestInfor.RoadTestName;
                //rt.StartFreq = RoadTestInfor.StartFreq;
                rt.TestDateTime  = DateTime.Now;
                rt.TestSample    = RoadTestInfor.TestSample;
                rt.TestStaffName = RoadTestInfor.TestStaffName;
                rt.Bz            = "";
                rt.ReciverPort   = 0;
                rt.FreqDataTable = RoadTestInfor.FreqDataTable;

                //if (EntityQuery<RoadTest>.Instance.Insert(rt) > 0)
                {
                    //Clear()
                    _LineChartViewModel.Clear();
                    FreqMeasureId       = 0;
                    FreqMeasurePakageId = 0;
                    FreqDataIndex       = 0;
                    _TestStatus         = FreqTestStatus.testing;
                    IsRecordFreqCount   = true;
                    endFreq             = Convert.ToDouble(RoadTestInfor.EndFreq) * 1000 * 1000.0;
                    _proc = RealTimeMonitorCallBack;
                    AgilentDll.Sensor.SendWbqexCmd(RoadTestInfor.StartFreq * 1000000.0, RoadTestInfor.EndFreq * 1000000.0, RoadTestInfor.Bandwidth * 1000.0, _proc);
                    _dTimer          = new System.Windows.Threading.DispatcherTimer();
                    _dTimer.Tick    += new EventHandler(dTimer_Tick);
                    _dTimer.Interval = new TimeSpan(0, 0, 0, 0, 1);
                    _dTimer.Start();
                }
                collectTime = DateTime.Now;
                UpdateTextBlockEnable();
                return;
            }
        }
        public FreqDataCollectViewModel()
        {
            #region

            try
            {
                #endregion
                WinCloseCommand = new RelayCommand(() =>
                {
                    //if (_TestStatus != FreqTestStatus.pause && _TestStatus != FreqTestStatus.testing)
                    //    Messenger.Default.Send<GenericMessage<string>>(new GenericMessage<string>(this, "showmainwindow"));
                });

                #region 打开或关闭 接收机
                OpenReciverCommand = new RelayCommand(() =>
                {
                    if (pingEquipment(RoadTestInfor.ReciverIp))
                    {
                        if (!AgilentDll.Sensor.Connect(RoadTestInfor.ReciverIp))
                        {
                            Sensor.IsUseSensor = false;
                            Messenger.Default.Send <GenericMessage <string> >(new GenericMessage <string>(this, "ErrorConnectReciver"));
                            return;
                        }
                        else
                        {
                            Sensor.IsUseSensor = true;
                            ImgConectEable     = System.Windows.Visibility.Visible;
                            ImgDisConectEable  = System.Windows.Visibility.Collapsed;
                            TextColor          = Brushes.Green;
                            TextStatus         = "连接状态:设备准备就绪Sensor";
                        }
                    }
                }, () => { return(!Sensor.IsUseSensor && _TestStatus != FreqTestStatus.testing && _TestStatus != FreqTestStatus.pause); });

                CloseReciverCommand = new RelayCommand(() =>
                {
                    ImgConectEable    = System.Windows.Visibility.Collapsed;
                    ImgDisConectEable = System.Windows.Visibility.Visible;
                    TextColor         = Brushes.Red;
                    TextStatus        = "连接状态:设备未连接";
                    Sensor.Close();
                    Sensor.IsUseSensor = false;
                }, () => { return(Sensor.IsUseSensor && _TestStatus != FreqTestStatus.testing && _TestStatus != FreqTestStatus.pause);; });

                #endregion


                #region 频谱测量命令
                StopMeasurCommand = new RelayCommand(() =>
                {
                    BtnPauseText = "暂停";
                    Sensor.SendStopWbqexCmd();
                    _TestStatus = FreqTestStatus.stop;
                    _CollectionDataSave.closeSQLiteConnection();
                    _CollectionDataSave.Flag = 0;
                    UpdateTextBlockEnable();
                }, () =>
                {
                    return(_TestStatus == FreqTestStatus.pause || _TestStatus == FreqTestStatus.testing);
                });

                StopRealTimeMonitorCommand = new RelayCommand(() =>
                {
                    BtnPauseText = "暂停";
                    Sensor.SendStopWbqexCmd();
                    _dTimer.Stop();
                    _dTimer     = null;
                    _TestStatus = FreqTestStatus.stop;
                    UpdateTextBlockEnable();
                    dTimer.Stop();
                }, () =>
                {
                    return(_TestStatus == FreqTestStatus.pause || _TestStatus == FreqTestStatus.testing);
                });

                PauseMeasurCommand          = new RelayCommand(ExecutePauseMeasurCommand, CanExecutePauseMeasurCommand);
                StartMeasurCommand          = new RelayCommand(ExecuteStartMeasurCommand, CanExecuteStartMeasurCommand);
                StartRealTimeMonitorCommand = new RelayCommand(ExecuteStartRealTimeMonitorCommand, CanExecuteStartRealTimeMonitorCommand);

                #endregion


                WinLoadedCommand = new RelayCommand(
                    () =>
                {
                }
                    );
                _LineChartViewModel         = new ChartViewModel(this);
                _RtFreqDataModel            = new RtFreqDataViewModel();
                _RtGpsDataModel             = new RtGpsDataViewModel();
                _RtCdma2G_DataModel         = new RtCdma2G_DataViewModel();
                _CarRunInfor                = new CarRunInforViewModel();
                _RoadTestInfor              = new RoadTestViewModel();
                _RoadTestInfor.AnalysisList = new System.Collections.ObjectModel.ObservableCollection <Data.Collection.AnalysisResult>();
                _CollectionDataSave         = new Collection.CollectionDataSave();
                _CollectionDataSave.openSQLiteConnection();
                _CollectionDataSave.createTable();


                //ThreadDbOperator = new Thread(new ThreadStart(() =>
                //{

                //})) { IsBackground = true };
                //ThreadDbOperator.Start();
            }
            catch (Exception ex)
            {
                LogTool.Debug(ex.StackTrace);
                LogTool.Error("", ex);
            }
        }