一、最近工作中遇到这样的问题:
程序在电脑上对低功耗的蓝牙进行通信。
程序是可以在win10系统电脑上进行对低功耗蓝牙进行通信,但在win7系统上运行时提示:找不到Windows运行时类型“Windows.Devices.Bluetooth.GenericAttributeProfile.GattDeviceService”问题
二、通过网上了解到一些解决方案:
1.升级电脑系统win7系统->win10系统。(遇到升级后电脑变的很卡)
2.购买蓝牙5.0适配器,安装低功耗蓝牙驱动。(不行,虽然实现了能搜索到低功耗蓝牙,但程序运行时,还是提示以上问题。)
3.在代码上进行解决问题。(目前还在研究解决方案,这个比较难实现,如果哪个大佬指点,感激不尽)。
public class Bluetooth
{
// 搜索蓝牙设备对象
public Windows.Devices.Bluetooth.Advertisement.BluetoothLEAdvertisementWatcher deviceWatcher;
// 搜索蓝牙设备
private void StartBleDeviceWatcher()
{
try
{
this.deviceWatcher = new Windows.Devices.Bluetooth.Advertisement.BluetoothLEAdvertisementWatcher();
// 主动扫描
this.deviceWatcher.ScanningMode = Windows.Devices.Bluetooth.Advertisement.BluetoothLEScanningMode.Active;
// 设备信号超过这个阈值时,会被认为在范围内。
this.deviceWatcher.SignalStrengthFilter.InRangeThresholdInDBm = -80;
// 设备信号低于这个阈值时,会被认为在范围外。
this.deviceWatcher.SignalStrengthFilter.OutOfRangeThresholdInDBm = -90;
// 设置设备在范围外的超时时间,超过这个时间后,设备将被认为不在范围内。
this.deviceWatcher.SignalStrengthFilter.OutOfRangeTimeout = TimeSpan.FromMilliseconds(5000);
// 设置信号强度的采样间隔,用于控制多久采集一次信号强度。
this.deviceWatcher.SignalStrengthFilter.SamplingInterval = TimeSpan.FromMilliseconds(10000);
this.deviceWatcher.Received += DeviceWatcher_Received;
new Thread(new ThreadStart(
this.deviceWatcher.Start
)).Start();
//this.deviceWatcher.Start();
}
catch (Exception ex)
{
if (ex.Message.Contains("设备未就绪"))
{
MessageBox.Show("请先打开蓝牙");
}
}
}
}