Author Topic: Pairing Window  (Read 26007 times)

ami

  • Guest
Pairing Window
« 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?

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3675
  • Karma: 1000
    • Wireless Communication Libraries
Re: Pairing Window
« Reply #1 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.

ami

  • Guest
Re: Pairing Window
« Reply #2 on: November 25, 2010, 06:58:45 PM »
with the code above, should i have the 'Authentication' property set to false?

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3675
  • Karma: 1000
    • Wireless Communication Libraries
Re: Pairing Window
« Reply #3 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).

ami

  • Guest
Re: Pairing Window
« Reply #4 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.

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3675
  • Karma: 1000
    • Wireless Communication Libraries
Re: Pairing Window
« Reply #5 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.

ami

  • Guest
Re: Pairing Window
« Reply #6 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?



 


Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3675
  • Karma: 1000
    • Wireless Communication Libraries
Re: Pairing Window
« Reply #7 on: November 25, 2010, 10:21:27 PM »
It does look like name is empty. Check it.

ami

  • Guest
Re: Pairing Window
« Reply #8 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.

ami

  • Guest
Re: Pairing Window
« Reply #9 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.

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3675
  • Karma: 1000
    • Wireless Communication Libraries
Re: Pairing Window
« Reply #10 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.

ami

  • Guest
Re: Pairing Window
« Reply #11 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.

 

Sitemap 1 2 3 4 5 6 7