|
Replies:
14
-
Last Post:
Feb 27, 2018 7:52 AM
Last Post By: Scott Pinkham
|
|
|
Posts:
8
Registered:
5/29/15
|
|
Hi
Platform WIN7 Delphi 10.2 Sample 'ExploreDeviceLE' and 'BLEScanner' on IOS
IOS: Mac Mini, macOS High Sierra V10.13.3
Target Platform MacOSX 10.13.2
'Android'
I run the apps on Android. It can find the BLE device next to the Android.
'Mac Mini'
The apps starts normal on IOS. I try to 'Find device'. It popup exception 'raised exception class EBluetoothAdapterException with message Bluetooth device not found: disconnected or turned off'.
I check with the 'Setting'. Bluetooth device is turned ON. It looks like it cannot see the Mac Mini Bluetooth in Delphi.
Would you please help me to check about with is going on?
Thank you for your assistance.
Dko
Here is my code:-
============================
unit Unit1;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
System.Bluetooth, System.Bluetooth.Components, FMX.Controls.Presentation,
FMX.StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
BluetoothLE1: TBluetoothLE;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.fmx}
procedure TForm1.Find device(Sender: TObject);
begin
BluetoothLE1.DiscoverDevices(2500); //This code is not working
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
BluetoothLE1.Enabled := True;
end;
end.
Edited by: Dominic Ko on Feb 1, 2018 11:20 AM
Edited by: Dominic Ko on Feb 1, 2018 11:25 AM
Edited by: Dominic Ko on Feb 2, 2018 11:54 AM
|
|
|
Posts:
54
Registered:
3/19/07
|
|
Make sure that Bluetooth is enabled on the Mac Mini.
In the FormCreate event you should call Bluetooth.EnableBluetooth first and check the return value from that to make sure BT really is enabled.
HTH,
Scott
Hi
Platform WIN7 Delphi 10.2 Sample 'ExploreDeviceLE' and 'BLEScanner' on IOS
IOS: Mac Mini, macOS High Sierra V10.13.3
Target Platform MacOSX 10.13.2
'Android'
I run the apps on Android. It can find the BLE device next to the Android.
'Mac Mini'
The apps starts normal on IOS. I try to 'Find device'. It popup exception 'raised exception class EBluetoothAdapterException with message Bluetooth device not found: disconnected or turned off'.
I check with the 'Setting'. Bluetooth device is turned ON. It looks like it cannot see the Mac Mini Bluetooth in Delphi.
Would you please help me to check about with is going on?
Thank you for your assistance.
Dko
Here is my code:-
============================
unit Unit1;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
System.Bluetooth, System.Bluetooth.Components, FMX.Controls.Presentation,
FMX.StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
BluetoothLE1: TBluetoothLE;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.fmx}
procedure TForm1.Find device(Sender: TObject);
begin
BluetoothLE1.DiscoverDevices(2500); //This code is not working
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
BluetoothLE1.Enabled := True;
end;
end.
Edited by: Dominic Ko on Feb 1, 2018 11:20 AM
Edited by: Dominic Ko on Feb 1, 2018 11:25 AM
Edited by: Dominic Ko on Feb 2, 2018 11:54 AM
|
|
|
|
Posts:
8
Registered:
5/29/15
|
|
Hi Scott
Thank you for your reply.
I try the below code. At FormCreate, BluetoothLE is enabled. When Button1Click BluetoothLE is also enabled.
I also debug the DiscoverDevices. 'The hardware Bluetooth Device is not found.' It also not work and unsuccessful.
I am using BluetoothLE mouse and keyboard on Mac Mini. Bluetooth is working on Mac mini.
In Delphi, it is using 'System.Mac.Bluetooth.pas' this GetConnectionState function to get the BluetoothLE status.
But it cannot get the status properly.
function TMacBluetoothLEManager.GetConnectionState: TBluetoothConnectionState;
var
LTotal: Single;
LMacBluetoothLEAdapter: TMacBluetoothLEAdapter;
begin
if FAdapter = nil then
FAdapter := TMacBluetoothLEAdapter.Create(Self);
LMacBluetoothLEAdapter := TMacBluetoothLEAdapter(FAdapter);
if LMacBluetoothLEAdapter.FLEManager.FCentralManager.state = CBCentralManagerStatePoweredOn then
Result := TBluetoothConnectionState.Connected
else
begin
LTotal := 0;
repeat
InternalWaitMessage(0.05);
LTotal := LTotal + 0.05;
until (LTotal >= 1) or (LMacBluetoothLEAdapter.FLEManager.FCentralManager.state = CBCentralManagerStatePoweredOn);
if LMacBluetoothLEAdapter.FLEManager.FCentralManager.state = CBCentralManagerStatePoweredOn then
Result := TBluetoothConnectionState.Connected
else
Result := TBluetoothConnectionState.Disconnected;
end;
end;
If you have try similar code on BluetoohLE successful in IOS or OSX environment. You can send it to me or
what Delphi version, IOS or OSX version you are using?
Here is my updated code.
=======================================
procedure TForm1.Button1Click(Sender: TObject);
begin
if BluetoothLE1.Enabled then
BluetoothLE1.DiscoverDevices(2500); //It also not work at this line.
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
while not BluetoothLE1.Enabled do
BluetoothLE1.Enabled := True;
end;
=======================================
Make sure that Bluetooth is enabled on the Mac Mini.
In the FormCreate event you should call Bluetooth.EnableBluetooth first and check the return value from that to make sure BT really is enabled.
HTH,
Scott
Hi
Platform WIN7 Delphi 10.2 Sample 'ExploreDeviceLE' and 'BLEScanner' on IOS
IOS: Mac Mini, macOS High Sierra V10.13.3
Target Platform MacOSX 10.13.2
'Android'
I run the apps on Android. It can find the BLE device next to the Android.
'Mac Mini'
The apps starts normal on IOS. I try to 'Find device'. It popup exception 'raised exception class EBluetoothAdapterException with message Bluetooth device not found: disconnected or turned off'.
I check with the 'Setting'. Bluetooth device is turned ON. It looks like it cannot see the Mac Mini Bluetooth in Delphi.
Would you please help me to check about with is going on?
Thank you for your assistance.
Dko
Here is my code:-
============================
unit Unit1;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
System.Bluetooth, System.Bluetooth.Components, FMX.Controls.Presentation,
FMX.StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
BluetoothLE1: TBluetoothLE;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.fmx}
procedure TForm1.Find device(Sender: TObject);
begin
BluetoothLE1.DiscoverDevices(2500); //This code is not working
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
BluetoothLE1.Enabled := True;
end;
end.
Edited by: Dominic Ko on Feb 1, 2018 11:20 AM
Edited by: Dominic Ko on Feb 1, 2018 11:25 AM
Edited by: Dominic Ko on Feb 2, 2018 11:54 AM
Edited by: Dominic Ko on Feb 3, 2018 2:50 AM
Edited by: Dominic Ko on Feb 3, 2018 2:51 AM
|
|
|
|
Posts:
1,850
Registered:
1/7/00
|
|
Dominic Ko wrote:
I also debug the DiscoverDevices. 'The hardware Bluetooth Device is not found.' It also not work and unsuccessful.
I am using BluetoothLE mouse and keyboard on Mac Mini. Bluetooth is working on Mac mini.
In Delphi, it is using 'System.Mac.Bluetooth.pas' this GetConnectionState function to get the BluetoothLE status.
But it cannot get the status properly.
What do you mean by "cannot get the status properly"? What exactly is happening in that routine?
--
Dave Nottage [MVP, TeamB]
Find hints, tips and tricks at Delphi Worlds blog: http://www.delphiworlds.com
|
|
|
|
Posts:
8
Registered:
5/29/15
|
|
Hi Scott,
Many many thanks.
I also test the code with Mac Book Air and Mini. Result is the same.
OS of IOS Mac Book Air: 10.13.2
OS of IOS Mac Mini: 10.13.3
Delphi: 10.2.1
Both Mac are using Bluetooth Wireless Mouse and Keyboard.
System.Mac.Bluetooth.pas is Delphi Library at 'C:\Program Files (x86)\Embarcadero\Studio\19.1\source\rtl\net\System.Mac.Bluetooth.pas'.
You can open a new project>Multi-Device Application. Drop a BluetoothLE on the form. And start with FormCreate with below code. Trace into BluetoothLE1.DiscoverDevices(2500); Result are the same 'Bluetooth device not found: disconnected or turned off' with exception.
procedure TForm1.FormCreate(Sender: TObject);
begin
BluetoothLE1.DiscoverDevices(2500);
end;
Run and Trace into the code. Trace it to function TMacBluetoothLEManager.DoGetAdapter: TBluetoothLEAdapter;. It 'cannot get the status properly' of GetConnectionState. It only return 'TBluetoothConnectionState.Disconnected'.
If you are successful to connect with the BluetoothLE in IOS/OSX. What version of Delphi and IOS/OSX in Mac are using?
Thank you for your help and assistance.
Dko
Note: I have a project using BluetoothLE in IOS and OSX
Dominic Ko wrote:
I also debug the DiscoverDevices. 'The hardware Bluetooth Device is not found.' It also not work and unsuccessful.
I am using BluetoothLE mouse and keyboard on Mac Mini. Bluetooth is working on Mac mini.
In Delphi, it is using 'System.Mac.Bluetooth.pas' this GetConnectionState function to get the BluetoothLE status.
But it cannot get the status properly.
What do you mean by "cannot get the status properly"? What exactly is happening in that routine?
--
Dave Nottage [MVP, TeamB]
Find hints, tips and tricks at Delphi Worlds blog: http://www.delphiworlds.com
|
|
|
|
Posts:
1,850
Registered:
1/7/00
|
|
Dominic Ko wrote:
Hi Scott,
I'm not Scott.
Run and Trace into the code. Trace it to function TMacBluetoothLEManager.DoGetAdapter: TBluetoothLEAdapter;. It
'cannot get the status properly' of GetConnectionState. It only return 'TBluetoothConnectionState.Disconnected'.
I assume then you mean that in the code:
if LMacBluetoothLEAdapter.FLEManager.FCentralManager.state = CBCentralManagerStatePoweredOn then
Result := TBluetoothConnectionState.Connected
else
Result := TBluetoothConnectionState.Disconnected;
It sets it to the Disconnected state. It might help to discover what the value of
LMacBluetoothLEAdapter.FLEManager.FCentralManager.state is, because there a number of other states it can be, namely:
CBCentralManagerStateUnknown (0)
CBCentralManagerStateResetting (1)
CBCentralManagerStateUnsupported (2)
CBCentralManagerStateUnauthorized (3)
CBCentralManagerStatePoweredOff (4)
I suggest making a copy of the unit, including in the project, and change the routine to the following:
function TMacBluetoothLEManager.GetConnectionState: TBluetoothConnectionState;
var
LTotal: Single;
LMacBluetoothLEAdapter: TMacBluetoothLEAdapter;
LState: CBCentralManagerState; // <------ Added this variable
begin
if FAdapter = nil then
FAdapter := TMacBluetoothLEAdapter.Create(Self);
LMacBluetoothLEAdapter := TMacBluetoothLEAdapter(FAdapter);
if LMacBluetoothLEAdapter.FLEManager.FCentralManager.state = CBCentralManagerStatePoweredOn then
Result := TBluetoothConnectionState.Connected
else
begin
LTotal := 0;
repeat
InternalWaitMessage(0.05);
LTotal := LTotal + 0.05;
until (LTotal >= 1) or (LMacBluetoothLEAdapter.FLEManager.FCentralManager.state = CBCentralManagerStatePoweredOn);
LState := LMacBluetoothLEAdapter.FLEManager.FCentralManager.state;
if LState = CBCentralManagerStatePoweredOn then // <------- Put a breakpoint on this line
Result := TBluetoothConnectionState.Connected
else
Result := TBluetoothConnectionState.Disconnected;
end;
end;
As per the comments in the code, put a breakpoint where indicated, and examine the value of LState to discover what the
actual problem is.
--
Dave Nottage [MVP, TeamB]
Find hints, tips and tricks at Delphi Worlds blog: http://www.delphiworlds.com
|
|
|
|
Posts:
8
Registered:
5/29/15
|
|
Hi Dave Nottage [MVP, TeamB]
Thank you very much for your assistance and help.
I re-route the code to System.Mac.Bluetooth below. I got LState = CBCentralManagerStateUnknown.
Note: From the StackOverFlow, I got some information in xCode. init(delegate:queue:) or: init(delegate:queue:options:) with CBCentralManager.
I don't know how to proceed? Would you please advice?
Many thanks.
Dko
function TMacBluetoothLEManager.GetConnectionState: TBluetoothConnectionState;
var
LTotal: Single;
LMacBluetoothLEAdapter: TMacBluetoothLEAdapter;
LState: CBCentralManagerState; // <------ Added this variable
begin
if FAdapter = nil then
FAdapter := TMacBluetoothLEAdapter.Create(Self);
LMacBluetoothLEAdapter := TMacBluetoothLEAdapter(FAdapter);
if LMacBluetoothLEAdapter.FLEManager.FCentralManager.state = CBCentralManagerStatePoweredOn then
Result := TBluetoothConnectionState.Connected
else
begin
LTotal := 0;
repeat
InternalWaitMessage(0.05);
LTotal := LTotal + 0.05;
until (LTotal >= 1) or (LMacBluetoothLEAdapter.FLEManager.FCentralManager.state = CBCentralManagerStatePoweredOn);
LState := LMacBluetoothLEAdapter.FLEManager.FCentralManager.state;
if LState = CBCentralManagerStateResetting then
Result := TBluetoothConnectionState.Disconnected;
if LState = CBCentralManagerStateUnsupported then
Result := TBluetoothConnectionState.Disconnected;
if LState = CBCentralManagerStateUnauthorized then
Result := TBluetoothConnectionState.Disconnected;
if LState = CBCentralManagerStatePoweredOff then
Result := TBluetoothConnectionState.Disconnected;
if LState = CBCentralManagerStateUnknown then //Finally break in here.
Result := TBluetoothConnectionState.Disconnected;
if LState = CBCentralManagerStatePoweredOn then
Result := TBluetoothConnectionState.Connected;
//if LMacBluetoothLEAdapter.FLEManager.FCentralManager.state = CBCentralManagerStatePoweredOn then
// Result := TBluetoothConnectionState.Connected
//else
// Result := TBluetoothConnectionState.Disconnected;
end;
end;
|
|
|
|
Posts:
1,850
Registered:
1/7/00
|
|
Dominic Ko wrote:
I re-route the code to System.Mac.Bluetooth below. I got LState = CBCentralManagerStateUnknown.
Note: From the StackOverFlow, I got some information in xCode. init(delegate:queue:) or:
init(delegate:queue:options:) with CBCentralManager.
The code is creating the CBCentralManager that way, in TInternalBluetoothLEManager.Create.
The problem may be that the GetConnectionState routine has not waited long enough for Bluetooth to initialize, as
suggested by this post:
https://stackoverflow.com/questions/12518562/what-causes-cbcentralmanagerstateunknown-in-ios/15720690
I expect that there should be something like an OnConnectionStateChange event or similar that is fired when the state
changes, from the centralManagerDidUpdateState method of TInternalBluetoothLEManager.
To come up with a definitive answer, I'd need to spend more time on it.
--
Dave Nottage [MVP, TeamB]
Find hints, tips and tricks at Delphi Worlds blog: http://www.delphiworlds.com
|
|
|
|
Posts:
8
Registered:
5/29/15
|
|
Hi Dave Nottage [MVP, TeamB]
Thank you for time.
I think you are right.
I got something from Apple Developer.
https://developer.apple.com/documentation/corebluetooth/cbcentralmanager
BluetoothLE must be init() first.
https://medium.com/@nebsp/hello-bluetooth-a-simple-swift-app-for-communicating-with-an-arduino-bbf26e089999
He share with the idea to write Bluetooth in swift
1) When initializing a CBCentralManager object, don’t call scanForPeripheralsWithServices right away. Instead, wait for the central’s state to be .PoweredOn via centralManagerDidUpdateState.
2) When a peripheral has been discovered (in didDiscoverPeripheral) you must hold onto that peripheral with a strong reference before trying to connect to it.
Best regards
Dko
Dominic Ko wrote:
I re-route the code to System.Mac.Bluetooth below. I got LState = CBCentralManagerStateUnknown.
Note: From the StackOverFlow, I got some information in xCode. init(delegate:queue:) or:
init(delegate:queue:options:) with CBCentralManager.
The code is creating the CBCentralManager that way, in TInternalBluetoothLEManager.Create.
The problem may be that the GetConnectionState routine has not waited long enough for Bluetooth to initialize, as
suggested by this post:
https://stackoverflow.com/questions/12518562/what-causes-cbcentralmanagerstateunknown-in-ios/15720690
I expect that there should be something like an OnConnectionStateChange event or similar that is fired when the state
changes, from the centralManagerDidUpdateState method of TInternalBluetoothLEManager.
To come up with a definitive answer, I'd need to spend more time on it.
--
Dave Nottage [MVP, TeamB]
Find hints, tips and tricks at Delphi Worlds blog: http://www.delphiworlds.com
|
|
|
|
Posts:
54
Registered:
3/19/07
|
|
Dko-
I just wanted to confirm that I have been able to make an app which uses Bluetooth LE to communicate with other devices, and the app runs on all 4 platforms (and is available on the Google and Apple stores) with only minor differences in the code for each platform, so it is possible. I'm using Delphi Berlin.
One thing I did do in my app is to always check the ConnectionState property and make sure it's 'Connected'. Also, on Android you have to watch out -- some Bluetooth events handlers will get called from a thread (not the main GUI thread), so if your handler does anything to the GUI it needs to use Synchronize.
-Scott
Hi Dave Nottage [MVP, TeamB]
Thank you for time.
I think you are right.
I got something from Apple Developer.
https://developer.apple.com/documentation/corebluetooth/cbcentralmanager
BluetoothLE must be init() first.
https://medium.com/@nebsp/hello-bluetooth-a-simple-swift-app-for-communicating-with-an-arduino-bbf26e089999
He share with the idea to write Bluetooth in swift
1) When initializing a CBCentralManager object, don’t call scanForPeripheralsWithServices right away. Instead, wait for the central’s state to be .PoweredOn via centralManagerDidUpdateState.
2) When a peripheral has been discovered (in didDiscoverPeripheral) you must hold onto that peripheral with a strong reference before trying to connect to it.
Best regards
Dko
Dominic Ko wrote:
I re-route the code to System.Mac.Bluetooth below. I got LState = CBCentralManagerStateUnknown.
Note: From the StackOverFlow, I got some information in xCode. init(delegate:queue:) or:
init(delegate:queue:options:) with CBCentralManager.
The code is creating the CBCentralManager that way, in TInternalBluetoothLEManager.Create.
The problem may be that the GetConnectionState routine has not waited long enough for Bluetooth to initialize, as
suggested by this post:
https://stackoverflow.com/questions/12518562/what-causes-cbcentralmanagerstateunknown-in-ios/15720690
I expect that there should be something like an OnConnectionStateChange event or similar that is fired when the state
changes, from the centralManagerDidUpdateState method of TInternalBluetoothLEManager.
To come up with a definitive answer, I'd need to spend more time on it.
--
Dave Nottage [MVP, TeamB]
Find hints, tips and tricks at Delphi Worlds blog: http://www.delphiworlds.com
|
|
|
|
Posts:
8
Registered:
5/29/15
|
|
Hi Scott Pinkham,
Thank you for your reply.
I download and try the Bluetooth apps from Apple Store. They are working and testing good in iPhone and iPad. They may be written or developed in swift (xcode). This means it must work in IOS or OSX.
May be I am missing something in Delphi development. I use Tokyo 10.2.1.
In Android (Nexus7), the code is OK to DiscoverDevices(2500) and it can connect to system Bluetooth device and carry on to detect Bluetooth (Next to the Tablet Nexus7).
In OSX, the code will raise exception.
Can you explain more about 'your handler does anything to the GUI it needs to use Synchronize' <---- is in IOS or OSX? Do you means in IOS or OSX need to use Synchronize to handle GUI things?
Thanks
Dko
procedure TForm1.FormCreate(Sender: TObject);
begin
while not BluetoothLE1.Enabled do
BluetoothLE1.Enabled := True;
BluetoothLE1.DiscoverDevices(2500);
end;
Dko-
I just wanted to confirm that I have been able to make an app which uses Bluetooth LE to communicate with other devices, and the app runs on all 4 platforms (and is available on the Google and Apple stores) with only minor differences in the code for each platform, so it is possible. I'm using Delphi Berlin.
One thing I did do in my app is to always check the ConnectionState property and make sure it's 'Connected'. Also, on Android you have to watch out -- some Bluetooth events handlers will get called from a thread (not the main GUI thread), so if your handler does anything to the GUI it needs to use Synchronize.
-Scott
Edited by: Dominic Ko on Feb 9, 2018 9:54 AM
|
|
|
|
Posts:
54
Registered:
3/19/07
|
|
I've been away for awhile... hope you've been able to get this working. To answer your questions:
* I am using Delphi 10.1 Berlin. I probably won't update to Tokyo for awhile since I keep hearing about problems with it and Android.
* On macOS, I'm using Xcode7.3 on Sierra -- I tend to stay with old versions as long as possible until the bugs are worked out of the new versions.
* Some Bluetooth events (such as OnDiscoveryEnd and others) occur on a background thread, NOT the main GUI thread, so if you are doing anything that access the GUI from that event, you need to use Synchronize. There are some differences on this between platforms -- I believe it's mainly an issue on Android.
I mostly use macOS when debugging Bluetooth code (Windows doesn't support the BLE profile I'm using) and have had very few problems with it, so maybe it's a issue with Tokyo?
Regards,
Scott
Hi Scott Pinkham,
Thank you for your reply.
I download and try the Bluetooth apps from Apple Store. They are working and testing good in iPhone and iPad. They may be written or developed in swift (xcode). This means it must work in IOS or OSX.
May be I am missing something in Delphi development. I use Tokyo 10.2.1.
In Android (Nexus7), the code is OK to DiscoverDevices(2500) and it can connect to system Bluetooth device and carry on to detect Bluetooth (Next to the Tablet Nexus7).
In OSX, the code will raise exception.
Can you explain more about 'your handler does anything to the GUI it needs to use Synchronize' <---- is in IOS or OSX? Do you means in IOS or OSX need to use Synchronize to handle GUI things?
Thanks
Dko
procedure TForm1.FormCreate(Sender: TObject);
begin
while not BluetoothLE1.Enabled do
BluetoothLE1.Enabled := True;
BluetoothLE1.DiscoverDevices(2500);
end;
Dko-
I just wanted to confirm that I have been able to make an app which uses Bluetooth LE to communicate with other devices, and the app runs on all 4 platforms (and is available on the Google and Apple stores) with only minor differences in the code for each platform, so it is possible. I'm using Delphi Berlin.
One thing I did do in my app is to always check the ConnectionState property and make sure it's 'Connected'. Also, on Android you have to watch out -- some Bluetooth events handlers will get called from a thread (not the main GUI thread), so if your handler does anything to the GUI it needs to use Synchronize.
-Scott
Edited by: Dominic Ko on Feb 9, 2018 9:54 AM
|
|
|
|
Posts:
54
Registered:
3/19/07
|
|
I did some more testing on different hardware and I'm running into the same issue as you on a MacBook Pro (an old 2010 model running Sierra), so there may be a hardware/software compatibility problem with BluetoothLE on some Macs. It may be possible to use a USB Bluetooth dongle that supports the newer BLE standards -- I've tried this on a Mac Mini and it works.
-Scott
I've been away for awhile... hope you've been able to get this working. To answer your questions:
* I am using Delphi 10.1 Berlin. I probably won't update to Tokyo for awhile since I keep hearing about problems with it and Android.
* On macOS, I'm using Xcode7.3 on Sierra -- I tend to stay with old versions as long as possible until the bugs are worked out of the new versions.
* Some Bluetooth events (such as OnDiscoveryEnd and others) occur on a background thread, NOT the main GUI thread, so if you are doing anything that access the GUI from that event, you need to use Synchronize. There are some differences on this between platforms -- I believe it's mainly an issue on Android.
I mostly use macOS when debugging Bluetooth code (Windows doesn't support the BLE profile I'm using) and have had very few problems with it, so maybe it's a issue with Tokyo?
Regards,
Scott
Hi Scott Pinkham,
Thank you for your reply.
I download and try the Bluetooth apps from Apple Store. They are working and testing good in iPhone and iPad. They may be written or developed in swift (xcode). This means it must work in IOS or OSX.
May be I am missing something in Delphi development. I use Tokyo 10.2.1.
In Android (Nexus7), the code is OK to DiscoverDevices(2500) and it can connect to system Bluetooth device and carry on to detect Bluetooth (Next to the Tablet Nexus7).
In OSX, the code will raise exception.
Can you explain more about 'your handler does anything to the GUI it needs to use Synchronize' <---- is in IOS or OSX? Do you means in IOS or OSX need to use Synchronize to handle GUI things?
Thanks
Dko
procedure TForm1.FormCreate(Sender: TObject);
begin
while not BluetoothLE1.Enabled do
BluetoothLE1.Enabled := True;
BluetoothLE1.DiscoverDevices(2500);
end;
Dko-
I just wanted to confirm that I have been able to make an app which uses Bluetooth LE to communicate with other devices, and the app runs on all 4 platforms (and is available on the Google and Apple stores) with only minor differences in the code for each platform, so it is possible. I'm using Delphi Berlin.
One thing I did do in my app is to always check the ConnectionState property and make sure it's 'Connected'. Also, on Android you have to watch out -- some Bluetooth events handlers will get called from a thread (not the main GUI thread), so if your handler does anything to the GUI it needs to use Synchronize.
-Scott
Edited by: Dominic Ko on Feb 9, 2018 9:54 AM
|
|
|
|
Posts:
8
Registered:
5/29/15
|
|
Hi Scott,
Thank you for your testing.
I try to put a dongle to Mac Mini and activate the GMYLE Bluetooth LE via Bluetooth Explorer.
I try test the Delphi code. It also not work. 'Bluetooth device not found'.
What kind of dongle or brand and model you are using?
Thank you.
Dko
I did some more testing on different hardware and I'm running into the same issue as you on a MacBook Pro (an old 2010 model running Sierra), so there may be a hardware/software compatibility problem with BluetoothLE on some Macs. It may be possible to use a USB Bluetooth dongle that supports the newer BLE standards -- I've tried this on a Mac Mini and it works.
-Scott
I've been away for awhile... hope you've been able to get this working. To answer your questions:
* I am using Delphi 10.1 Berlin. I probably won't update to Tokyo for awhile since I keep hearing about problems with it and Android.
* On macOS, I'm using Xcode7.3 on Sierra -- I tend to stay with old versions as long as possible until the bugs are worked out of the new versions.
* Some Bluetooth events (such as OnDiscoveryEnd and others) occur on a background thread, NOT the main GUI thread, so if you are doing anything that access the GUI from that event, you need to use Synchronize. There are some differences on this between platforms -- I believe it's mainly an issue on Android.
I mostly use macOS when debugging Bluetooth code (Windows doesn't support the BLE profile I'm using) and have had very few problems with it, so maybe it's a issue with Tokyo?
Regards,
Scott
Hi Scott Pinkham,
Thank you for your reply.
I download and try the Bluetooth apps from Apple Store. They are working and testing good in iPhone and iPad. They may be written or developed in swift (xcode). This means it must work in IOS or OSX.
May be I am missing something in Delphi development. I use Tokyo 10.2.1.
In Android (Nexus7), the code is OK to DiscoverDevices(2500) and it can connect to system Bluetooth device and carry on to detect Bluetooth (Next to the Tablet Nexus7).
In OSX, the code will raise exception.
Can you explain more about 'your handler does anything to the GUI it needs to use Synchronize' <---- is in IOS or OSX? Do you means in IOS or OSX need to use Synchronize to handle GUI things?
Thanks
Dko
procedure TForm1.FormCreate(Sender: TObject);
begin
while not BluetoothLE1.Enabled do
BluetoothLE1.Enabled := True;
BluetoothLE1.DiscoverDevices(2500);
end;
Dko-
I just wanted to confirm that I have been able to make an app which uses Bluetooth LE to communicate with other devices, and the app runs on all 4 platforms (and is available on the Google and Apple stores) with only minor differences in the code for each platform, so it is possible. I'm using Delphi Berlin.
One thing I did do in my app is to always check the ConnectionState property and make sure it's 'Connected'. Also, on Android you have to watch out -- some Bluetooth events handlers will get called from a thread (not the main GUI thread), so if your handler does anything to the GUI it needs to use Synchronize.
-Scott
Edited by: Dominic Ko on Feb 9, 2018 9:54 AM
|
|
|
|
Posts:
54
Registered:
3/19/07
|
|
The dongle I'm using is made by Plugable, model USB-BT4LE.
-Scott
Hi Scott,
Thank you for your testing.
I try to put a dongle to Mac Mini and activate the GMYLE Bluetooth LE via Bluetooth Explorer.
I try test the Delphi code. It also not work. 'Bluetooth device not found'.
What kind of dongle or brand and model you are using?
Thank you.
Dko
I did some more testing on different hardware and I'm running into the same issue as you on a MacBook Pro (an old 2010 model running Sierra), so there may be a hardware/software compatibility problem with BluetoothLE on some Macs. It may be possible to use a USB Bluetooth dongle that supports the newer BLE standards -- I've tried this on a Mac Mini and it works.
-Scott
I've been away for awhile... hope you've been able to get this working. To answer your questions:
* I am using Delphi 10.1 Berlin. I probably won't update to Tokyo for awhile since I keep hearing about problems with it and Android.
* On macOS, I'm using Xcode7.3 on Sierra -- I tend to stay with old versions as long as possible until the bugs are worked out of the new versions.
* Some Bluetooth events (such as OnDiscoveryEnd and others) occur on a background thread, NOT the main GUI thread, so if you are doing anything that access the GUI from that event, you need to use Synchronize. There are some differences on this between platforms -- I believe it's mainly an issue on Android.
I mostly use macOS when debugging Bluetooth code (Windows doesn't support the BLE profile I'm using) and have had very few problems with it, so maybe it's a issue with Tokyo?
Regards,
Scott
Hi Scott Pinkham,
Thank you for your reply.
I download and try the Bluetooth apps from Apple Store. They are working and testing good in iPhone and iPad. They may be written or developed in swift (xcode). This means it must work in IOS or OSX.
May be I am missing something in Delphi development. I use Tokyo 10.2.1.
In Android (Nexus7), the code is OK to DiscoverDevices(2500) and it can connect to system Bluetooth device and carry on to detect Bluetooth (Next to the Tablet Nexus7).
In OSX, the code will raise exception.
Can you explain more about 'your handler does anything to the GUI it needs to use Synchronize' <---- is in IOS or OSX? Do you means in IOS or OSX need to use Synchronize to handle GUI things?
Thanks
Dko
procedure TForm1.FormCreate(Sender: TObject);
begin
while not BluetoothLE1.Enabled do
BluetoothLE1.Enabled := True;
BluetoothLE1.DiscoverDevices(2500);
end;
Dko-
I just wanted to confirm that I have been able to make an app which uses Bluetooth LE to communicate with other devices, and the app runs on all 4 platforms (and is available on the Google and Apple stores) with only minor differences in the code for each platform, so it is possible. I'm using Delphi Berlin.
One thing I did do in my app is to always check the ConnectionState property and make sure it's 'Connected'. Also, on Android you have to watch out -- some Bluetooth events handlers will get called from a thread (not the main GUI thread), so if your handler does anything to the GUI it needs to use Synchronize.
-Scott
Edited by: Dominic Ko on Feb 9, 2018 9:54 AM
|
|
|
|
Legend
|
|
Helpful Answer
(5 pts)
|
|
Correct Answer
(10 pts)
|
|
Connect with Us