Maybe someone can help me out because I have a really tricky situation with Bluetooth LE using WinRT on Windows 10 (like supposed here: Bluetooth Low Energy in .Net (C#)).
I need BLE within a Win32 classic desktop application.
Our code is running in a 32 Bit frame application using the .NET runtime (v4.0.30319, .NET Framework 4.6.2). I was able to manage all the other issues (strong naming some NuGet assemblies (Shiny.BluetoothLE), running BluetoothAdapter.GetRadioAsync()
in a 64 Bit COM surrogate DLL when running on 64 Bit Windows) but now I am totally stuck with this and here’s where:
The problem occurrs when executing var result = await gattDeviceService.GetCharacteristicsForUuidAsync(uuid, BluetoothCacheMode.Cached);
see here https://docs.microsoft.com/de-de/uwp/api/windows.devices.bluetooth.genericattributeprofile.gattdeviceservice.getcharacteristicsforuuidasync?view=winrt-20348.
When getting the read characteristics, the result.Status
is GattCommunicationStatus.Success
and the result contains the desired characteristic.
But of course I also need to get the write characteristic and I am ALWAYS getting GattCommunicationStatus.AccessDenied
!
Because of that the result contains NO characteristic.
Has anybody a clue why is that? I really need help here because I am kinda lost right now…
I also tried to set AccessPermission
via registry like supposed here but no luck at all…
PS: I use Windows 10 SDK Kit Build 20348 and like stated above it is a C# .NET Framework 4.6.2 project and all our assemblies are strong named because of using GAC. If I am missing anything don’t hesitate to contact me.
CodePudding user response:
For anyone who stumbles over the same stupid issue...Here's the solution:
On Windows, using .NET Framework 4.6.1 and the WinRT libraries inside a Non-UWP application, you can only call ONCE for getting the characteristics, no matter if you call for all at once via gattDeviceService.GetCharacteristicsAsync(BluetoothCacheMode.Uncached)
or for a specific one via gattDeviceService.GetCharacteristicsForUuidAsync(uuid, BluetoothCacheMode.Cached)
.
Any subsequent calls will fail with GattCommunicationStatus.AccessDenied
...
So my solution now is to retrieve all characteristics at once and filter them locally.
That did the trick! Anyways, this is so stupid...It wasted a lot of my time now!
As it seems, I also do not need to set any AccessPermission
via registry.
PS: I will call out to you, if I stumble over another tricky situation, just to let you guyz know.