C# UWP BluetoothLEDevice“;未找到元素。(HRESULT的例外情况:0x80070490)";
我需要一个蓝牙设备通过GATT连接。 下面是我能想到的全新通用应用程序中最简单的代码:C# UWP BluetoothLEDevice“;未找到元素。(HRESULT的例外情况:0x80070490)";,c#,bluetooth,async-await,bluetooth-lowenergy,uwp,C#,Bluetooth,Async Await,Bluetooth Lowenergy,Uwp,我需要一个蓝牙设备通过GATT连接。 下面是我能想到的全新通用应用程序中最简单的代码: protected async override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); var devices = await DeviceInformation.FindAllAsync(BluetoothLEDevice.GetDeviceSelector()); if (device
protected async override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
var devices = await DeviceInformation.FindAllAsync(BluetoothLEDevice.GetDeviceSelector());
if (devices.Count <= 0) return;
this.bluetoothDevice = await BluetoothLEDevice.FromIdAsync(devices[0].Id);
}
每个方法都返回一个包含两个配对蓝牙设备的列表。
但是,第一个方法(BluetoothLEDevice.GetDeviceSelector())返回名称字段为空的设备,而其他两个方法则返回正确的名称
我在任何地方都找不到任何具有相同问题的示例,在使用“BluetoothLEDevice.FromIdAsync”时,似乎没有人关心异常处理。这与
async await
有什么关系?我不完全确定,但我发现了一些情况,其中元素not found exception与线程/异步问题有关。我还读到BluetoothLEDevice.FromIdAsync在第一次使用时使用UI线程请求许可,这可能是一个问题这似乎是Windows 10中的一个主要错误。正如我发现的,几乎相同的代码在Windows8上运行得很好。如果有人将蓝牙LE设备正确连接到Windows 10,那将非常有趣。我已经读过一些关于关贸总协定许多独特服务存在问题的提示
<Capabilities>
<Capability Name="internetClient" />
<DeviceCapability Name="bluetooth.genericAttributeProfile">
<Device Id="any">
<Function Type="name:genericAttribute"/>
</Device>
</DeviceCapability>
</Capabilities>
var devices = await DeviceInformation.FindAllAsync(GattDeviceService.GetDeviceSelectorFromUuid(new Guid("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX")));
var devices = await DeviceInformation.FindAllAsync(GattDeviceService.GetDeviceSelectorFromUuid(GattServiceUuids.GenericAccess));