添加连接失败后重新连接及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();
|
GattCharacteristics.Clear();
|
||||||
|
|
||||||
GattDeviceServicesResult servicesResult = await _device.GetGattServicesAsync().GetResultAsync();
|
GattDeviceServicesResult servicesResult = await _device.GetGattServicesAsync().GetResultAsync();
|
||||||
|
|
||||||
if (servicesResult.Status == GattCommunicationStatus.Success)
|
if (servicesResult.Status == GattCommunicationStatus.Success)
|
||||||
{
|
{
|
||||||
foreach (GattDeviceService service in servicesResult.Services)
|
foreach (GattDeviceService service in servicesResult.Services)
|
||||||
@ -267,9 +268,15 @@ namespace MonitoringTechnology.Ble
|
|||||||
{
|
{
|
||||||
Log.Info("订阅通知成功!" + CharacteristicNotify.Uuid);
|
Log.Info("订阅通知成功!" + CharacteristicNotify.Uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
ConnectionStateChanged?.Invoke(this, true);
|
ConnectionStateChanged?.Invoke(this, true);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
string _message = "连接失败,请重新尝试连接!";
|
||||||
|
ReceiveValueChangedChanged(null, _message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -470,37 +477,37 @@ namespace MonitoringTechnology.Ble
|
|||||||
///定时去刷新首页电气数据和故障信息
|
///定时去刷新首页电气数据和故障信息
|
||||||
ThreadPool.QueueUserWorkItem(delegate
|
ThreadPool.QueueUserWorkItem(delegate
|
||||||
{
|
{
|
||||||
SynchronizationContext.SetSynchronizationContext(new
|
SynchronizationContext.SetSynchronizationContext(new
|
||||||
DispatcherSynchronizationContext(System.Windows.Application.Current.Dispatcher));
|
DispatcherSynchronizationContext(System.Windows.Application.Current.Dispatcher));
|
||||||
SynchronizationContext.Current.Post(pl =>
|
SynchronizationContext.Current.Post(pl =>
|
||||||
{
|
{
|
||||||
if (FirstPageView.firstPageView.ElectricalEnvironmentalList.Count >= 30)
|
if (FirstPageView.firstPageView.ElectricalEnvironmentalList.Count >= 30)
|
||||||
FirstPageView.firstPageView.ElectricalEnvironmentalList.RemoveAt(0);
|
FirstPageView.firstPageView.ElectricalEnvironmentalList.RemoveAt(0);
|
||||||
FirstPageView.firstPageView.ElectricalEnvironmentalList.Add(new ElectricalEnvironmentalModel()
|
FirstPageView.firstPageView.ElectricalEnvironmentalList.Add(new ElectricalEnvironmentalModel()
|
||||||
{
|
{
|
||||||
F_CreateDate = (DateTime)monitoringSensorModel.f_CreateDate,
|
F_CreateDate = (DateTime)monitoringSensorModel.f_CreateDate,
|
||||||
F_DatetimeSensor = (DateTime)monitoringSensorModel._datetime_Sensor,
|
F_DatetimeSensor = (DateTime)monitoringSensorModel._datetime_Sensor,
|
||||||
F_Tem = (float)monitoringSensorModel._Tem,
|
F_Tem = (float)monitoringSensorModel._Tem,
|
||||||
F_Hum = (float)monitoringSensorModel._Hum,
|
F_Hum = (float)monitoringSensorModel._Hum,
|
||||||
F_Pressure = (float)monitoringSensorModel._pressure
|
F_Pressure = (float)monitoringSensorModel._pressure
|
||||||
});
|
});
|
||||||
for (int i = 0; i < FirstPageView.firstPageView.ElectricalEnvironmentalList.Count; i++)
|
for (int i = 0; i < FirstPageView.firstPageView.ElectricalEnvironmentalList.Count; i++)
|
||||||
{
|
{
|
||||||
FirstPageView.firstPageView.ElectricalEnvironmentalList[i].F_SerialNo = i + 1;
|
FirstPageView.firstPageView.ElectricalEnvironmentalList[i].F_SerialNo = i + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
////告警信息
|
////告警信息
|
||||||
////if (FirstPageView.firstPageView.AlarmItemModelList.Count >= 30)
|
////if (FirstPageView.firstPageView.AlarmItemModelList.Count >= 30)
|
||||||
//// FirstPageView.firstPageView.AlarmItemModelList.RemoveAt(0);
|
//// FirstPageView.firstPageView.AlarmItemModelList.RemoveAt(0);
|
||||||
|
|
||||||
////FirstPageView.firstPageView.AlarmItemModelList.Add(new AlarmItemModel()
|
////FirstPageView.firstPageView.AlarmItemModelList.Add(new AlarmItemModel()
|
||||||
////{
|
////{
|
||||||
//// F_CreateDate =
|
//// F_CreateDate =
|
||||||
//// F_Time =
|
//// F_Time =
|
||||||
//// F_Message =
|
//// F_Message =
|
||||||
//// F_Len =
|
//// F_Len =
|
||||||
////});
|
////});
|
||||||
}, null);
|
}, null);
|
||||||
});
|
});
|
||||||
|
|
||||||
//姿态数据刷新
|
//姿态数据刷新
|
||||||
@ -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 + "');");
|
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);
|
ReceiveValueChangedChanged(null, _message);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|||||||
@ -125,6 +125,9 @@ namespace MonitoringTechnology.Ble
|
|||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 开始扫描
|
||||||
|
/// </summary>
|
||||||
public async void StartScan()
|
public async void StartScan()
|
||||||
{
|
{
|
||||||
if (advertisementWatcher.Status != BluetoothLEAdvertisementWatcherStatus.Started)
|
if (advertisementWatcher.Status != BluetoothLEAdvertisementWatcherStatus.Started)
|
||||||
@ -134,11 +137,15 @@ namespace MonitoringTechnology.Ble
|
|||||||
advertisementWatcher.Start();
|
advertisementWatcher.Start();
|
||||||
deviceWatcher.Start();
|
deviceWatcher.Start();
|
||||||
Started?.Invoke(this, null);
|
Started?.Invoke(this, null);
|
||||||
await Task.Delay(5000);
|
await Task.Delay(1000);
|
||||||
StopScan();
|
StartScan();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 停止扫描
|
||||||
|
/// </summary>
|
||||||
public void StopScan()
|
public void StopScan()
|
||||||
{
|
{
|
||||||
//判断状态,防止 InvalidOperationException
|
//判断状态,防止 InvalidOperationException
|
||||||
@ -149,7 +156,5 @@ namespace MonitoringTechnology.Ble
|
|||||||
Log.Info("停止扫描");
|
Log.Info("停止扫描");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -95,6 +95,7 @@
|
|||||||
<ColumnDefinition Width="Auto"/>
|
<ColumnDefinition Width="Auto"/>
|
||||||
<ColumnDefinition Width="Auto"/>
|
<ColumnDefinition Width="Auto"/>
|
||||||
<ColumnDefinition Width="Auto"/>
|
<ColumnDefinition Width="Auto"/>
|
||||||
|
<ColumnDefinition Width="Auto"/>
|
||||||
</Grid.ColumnDefinitions>
|
</Grid.ColumnDefinitions>
|
||||||
<Grid.RowDefinitions>
|
<Grid.RowDefinitions>
|
||||||
<RowDefinition Height="Auto"/>
|
<RowDefinition Height="Auto"/>
|
||||||
@ -113,6 +114,8 @@
|
|||||||
Click="buttonRead_Click" Template="{StaticResource ButtonTemplate}"/>
|
Click="buttonRead_Click" Template="{StaticResource ButtonTemplate}"/>
|
||||||
<Button Grid.Column="8" x:Name="TimeCheck" Content="系统校时" Width="90" Height="30" Margin="10,-2,10,6"
|
<Button Grid.Column="8" x:Name="TimeCheck" Content="系统校时" Width="90" Height="30" Margin="10,-2,10,6"
|
||||||
Click="TimeCheck_Click" Template="{StaticResource ButtonTemplate}"/>
|
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>
|
</Grid>
|
||||||
<Label Grid.Row="1" Content="日志记录" Foreground="White"/>
|
<Label Grid.Row="1" Content="日志记录" Foreground="White"/>
|
||||||
<!-- Log区,禁止 ListBox 横向滚动 TextBlock 才能实现自动换行 -->
|
<!-- Log区,禁止 ListBox 横向滚动 TextBlock 才能实现自动换行 -->
|
||||||
|
|||||||
@ -98,7 +98,7 @@ namespace MonitoringTechnology.Views
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sender"></param>
|
/// <param name="sender"></param>
|
||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void buttonConnect_Click(object sender, RoutedEventArgs e)
|
private async void buttonConnect_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
if (isSelect)
|
if (isSelect)
|
||||||
{
|
{
|
||||||
@ -116,7 +116,12 @@ namespace MonitoringTechnology.Views
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
systemOperationViewModel.BleDevice.Connect();
|
while (!isConnection)
|
||||||
|
{
|
||||||
|
systemOperationViewModel.BleDevice.Connect();
|
||||||
|
AddLog("正在尝试重新连接设备,请稍等!");
|
||||||
|
await Task.Delay(10000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -452,7 +457,7 @@ namespace MonitoringTechnology.Views
|
|||||||
if (isConnection)
|
if (isConnection)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (systemOperationViewModel.StartDate > DateTime.Now|| systemOperationViewModel.EndDate > DateTime.Now)
|
if (systemOperationViewModel.StartDate > DateTime.Now || systemOperationViewModel.EndDate > DateTime.Now)
|
||||||
{
|
{
|
||||||
AddLog("查询历史数据-时间不能大于当前日期,请重试!");
|
AddLog("查询历史数据-时间不能大于当前日期,请重试!");
|
||||||
}
|
}
|
||||||
@ -555,6 +560,37 @@ namespace MonitoringTechnology.Views
|
|||||||
AddLog("请搜索附近蓝牙设备并连接后重试!!!");
|
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
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
@ -583,6 +619,7 @@ namespace MonitoringTechnology.Views
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
device.Connect();
|
device.Connect();
|
||||||
|
AddLog("正在连接设备,请稍等!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -762,5 +799,6 @@ namespace MonitoringTechnology.Views
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user