Jump to content
Sign in to follow this  
pcplayer99

BLE cannot get service

Recommended Posts

Android, Delphi 10.3.3. community version.

 

TBluetoothLE  scan BLE device ok, and then:

var
  AService: TBluetoothGattService;

 

AService := BluetoothLE1.GetService(Self.FMyDevice, Service_ID);
if not Assigned(AService) then raise exception.Create('No service found.');

 

Here, mybe I can got the service, mybe not, on the same device. Maybe I restart APP and can got service.

Share this post


Link to post

Thank you Lars.

 

My Program is:

 

1. Scan device. then list devices.

2. Let user select a device, and user click a "Select" button.

3. in the button onclick event handler, find the device, and set user selected device to FMyDevice, and then call BluetoothLE1.DiscoverServices(Self.FMyDevice);

4. Do someting that need service, call GetService(FMyDevice), and then maybe ok, maybe got nil.

Share this post


Link to post

You may need to give Android a little time after setting one command, before it will be able to give back a result.

Also you should always ensure to touch such commands and results into the UI thread, as these responses came from extenral devices,

and may drop in at any (asynchronous) time.

The whole Bluetooth system is quite tricky, and has various smaller or larger pitfalls on different platforms.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×