Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: StartDiscovery function


This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 8 - Last Post: Mar 24, 2017 1:50 PM Last Post By: aidan levy
aidan levy

Posts: 31
Registered: 7/6/16
StartDiscovery function  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 23, 2017 1:23 PM
Hi !
I try to use StartDiscovery function : [http://docwiki.embarcadero.com/Libraries/Tokyo/en/System.Bluetooth.TBluetoothLEManager.StartDiscovery]
first option is : bool __fastcall StartDiscovery(unsigned Timeout, TBluetoothUUIDsList* const AFilterUUIDList = (TBluetoothUUIDsList*)(0x0), bool ForceConnect = false)/* overload */;
where AFilterUUIDList is an optional list of one or more UUIDs of Bluetooth GATT services. If you provide this list, the manager ignores the remote devices that do not advertise at least one of the specified services.

I added in header :
TBluetoothUUIDsList *LList;
const TBluetoothUUID MY_SERVICE = StringToGUID("{0003CBBB-0000-1000-8000-00805F9B0131}");

In FormCreate placed : LList->Add(MY_SERVICE);
In function I call : FBluetoothManagerLE->StartDiscovery(ScanningTime, LList);

When I try compile I received error : undefined reference to 'System::Generics::Collections::TList__1<_GUID>::Add(_GUID)'
I can`t find any example how to do it. What wrong ?
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: StartDiscovery function  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 23, 2017 1:43 PM   in response to: aidan levy in response to: aidan levy
aidan wrote:

I added in header :

TBluetoothUUIDsList *LList;
const TBluetoothUUID MY_SERVICE =
StringToGUID("{0003CBBB-0000-1000-8000-00805F9B0131}");

In FormCreate placed :
LList->Add(MY_SERVICE);

You declared a pointer so make sure you actually allocate the list object
before calling Add() on it:

LList = new TBluetoothUUIDsList;


Also, you should not be using the OnCreate event in C++ at all. It is a
Delphi idiom that causes illegal behavior in C++. Use the Form's constructor
instead.

In function I call :
FBluetoothManagerLE->StartDiscovery(ScanningTime, LList);

When I try compile I received error : undefined reference to
'System::Generics::Collections::TList__1<_GUID>::Add(_GUID)'

This is covered in the documentation:

How to Handle Delphi Generics in C++
http://docwiki.embarcadero.com/RADStudio/en/How_to_Handle_Delphi_Generics_in_C%2B%2B

The issue is described in detail in the second half of the page.

--
Remy Lebeau (TeamB)
Sean Hoffman

Posts: 126
Registered: 3/28/99
Re: StartDiscovery function  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 23, 2017 1:52 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
<snip>
Also, you should not be using the OnCreate event in C++ at all. It is a
Delphi idiom that causes illegal behavior in C++. Use the Form's constructor
instead.

Remy wasn't there an issue at one time with accessing VCL objects in the constructor? Something about you couldn't access them in the constructor because they hadn't been created yet?
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: StartDiscovery function  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 23, 2017 2:14 PM   in response to: Sean Hoffman in response to: Sean Hoffman
Sean wrote:

Remy wasn't there an issue at one time with accessing VCL objects
in the constructor?

No.

Something about you couldn't access them in the constructor because
they hadn't been created yet?

They are created during DFM streaming in the base TCustomForm constructor.
They have been fully created before a derived Form's constructor body is
entered. That has always been the case.

--
Remy Lebeau (TeamB)
aidan levy

Posts: 31
Registered: 7/6/16
Re: StartDiscovery function  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 23, 2017 2:15 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
For only 1 service UUID it`s very complicated . How can I make it static?

Something like this :
(TBluetoothUUIDsList) LList = ("{0003CBBB-0000-1000-8000-00805F9B0131}");
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: StartDiscovery function  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 23, 2017 2:42 PM   in response to: aidan levy in response to: aidan levy
aidan wrote:

For only 1 service UUID it`s very complicated . How can I
make it static?

You can't. TBluetoothUUIDsList is a TObjct*derived class, you must instantiate
it on the heap before you can then populate it, and then you have to destroy
it when you are doing using it. If you don't like that, wrap it in a RAII-style
helper class, eg:

class TSingleBluetoothUUIDList
{
private:
    TBluetoothUUIDsList *LList; 
 
    // to prevent copies to be made...
    TSingleBluetoothUUIDsList(const TSingleBluetoothUUIDsList &src) {}
    TSingleBluetoothUUIDsList& operator=(const TSingleBluetoothUUIDsList 
&rhs) { return *this; }
 
public:
    TSingleBluetoothUUIDsList(const String &uuidstr)
    {
        GUID uuid = StringToGUID(uuidstr);
        LList = new TBluetoothUUIDsList; 
        LList->Add(uuid);
    }
 
    TSingleBluetoothUUIDsList(const GUID &uuid)
    {
        LList = new TBluetoothUUIDsList; 
        LList->Add(uuid);
    }
 
    ~TSingleBluetoothUUIDsList()
    {
        delete LList; 
    }
 
    operator TBluetoothUUIDsList*() { return LList; }
};
 

const TBluetoothUUID MY_SERVICE = StringToGUID("{0003CBBB-0000-1000-8000-00805F9B0131}");
...
FBluetoothManagerLE->StartDiscovery(ScanningTime, TSingleBluetoothUUIDList(MY_SERVICE));

Or:
 

FBluetoothManagerLE->StartDiscovery(ScanningTime, TSingleBluetoothUUIDList("{0003CBBB-0000-1000-8000-00805F9B0131}"));
{code}

--
Remy Lebeau (TeamB)
aidan levy

Posts: 31
Registered: 7/6/16
Re: StartDiscovery function  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 24, 2017 12:08 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Thanks ! As usual you give extra answer !
aidan levy

Posts: 31
Registered: 7/6/16
Re: StartDiscovery function  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 24, 2017 12:13 AM   in response to: aidan levy in response to: aidan levy
Thanks
aidan levy

Posts: 31
Registered: 7/6/16
Re: StartDiscovery function  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 24, 2017 1:50 PM   in response to: aidan levy in response to: aidan levy
Some problem exist and I can`t understand why application is very unstable.
I created some demo application to check how it`s work but receive crashes and error messages like :
Access violation at address... or Duplicates not allowed
this is [project example|https://drive.google.com/open?id=0B69WY1p3UGcMMUpKd3hqcW85RmM]
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02