From 86856b6e42b0ef0edcc4bb57fa4b9521b79ad0bf Mon Sep 17 00:00:00 2001 From: pxzleo Date: Fri, 4 Aug 2017 22:29:20 +0800 Subject: [PATCH] =?UTF-8?q?RTK=E5=8A=A0=E5=85=A5=E5=81=9C=E6=AD=A2?= =?UTF-8?q?=E5=8F=91=E9=80=81=E5=92=8C=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ViewModels/ControlPanelViewModel.cs | 85 ++++++++++++++----- .../Views/ControlPanelView.xaml | 9 +- 2 files changed, 70 insertions(+), 24 deletions(-) diff --git a/Plane.FormationCreator/ViewModels/ControlPanelViewModel.cs b/Plane.FormationCreator/ViewModels/ControlPanelViewModel.cs index 7a4c4f5..645fc34 100644 --- a/Plane.FormationCreator/ViewModels/ControlPanelViewModel.cs +++ b/Plane.FormationCreator/ViewModels/ControlPanelViewModel.cs @@ -45,6 +45,22 @@ namespace Plane.FormationCreator.ViewModels set { Set(nameof(AltP), ref _AltP, value); } } + + private string _RTKState = "RTK未发送"; + public string RTKState + { + get { return _RTKState; } + set { Set(nameof(RTKState), ref _RTKState, value); } + } + + private string _RTKbtntxt = "发送RTK"; + public string RTKbtntxt + { + get { return _RTKbtntxt; } + set { Set(nameof(RTKbtntxt), ref _RTKbtntxt, value); } + } + + private ICommand _UnlockCommand; public ICommand UnlockCommand { @@ -204,28 +220,36 @@ namespace Plane.FormationCreator.ViewModels { return _SendRTKCommand ?? (_SendRTKCommand = new RelayCommand(async () => { - Rtkport = new SerialPortConnection(RTKcomvalue,57600) as IConnection; - await Rtkport.OpenAsync(); - if (!Rtkport.IsOpen) + if (!trkthreadrun) { - Alert.Show("无法打开" + RTKcomvalue , "警告", MessageBoxButton.OK, MessageBoxImage.Warning); - return; - } - trkthreadrun = true; //开始运行后台任务 - /* //线程方式后台运行rtk转发任务 - thrtk = new System.Threading.Thread(new System.Threading.ThreadStart(mainloop)) - { - IsBackground = true, - Name = "injectgps" - }; - thrtk.Start(); - */ - //后台任务方式运行rtk转发任务 - await Task.Run(async () => + + + Rtkport = new SerialPortConnection(RTKcomvalue, 57600) as IConnection; + await Rtkport.OpenAsync(); + if (!Rtkport.IsOpen) { - //读取RTK数据循环 - while (trkthreadrun) + Alert.Show("无法打开" + RTKcomvalue, "警告", MessageBoxButton.OK, MessageBoxImage.Warning); + return; + } + trkthreadrun = true; //开始运行后台任务 + /* //线程方式后台运行rtk转发任务 + thrtk = new System.Threading.Thread(new System.Threading.ThreadStart(mainloop)) + { + IsBackground = true, + Name = "injectgps" + }; + thrtk.Start(); + */ + //后台任务方式运行rtk转发任务 + Alert.Show("RTK数据开始发送", "提示", MessageBoxButton.OK, MessageBoxImage.Information); + RTKState = "RTK数据发送中"; + RTKbtntxt = "停止RTK"; + + await Task.Run(async () => { + //读取RTK数据循环 + while (trkthreadrun) + { //读入RTK数据 var packet = await ReadRTKPacketAsync().ConfigureAwait(false); //分发到每个飞机 @@ -235,10 +259,27 @@ namespace Plane.FormationCreator.ViewModels } - await Task.Delay(200).ConfigureAwait(false); + await Task.Delay(200).ConfigureAwait(false); + + } + }).ConfigureAwait(false); + Alert.Show("RTK数据停止发送", "提示", MessageBoxButton.OK, MessageBoxImage.Information); + + } + else//停止RTK + { + trkthreadrun = false; + Rtkport.Close(); + Rtkport = null; + + RTKState = "未发送RTK数据"; + RTKbtntxt = "发送RTK"; + + + + + } - } - }).ConfigureAwait(false); /* diff --git a/Plane.FormationCreator/Views/ControlPanelView.xaml b/Plane.FormationCreator/Views/ControlPanelView.xaml index 705cc08..cf615ef 100644 --- a/Plane.FormationCreator/Views/ControlPanelView.xaml +++ b/Plane.FormationCreator/Views/ControlPanelView.xaml @@ -67,9 +67,14 @@ HorizontalContentAlignment="Right" Text="{Binding RTKcomvalue, UpdateSourceTrigger=PropertyChanged}" /> -