Wireless Communication Library Support Forum

Frameworks => Bluetooth Framework => Topic started by: ami on November 25, 2010, 06:14:50 PM

Title: Pairing Window
Post by: ami on November 25, 2010, 06:14:50 PM
I'm using the wclClient can connecting to a device that has it's pin in it's friendly name. I'm pairing as follows.
Code: [Select]
Device.Address := address;

      wclClient.Transport := ctBluetooth;
      wclClient.BluetoothParams.Address := address;
      wclClient.BluetoothParams.Radio := Radio;
      wclClient.BluetoothParams.Service := SerialPortServiceClass_UUID;

      Cnt := 0;
      Res := WCL_E_SUCCESS;
      while Cnt < 3 do begin
        Res := Device.GetName(Radio, aName);
        if (aName <> '') or (Res <> WCL_E_SUCCESS) then Break;
        Inc(Cnt);
      end;

      if Res <> WCL_E_SUCCESS then
        raise Exception.Create('Unable to get device name.');

      pin := GetPinFromName( aName );

      if ( device.GetPaired( radio, isPaired ) <> WCL_E_SUCCESS ) then
        raise Exception.Create('Unabled to communicate with device');

      if ( (isPaired = false) and (Device.Pair( radio, pin ) <> WCL_E_SUCCESS) ) then
          raise Exception.Create('Unable to pair device.');

      if (wclClient.Connect <> WCL_E_SUCCESS ) then
        raise Exception.Create('Error. Connect failed.');


This seems to work 90% of the time. The onther 10% i get the pairing window prompting me for the pin. Do i need to delay before calling the connect?
Title: Re: Pairing Window
Post by: Mike Petrichenko on November 25, 2010, 06:18:21 PM
Hi,

Your code looks correct. Unfortunately I can not say way it may happen without testing it in real everonment. However, there is better way: use wclAuthenticator instead of Pair method.
Title: Re: Pairing Window
Post by: ami on November 25, 2010, 06:58:45 PM
with the code above, should i have the 'Authentication' property set to false?
Title: Re: Pairing Window
Post by: Mike Petrichenko on November 25, 2010, 07:03:56 PM
No, It must be true if your device requires authentication. TwclAuthenticator is one of the WCL components (available in Personal and Developer licenses).
Title: Re: Pairing Window
Post by: ami on November 25, 2010, 07:36:05 PM
Okay. We currently only have the lite non commerical. For now i guess i will try inserting a small delay after the pair.
Title: Re: Pairing Window
Post by: Mike Petrichenko on November 25, 2010, 07:52:20 PM
By your code:

it also may appear if Name wasn't read so the PIN is empty. In this case PIN dialog may popup.
Title: Re: Pairing Window
Post by: ami on November 25, 2010, 10:11:45 PM
The name should be there. I scan and query the name in another operation.

I guess it's possible if the device some how went out of range or the radio connection momentarily got interrupted.
If that's the case, that's fine. Displaying the dialog to attempt a manual pairing is better than failing immediatly.

So you're saying the  problem isn't because the Device.Pair call needs a bit of time before the
wclClient.Connect?



 

Title: Re: Pairing Window
Post by: Mike Petrichenko on November 25, 2010, 10:21:27 PM
It does look like name is empty. Check it.
Title: Re: Pairing Window
Post by: ami on November 25, 2010, 11:58:22 PM
Okay, i'll remove the delay and put in a trap to throw an exception if the name is blank. I'll see if that's the issue.
Title: Re: Pairing Window
Post by: ami on November 26, 2010, 10:35:12 PM
I added

Code: [Select]
if aName = '' then
  raise Exception.Create('Unable to get device name.');

I still see the pairing window, from time to time. I never see the exception. It appears to me windows or WCL needs some time after the pair call.

I'll just add a delay.
Title: Re: Pairing Window
Post by: Mike Petrichenko on November 26, 2010, 10:39:12 PM
Well, Actualy TwclAuthenticator was designed for such usage.

WCL just uses low-leve driver. Unfortunately we can not reproduce that on our side but we will work on it to find the problem and fix.
Title: Re: Pairing Window
Post by: ami on November 26, 2010, 11:08:59 PM
We only have the lite version. It's really not a big deal, with a 100ms delay things seem to work out.