c# Bluetooth LE - write configuration error - ValueChanged never called

后端 未结 2 1300
夕颜
夕颜 2021-01-28 12:01

So I try to connect my c# WPF program to a BLE device and this is the code to connect to the device:

private async Task ConnectToWatcher(DeviceInformation device         


        
相关标签:
2条回答
  • 2021-01-28 12:40

    you need to call CoInitializeSecurity before

    more info here. couple of weeks I spent looking for solution :)

    https://social.msdn.microsoft.com/Forums/en-US/58da3fdb-a0e1-4161-8af3-778b6839f4e1/

    0 讨论(0)
  • 2021-01-28 12:50

    Apparently, some Windows 10 builds have a COM security bug. Solution was to register for Windows-Insider-Program and update Windows.

    Update: There are two more solutions to this: 1) Calling CoInitializeSecurity from outside your c#-code (didn't bring it to work) - or- 2) Writing two new keys into the windows registry. You cann create a file "Bluetooth.reg", which will add those two keys on a doubleklick. This answer from https://social.msdn.microsoft.com/Forums/en-US/58da3fdb-a0e1-4161-8af3-778b6839f4e1/bluetooth-bluetoothledevicefromidasync-does-not-complete-on-10015063?forum=wdk was my solution:

    Hi Kamen, I have experienced exactly same issue. You can give a quick try of the following:


    Windows Registry Editor Version 5.00

    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\AppID{C6BFD646-3DF0-4DE5-B7AF-5FFFACB844A5}] "AccessPermission"=hex:01,00,04,80,9c,00,00,00,ac,00,00,00,00,00,00,00,14,00,\ 00,00,02,00,88,00,06,00,00,00,00,00,14,00,07,00,00,00,01,01,00,00,00,00,00,\ 05,0a,00,00,00,00,00,14,00,03,00,00,00,01,01,00,00,00,00,00,05,12,00,00,00,\ 00,00,18,00,07,00,00,00,01,02,00,00,00,00,00,05,20,00,00,00,20,02,00,00,00,\ 00,18,00,03,00,00,00,01,02,00,00,00,00,00,0f,02,00,00,00,01,00,00,00,00,00,\ 14,00,03,00,00,00,01,01,00,00,00,00,00,05,13,00,00,00,00,00,14,00,03,00,00,\ 00,01,01,00,00,00,00,00,05,14,00,00,00,01,02,00,00,00,00,00,05,20,00,00,00,\ 20,02,00,00,01,02,00,00,00,00,00,05,20,00,00,00,20,02,00,00

    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\AppID\YOURAPP.exe] "AppID"="{C6BFD646-3DF0-4DE5-B7AF-5FFFACB844A5}"


    1. Copy above content to a text file.

    2. Replace 'YOURAPP.EXE' with your executable name

    3. Optionally replace GUIDs (I have created a new one for you)

    4. Save text file with an extension as .reg

    5. Double click on the file.

    6. You would see a message 'The Keys and values contained in ..... .reg have been successfully added to the registry.'

    With this, I don't need to call CoInitializeSecurity from my app.

    0 讨论(0)
提交回复
热议问题