Wireless Communication Library Support Forum
Frameworks => Bluetooth Framework => Topic started 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.
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?
-
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.
-
with the code above, should i have the 'Authentication' property set to false?
-
No, It must be true if your device requires authentication. TwclAuthenticator is one of the WCL components (available in Personal and Developer licenses).
-
Okay. We currently only have the lite non commerical. For now i guess i will try inserting a small delay after the pair.
-
By your code:
it also may appear if Name wasn't read so the PIN is empty. In this case PIN dialog may popup.
-
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?
-
It does look like name is empty. Check it.
-
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.
-
I added
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.
-
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.
-
We only have the lite version. It's really not a big deal, with a 100ms delay things seem to work out.