Search code examples
delphibluetooth-lowenergydelphi-11-alexandria

Bluetooth LE not working with Delphi 11.3


I recompiled an older project with Delphi 11.3, that was created with Delphi 10, and worked just fine. Now it stopped working. The program simply freezes.

The program communicated with a BLE device (Microchip RN4871) using the TBluetoothLE component. I did everything that the documentation says, discovered the devices, found it, discovered its services, found what I needed, got the characteristics I needed, and communicated. Everything worked without any problems on an Android phone (FMX project). On Windows 11, the program works only if the device is paired with Windows. The project throws an exception saying the device is not paired, right when I try to discover the services of the device. I don't understand that as BLE does not need pairing, as far as I know. But OK, I can live with that. Now I recompiled that project using Delphi 11.3. If the device is not paired, the program simply freezes instead of throwing an exception. Right when I call ADevice.DiscoverServices, it just stops responding. If I pair the device with Windows, it goes on however. It finds the service I need. Then I try to read the characteristics of this service. AService.GetCharacteristic() returns nil, but that's fine, since the documentation says "Warning: You must read the value of the AService.Characteristics property before you call GetCharacteristic. Otherwise, GetCharacteristic returns nil." So let's read AService.Characteristics. And the program freezes. The exact same code that worked when I compiled it with Delphi 10, now freezes. I googled, and googled, found nothing. I read every topic here related to Delphi and Bluetooth LE. Found nothing. What do I miss? Did Embarcadero messed it up, and do I need to wait for the next Delphi version?


Solution

  • Delphi 11.3 BTLE is simply broken on Windows. I needed to update the file System.Win.BluetoothWinRT.pas file (aka make a copy from the source file and add the changed copy to your project).

    The changes I made are handled in this thread: https://www.delphipraxis.net/213532-bluetooth-le-unter-windows-11-funktioniert-nicht-mehr.html

    It's in German but the fixes should be readable ;)

    Let me know if that worked for you.