question

EdmondHardin-2537 avatar image
0 Votes"
EdmondHardin-2537 asked RoyLi-MSFT edited

Syntax for BluetoothLEDevice::RequestPreferredConnectionParameters()

Using C++/WinRT, Win10, VS2019, SDK 10.0.22621.0, NuGet CppWinRT 2.0.220608.4

I'm trying to get the RequestPreferredConnectionParameters to work. At this point I am wondering if maybe I have the syntax wrong or maybe something else about it that I am not aware of. The MS docs for the function are here and the link to the various parameters are here.

The command line, as I have it, with pubDevice being the BLE device object, is:

 BluetoothLEPreferredConnectionParametersRequest rcoConnect = pubDevice.RequestPreferredConnectionParameters(BluetoothLEPreferredConnectionParameters::ThroughputOptimized());

Just to mention, I am able to run

 auto statusTest = co_await pubDevice.RequestAccessAsync();

before the RequestPreferredConnectionParameters without problems so, obviously, the device object is good and can be connected to.

What is happening is this. I have a function, OpenDevice(), that opens the device based on the address. If, after getting the device object, I issue the command above while still in the OpenDevice function, the code will not crash but it will immediately jump to the end of the OpenDevice() function bypassing all other lines of code below it and there will be no connection at all after that.

If I run the RequestPreferredConnectionParameters outside of the OpenDevice() function it errors out with a
An unhandled exception was encountered during a user callback and the line referenced is in base.h line 4942 if (result == impl::error_changed_state)

I had assumed that the callback refered to was the Rx Characteristic ValueChanged Callback that is set in OpenDevice(). So I tested by first revoking that callback with

 pubRxCharacteristic.ValueChanged(etValueChangeToken);

and then running the RequestPreferredConnectionParameters but I still got the An unhandled exception error.

The only other callback that I have is the BluetoothLEAdvertisementWatcher advert received callback but that was stopped after the device was found.

Can anyone verify that my syntax seems correct and/or have any clue as to what is causing my problems?


windows-uwpc++
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@EdmondHardin-2537 I haven't heard from you for a while. Have you checked my answer?

0 Votes 0 ·

1 Answer

RoyLi-MSFT avatar image
0 Votes"
RoyLi-MSFT answered

Hello,

Welcome to Microsoft Q&A!

Can anyone verify that my syntax seems correct and/or have any clue as to what is causing my problems?

I noticed that you are running in Windows 10. Based on the document that you posted: BluetoothLEPreferredConnectionParameters Class and BluetoothLEDevice.RequestPreferredConnectionParameters Method, both of them require Windows 11 (introduced in 10.0.22000.0). This should be the reason why you are getting this behavior. Please try to run your project in a Windows 11 Device. Please let me know if you still have questions about this.

Thank you.


If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.