RTK加入停止发送和提示

This commit is contained in:
pxzleo 2017-08-04 22:29:20 +08:00
parent d81d8f30ea
commit 86856b6e42
2 changed files with 70 additions and 24 deletions

View File

@ -45,6 +45,22 @@ namespace Plane.FormationCreator.ViewModels
set { Set(nameof(AltP), ref _AltP, value); } 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; private ICommand _UnlockCommand;
public ICommand UnlockCommand public ICommand UnlockCommand
{ {
@ -204,28 +220,36 @@ namespace Plane.FormationCreator.ViewModels
{ {
return _SendRTKCommand ?? (_SendRTKCommand = new RelayCommand(async () => return _SendRTKCommand ?? (_SendRTKCommand = new RelayCommand(async () =>
{ {
Rtkport = new SerialPortConnection(RTKcomvalue,57600) as IConnection; if (!trkthreadrun)
await Rtkport.OpenAsync();
if (!Rtkport.IsOpen)
{ {
Alert.Show("无法打开" + RTKcomvalue , "警告", MessageBoxButton.OK, MessageBoxImage.Warning);
return;
} Rtkport = new SerialPortConnection(RTKcomvalue, 57600) as IConnection;
trkthreadrun = true; //开始运行后台任务 await Rtkport.OpenAsync();
/* //线程方式后台运行rtk转发任务 if (!Rtkport.IsOpen)
thrtk = new System.Threading.Thread(new System.Threading.ThreadStart(mainloop))
{
IsBackground = true,
Name = "injectgps"
};
thrtk.Start();
*/
//后台任务方式运行rtk转发任务
await Task.Run(async () =>
{ {
//读取RTK数据循环 Alert.Show("无法打开" + RTKcomvalue, "警告", MessageBoxButton.OK, MessageBoxImage.Warning);
while (trkthreadrun) 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数据 //读入RTK数据
var packet = await ReadRTKPacketAsync().ConfigureAwait(false); 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);
/* /*

View File

@ -67,9 +67,14 @@
HorizontalContentAlignment="Right" HorizontalContentAlignment="Right"
Text="{Binding RTKcomvalue, UpdateSourceTrigger=PropertyChanged}" Text="{Binding RTKcomvalue, UpdateSourceTrigger=PropertyChanged}"
/> />
<Button Content="发送RTK" <Button Content="{Binding Path=RTKbtntxt}"
Command="{Binding SendRTKCommand}" /> Command="{Binding SendRTKCommand}" />
</WrapPanel> <TextBlock
Margin="5,5,5,5"
Text="{Binding Path=RTKState}"
/>
</WrapPanel>
<!--// 林俊清, 20150920, 目前不再使用 FormationController删除相关按钮。 <!--// 林俊清, 20150920, 目前不再使用 FormationController删除相关按钮。