添加连接失败后重新连接及Z轴校准功能
This commit is contained in:
parent
2f4b6c0ed1
commit
2886676945
BIN
MonitoringTechnology/Assets/Images/Logo.png
Normal file
BIN
MonitoringTechnology/Assets/Images/Logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 280 KiB |
@ -222,6 +222,7 @@ namespace MonitoringTechnology.Ble
|
||||
GattCharacteristics.Clear();
|
||||
|
||||
GattDeviceServicesResult servicesResult = await _device.GetGattServicesAsync().GetResultAsync();
|
||||
|
||||
if (servicesResult.Status == GattCommunicationStatus.Success)
|
||||
{
|
||||
foreach (GattDeviceService service in servicesResult.Services)
|
||||
@ -267,9 +268,15 @@ namespace MonitoringTechnology.Ble
|
||||
{
|
||||
Log.Info("订阅通知成功!" + CharacteristicNotify.Uuid);
|
||||
}
|
||||
|
||||
}
|
||||
ConnectionStateChanged?.Invoke(this, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
string _message = "连接失败,请重新尝试连接!";
|
||||
ReceiveValueChangedChanged(null, _message);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
@ -526,7 +533,7 @@ namespace MonitoringTechnology.Ble
|
||||
|
||||
localDataAccess.write("INSERT INTO monitoringsensormodel(F_CreateDate,F_DatetimeSensor,F_Tem,F_Hum,F_Pressure,F_AccelerationX,F_AccelerationY,F_AccelerationZ,F_AngularVelocityX,F_AngularVelocityY,F_AngularVelocityZ,F_DegreesX,F_DegreesY,F_DegreesZ,F_BatteryVoltage,F_ChargingCurrent,F_State) VALUES('" + monitoringSensorModel.f_CreateDate + "','" + monitoringSensorModel._datetime_Sensor + "','" + monitoringSensorModel._Tem + "','" + monitoringSensorModel._Hum + "','" + monitoringSensorModel._pressure + "','" + monitoringSensorModel._acceleration_X + "','" + monitoringSensorModel._acceleration_Y + "','" + monitoringSensorModel._acceleration_Z + "','" + monitoringSensorModel._angularVelocity_X + "','" + monitoringSensorModel._angularVelocity_Y + "','" + monitoringSensorModel._angularVelocity_Z + "','" + monitoringSensorModel.degrees_x + "','" + monitoringSensorModel.degrees_y + "','" + monitoringSensorModel.degrees_z + "','" + monitoringSensorModel._batteryVoltage + "','" + monitoringSensorModel._ChargingCurrent + "','" + monitoringSensorModel._State + "');");
|
||||
|
||||
_message = "状态数据获取成功: 数据上传时间: " + monitoringSensorModel._datetime_Sensor + " 温度:" + monitoringSensorModel._Tem + "℃ 湿度:" + monitoringSensorModel._Hum + "% 气压:" + monitoringSensorModel._pressure + "KPa 俯仰角:" + monitoringSensorModel._acceleration_X + "° 横滚角:" + monitoringSensorModel._acceleration_Y + "° 偏航角:" + monitoringSensorModel._acceleration_Z + "° 角速度X:" + monitoringSensorModel._angularVelocity_X + "m/s² 角速度Y:" + monitoringSensorModel._angularVelocity_Y + "m/s² 角速度Z:" + monitoringSensorModel._angularVelocity_Z + "m/s² 角度X:" + monitoringSensorModel.degrees_x + "rad/s 角度Y:" + monitoringSensorModel.degrees_y + "rad/s 角度Z:" + monitoringSensorModel.degrees_z + "rad/s 电池电压:" + monitoringSensorModel._batteryVoltage +"V 充电电流:"+ monitoringSensorModel._ChargingCurrent +"A 充电状态:"+ monitoringSensorModel._State;
|
||||
_message = "状态数据获取成功: 数据上传时间: " + monitoringSensorModel._datetime_Sensor + " 温度:" + monitoringSensorModel._Tem + "℃ 湿度:" + monitoringSensorModel._Hum + "% 气压:" + monitoringSensorModel._pressure + "KPa 俯仰角:" + monitoringSensorModel._acceleration_X + "° 横滚角:" + monitoringSensorModel._acceleration_Y + "° 偏航角:" + monitoringSensorModel._acceleration_Z + "° 角速度X:" + monitoringSensorModel._angularVelocity_X + "m/s² 角速度Y:" + monitoringSensorModel._angularVelocity_Y + "m/s² 角速度Z:" + monitoringSensorModel._angularVelocity_Z + "m/s² 角度X:" + monitoringSensorModel.degrees_x + "rad/s 角度Y:" + monitoringSensorModel.degrees_y + "rad/s 角度Z:" + monitoringSensorModel.degrees_z + "rad/s 电池电压:" + monitoringSensorModel._batteryVoltage + "V 充电电流:" + monitoringSensorModel._ChargingCurrent + "A 充电状态:" + monitoringSensorModel._State;
|
||||
ReceiveValueChangedChanged(null, _message);
|
||||
break;
|
||||
|
||||
|
||||
@ -125,6 +125,9 @@ namespace MonitoringTechnology.Ble
|
||||
}*/
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 开始扫描
|
||||
/// </summary>
|
||||
public async void StartScan()
|
||||
{
|
||||
if (advertisementWatcher.Status != BluetoothLEAdvertisementWatcherStatus.Started)
|
||||
@ -134,11 +137,15 @@ namespace MonitoringTechnology.Ble
|
||||
advertisementWatcher.Start();
|
||||
deviceWatcher.Start();
|
||||
Started?.Invoke(this, null);
|
||||
await Task.Delay(5000);
|
||||
StopScan();
|
||||
await Task.Delay(1000);
|
||||
StartScan();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 停止扫描
|
||||
/// </summary>
|
||||
public void StopScan()
|
||||
{
|
||||
//判断状态,防止 InvalidOperationException
|
||||
@ -149,7 +156,5 @@ namespace MonitoringTechnology.Ble
|
||||
Log.Info("停止扫描");
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
}
|
||||
}
|
||||
|
||||
@ -95,6 +95,7 @@
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
@ -113,6 +114,8 @@
|
||||
Click="buttonRead_Click" Template="{StaticResource ButtonTemplate}"/>
|
||||
<Button Grid.Column="8" x:Name="TimeCheck" Content="系统校时" Width="90" Height="30" Margin="10,-2,10,6"
|
||||
Click="TimeCheck_Click" Template="{StaticResource ButtonTemplate}"/>
|
||||
<Button Grid.Column="9" x:Name="ZCheck" Content="Z轴校准" Width="90" Height="30" Margin="10,-2,10,6"
|
||||
Click="ZCheck_Click" Template="{StaticResource ButtonTemplate}"/>
|
||||
</Grid>
|
||||
<Label Grid.Row="1" Content="日志记录" Foreground="White"/>
|
||||
<!-- Log区,禁止 ListBox 横向滚动 TextBlock 才能实现自动换行 -->
|
||||
|
||||
@ -98,7 +98,7 @@ namespace MonitoringTechnology.Views
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void buttonConnect_Click(object sender, RoutedEventArgs e)
|
||||
private async void buttonConnect_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (isSelect)
|
||||
{
|
||||
@ -115,8 +115,13 @@ namespace MonitoringTechnology.Views
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while (!isConnection)
|
||||
{
|
||||
systemOperationViewModel.BleDevice.Connect();
|
||||
AddLog("正在尝试重新连接设备,请稍等!");
|
||||
await Task.Delay(10000);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -452,7 +457,7 @@ namespace MonitoringTechnology.Views
|
||||
if (isConnection)
|
||||
{
|
||||
|
||||
if (systemOperationViewModel.StartDate > DateTime.Now|| systemOperationViewModel.EndDate > DateTime.Now)
|
||||
if (systemOperationViewModel.StartDate > DateTime.Now || systemOperationViewModel.EndDate > DateTime.Now)
|
||||
{
|
||||
AddLog("查询历史数据-时间不能大于当前日期,请重试!");
|
||||
}
|
||||
@ -555,6 +560,37 @@ namespace MonitoringTechnology.Views
|
||||
AddLog("请搜索附近蓝牙设备并连接后重试!!!");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Z轴校准
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private async void ZCheck_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (isConnection)
|
||||
{
|
||||
byte[] _send = new byte[] { 0xFE, 0xEF, 0x00, 0x0E, 0x00, 0x10, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16 };
|
||||
int a = 0;
|
||||
for (int i = 0; i < _send.Length - 2; i++)
|
||||
{
|
||||
a += _send[i];
|
||||
}
|
||||
a = a & 0xFF;
|
||||
_send[16] = (byte)a;
|
||||
//调用发送的那个方法
|
||||
bool success = await systemOperationViewModel.BleDevice.Write(_send);
|
||||
if (success)
|
||||
{
|
||||
AddLog("已进行Z轴校准!");
|
||||
PreservationData(_send.ToList(), "Z轴校准指令");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
AddLog("请搜索附近蓝牙设备并连接后重试!!!");
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
@ -583,6 +619,7 @@ namespace MonitoringTechnology.Views
|
||||
else
|
||||
{
|
||||
device.Connect();
|
||||
AddLog("正在连接设备,请稍等!");
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
@ -762,5 +799,6 @@ namespace MonitoringTechnology.Views
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user