FromBluetoothAddressAsync never returns on Windows 10 Creators Update in WPF Application

后端 未结 3 858
醉话见心
醉话见心 2020-12-20 19:12

I upgraded to Windows 10, version 1703 build 15063 (Creators Update) official release. When I run the following code in a WPF desktop application, BluetoothLEDevice.FromBlue

3条回答
  •  既然无缘
    2020-12-20 20:10

    Interestingly, it does work on desktop applications using cppwinrt:

    Advertisement::BluetoothLEAdvertisementWatcher watcher;
    
    void Start() {
        watcher.ScanningMode(Advertisement::BluetoothLEScanningMode::Active);
        Windows::Foundation::TimeSpan timeout = std::chrono::seconds(2);
        watcher.SignalStrengthFilter().OutOfRangeTimeout(timeout);
        watcher.SignalStrengthFilter().OutOfRangeThresholdInDBm(-90);
    
        watcher.Received([&](Advertisement::BluetoothLEAdvertisementWatcher watcher, Advertisement::BluetoothLEAdvertisementReceivedEventArgs eventArgs) {
            connect(eventArgs.BluetoothAddress());
        });
        watcher.Start();
    }
    
    Windows::Foundation::IAsyncAction connect(uint64_t uuid) {
        co_await resume_background();
        BluetoothLEDevice device = co_await BluetoothLEDevice::FromBluetoothAddressAsync(uuid);
        GenericAttributeProfile::GattDeviceServicesResult gatt = co_await device.GetGattServicesForUuidAsync(myServiceUUID);
        // works fine!
    }
    

    However, notifications for GATT characteristics don't work for me after that. I have filed a bug report with the cppwinrt project, but the devs don't seem to be particularly inclined to look into it.

    I have no idea what that API is doing differently than the desktop C# version.

提交回复
热议问题