Wireless Communication Library Support Forum

Frameworks => Bluetooth Framework => Topic started by: ppaquin on February 06, 2013, 05:28:53 PM

Title: wclBluetoothDevice Pair request lock
Post by: ppaquin on February 06, 2013, 05:28:53 PM
Hi,

I'm trying to pair a device with WCL (6.11.2.0). The demo app "BluetoothDiscoveryDemo" works great but it can't pair a device... It locks on the line "Device.Pair(Radio);" and never go after... If i click again on "pair" button, it  says "Authenticator is already in use".

Any idea?...

Many thanks,
Title: Re: wclBluetoothDevice Pair request lock
Post by: Mike Petrichenko on February 06, 2013, 07:00:11 PM
What bluetooth driver and os do you use?
Title: Re: wclBluetoothDevice Pair request lock
Post by: ppaquin on February 13, 2013, 09:46:46 AM
Hi thanks for answer and sorry for delay...

I'm using a Microsoft BT Dongle ucrently, on Windows 7 64bits Pro.

By the way, i tested the dmo app "BlueToothDiscoveryDemo" on another PC (Windows 7 netbook) with a Toshiba RFCOMM BT, it don't see the radio...
Title: Re: wclBluetoothDevice Pair request lock
Post by: Mike Petrichenko on February 13, 2013, 10:14:05 AM
Hi,

Its strange. Does it show any dialog box when pairing? If no - dialog box may appear behind the main window so it looks like locked.

I have reproduced the problem. Looks like it locks when device is already paired.

With regards Toshiba: what Toshiba version do you use?
Title: Re: wclBluetoothDevice Pair request lock
Post by: ppaquin on February 13, 2013, 12:10:15 PM
In my case, Device isn't paired (it shows "false" in pair column). But it still locks... If you get some clue on this, many thanks!

On Toshiba, I tried on Toshiba Z930-10T laptop. I don't know where I can find more information... In control Panel, it says "Bluetooth RFCOMM"

Many thanks,
Title: Re: wclBluetoothDevice Pair request lock
Post by: Mike Petrichenko on February 13, 2013, 12:13:37 PM
Pairing looks fixed (attached). Toshiba: you have to check driver version in its control panel. Unfortunately I don't know what version is installed on each device.

[attachment deleted by admin]
Title: Re: wclBluetoothDevice Pair request lock
Post by: ppaquin on February 13, 2013, 12:17:54 PM
Thanks for you answer, i'll have a look on your code, many thanks again!

For Toshiba, here's what I get from Control Panel :
TOSHIBA
Date : 05/03/2012
Version : 8.0.2505.0
Sign : Microsoft Windows Hardware Compatibility Publisher

Reguards,
Title: Re: wclBluetoothDevice Pair request lock
Post by: ppaquin on February 13, 2013, 12:48:13 PM
Hi, I tried the new Demo, and the fact is that it doesn't lock anymore. But I still can't pair my device with the demo app, i get "authentication error".

I put some debug points in the code, and it seems i don't go through "Device_OnPINRequest", "Device_OnPasskey" or "Device_OnNumericComparison" so I think device can't get the right PIN code...

Do i have anything wrong?
Title: Re: wclBluetoothDevice Pair request lock
Post by: Mike Petrichenko on February 13, 2013, 12:53:45 PM
It looks like your device rejects authentication request or something wrong with drivers. If no one event fires then MS driver doesn't actually call pairing function and BluetoothAuthenticateDeviceEx returns Error without actualy trying to pair with device. It may appear if device is already paired or if something wrong with dongle/driver. Make sure that MS driver can pair itself (through MS BT Add device dialog).

With regards to Toshiba: I could't find exactly the same version of driver but I found 9.10.00 (T) and tested it: all works as expected. However, Toshiba SDK doesn't like if you run application from debugger. Try to reboot your laptop and run application without debugger. Also, make sure that Toshiba works itself (by running its Add device dialog).
Title: Re: wclBluetoothDevice Pair request lock
Post by: ppaquin on February 13, 2013, 02:05:22 PM
I tried to pair the device with the Window BT Dialog, all went ok. Then the device appeared as paired in the demo app, and i even can unpair it with the demo app. But i can't pair it again... You're right, seems that pairing function isn't called...

If you have idea for that, i would be glad...

Let's forget Toshiba for the moment, that's not my main problem.
Title: Re: wclBluetoothDevice Pair request lock
Post by: Mike Petrichenko on February 13, 2013, 02:06:16 PM
Device needs PIN or numeric comparison?
Title: Re: wclBluetoothDevice Pair request lock
Post by: ppaquin on February 13, 2013, 02:54:34 PM
Device need PIN.

Well, I got some news :
- For toshiba, i'm realy sorry... BT was disabled! Now it works better than my Microsoft dongle: All is good (i can pair my device...etc.)
- For my desktop PC (with Microsoft dongle) : I can pair device in a particular case :
* I select "enum"
* I select my radio
* I click "Discover"
* While discover is running (laStatus has "Waiting for names") : i select my device and clic "pair"
=> I go through Device_OnPINRequest and get my PIN, then i have a message "select device" that has no consequences
* On next "Discover", my device is paired!

But if I wait the discover to finish, then i can't pair my device the same way... It only works when "waiting for name" is written...

I go on searching.
Title: Re: wclBluetoothDevice Pair request lock
Post by: Mike Petrichenko on February 13, 2013, 03:03:58 PM
Try to:

1. find method wclBluetoothDiscovery_OnDiscoveryComplete

2. comment out those lines:
Timer.Enabled = true;
laStatus.Text = "Waiting for names";

3. Add the following lines after laStatus.Text = "Waiting for names";

Item.Selected = true;
lvDevices.Select();
RefreshDevice();
Item.Selected = false;
lvDevices.Select();

With that changes WCL will not wait on timer for names and you can try to pair immediately after discovering. I guess its something with timeout in your device. Does your device have limited discovering/connectiong mode?
Title: Re: wclBluetoothDevice Pair request lock
Post by: ppaquin on February 13, 2013, 03:07:18 PM
I was taping this while you answer, we got the same solution. Just wonder why i can't pair a second time without launching discover again.

Thanks,

-----


I'm on the right way...

I commented all Timer_Tick method, that is called after "waiting for name" message. That seems to conflict with my actions.

Now i can pair my device without problem. Once Paired, i can unpair it but i can't pair it again unless I go on discover again.

If you have some explanation on that, i would be glad, but i think i can begin to work with such method, without pairing multiple time the same device :).

Thanks!
Title: Re: wclBluetoothDevice Pair request lock
Post by: Mike Petrichenko on February 13, 2013, 03:13:13 PM
I'm absolutely not sure why it can be but we will keep working on this. Also I was noticed that if you call Pair twice without delay it will fail. If you call pair (success or not) and then wait for about few seconds (2-3) then call pair again - it works. Probably, MS stack is not released yet and needs sometime to re-init for next pair.

P.S. Have never seen such problem on XP.
Title: Re: wclBluetoothDevice Pair request lock
Post by: ppaquin on February 13, 2013, 03:32:34 PM
Hi,

I'm on Seven 64bit pro. Maybe it's special on seven...
Title: Re: wclBluetoothDevice Pair request lock
Post by: Mike Petrichenko on February 13, 2013, 04:24:28 PM
Yes, that appears only on Win 7. Looks better on Win 8.
Title: Re: wclBluetoothDevice Pair request lock
Post by: Mike Petrichenko on February 13, 2013, 10:51:45 PM
Hi,

Updated version (attached). Works much better. wclBluetoothDevice.Pair method has been reworked: now it takes PIN as a parameter and does not fire events (all events have been removed from wclBluetoothDevice class). The Pair method trys to pair with device with given PIN. If a target device supports BT 2.1 SSP authentication, the Pair method automatically accepts numeric/passkey comparison. If a target device requires legacy PIN authentication then the Pair method trys to pair with given PIN.

[attachment deleted by admin]
Title: Re: wclBluetoothDevice Pair request lock
Post by: ppaquin on February 14, 2013, 09:06:52 AM
Hi,

previous version seems to work better to me. Now i get a "Access Denied" message when i want to pair my device (still with DiscoveryDemo app)... Pairing still work with Window classic dialog.

Reguards,
Title: Re: wclBluetoothDevice Pair request lock
Post by: Mike Petrichenko on February 14, 2013, 09:38:34 AM
Its good news that it gives that error. It means that now function works correctly but the device rejects pairing. It may be because WCL sends wrong PIN or something.
what is your target device you try connect to? And what is PIN it needs?
Title: Re: wclBluetoothDevice Pair request lock
Post by: ppaquin on February 14, 2013, 09:51:10 AM
The device is actually a custom Bluetooth card of my society. The pin is actually 19980000.
Title: Re: wclBluetoothDevice Pair request lock
Post by: Mike Petrichenko on February 14, 2013, 10:16:59 AM
Ok, thanks.

By the way, what do you want to do after pairing? If you want to connect to your device may be its better to use wclAuthenticator and handle authentication requests asynchronous during connecting instead if force pairing before connect?
Title: Re: wclBluetoothDevice Pair request lock
Post by: ppaquin on February 14, 2013, 10:24:33 AM
True, i want to send some instruction with wclClient.write (i have some trouble here too). I'll have to receive instructions too. What's the best way to do that?

I have difficulties to find documentation over WCL, can you tell me where to find it? (some tuto or API doc as exemple?) Actually, i base my developpements over demos provided in the installation of WCL.

For explanation, we used 32Feet library before, but for some compatibility problem, we're trying to migrate to WCL our app. (we'll see for buying after, if all work of course)

Many thanks,

Title: Re: wclBluetoothDevice Pair request lock
Post by: ppaquin on February 14, 2013, 12:50:14 PM
Ok Wonderfull,

This new version work very good... if i launch it in administrator rights. I had to generate the demo with visual studio then launch it with right clic and admin rights... That'll be hard to debug! But that's Microsoft fail :p.

Many thanks for your reactivity. In this new version, i can pair and unpair any time it works (in admin right).

For my last question (i hope) can you explain or show me some doc for use wclClient.Write? Actually, it sais "Device not connected", but it does! (I paired and use wclClient.connect before successfull). We even have some sound on our card for when i disconnect, and it rings when i stop the app, so i am well connected when this message prompt...

Thanks!
Title: Re: wclBluetoothDevice Pair request lock
Post by: Mike Petrichenko on February 14, 2013, 01:53:10 PM
That's great that it works! I have never thought that pairing can fail because of rigts (at least there is nothing in MS doncs for that).

wclClient is simple. First, take a look on BluetoothClientDemo. It shows how to use it for SPP connection. In few words:

1. Set wclClient Params (Transport, Radio, Address, Service)
2. Call Connect and if it is success wait for OnConnect event (e.Error indicates connection result. If it is WCL_E_SUCCESS then connection is established)
3. Then you can call Write (it takes buffer as parameter (buffer is simple bytes array)).
4. Received data will be passed in OnData event.
5. To disconnect call Disconnect method
6. When wclClient is disconnected OnDisconnect event fires (if you call Disconnect or if remote device forces disconnection).
Title: Re: wclBluetoothDevice Pair request lock
Post by: Mike Petrichenko on February 14, 2013, 02:29:14 PM
A little bit updated version (attached): added synchronization for Pair calls to prevent shared data corruption when trying to pair in threads.

[attachment deleted by admin]
Title: Re: wclBluetoothDevice Pair request lock
Post by: ppaquin on February 14, 2013, 02:37:25 PM
Thanks for this new version, i'll check that.

For the connection, here's the point :

The following code goes to a never-ending loop
            wcl.wclErrors.wclShowError(wclClient.Connect());
            while (wclClient.State != wclClientState.csConnected)
            {
                Thread.Sleep(1000);
            }

But, if i stop there the method, and put some action (write....) int the "wclClient_OnConnect" method, that's working. It seems that the client wait for the current thread to end to realy connect.

I'll try to use as it, but if you've got some indications, i'll be glad!
Title: Re: wclBluetoothDevice Pair request lock
Post by: Mike Petrichenko on February 14, 2013, 02:40:31 PM
WCL is asynchronous library and you have to use events instead of waiting for state changes. Also it is recomended to use WCL in main thread (as it is async it doesn't block main thread).

However, if you need synchronous call then change you code as below:

while (wclClient.State != wclClientState.csConnected)
            {
                Application.DoEvents();
               Thread.Sleep(50);
            }


But it is not recomended way to use WCL.
Title: Re: wclBluetoothDevice Pair request lock
Post by: ppaquin on February 14, 2013, 02:55:34 PM
Thanks!
Title: Re: wclBluetoothDevice Pair request lock
Post by: Mike Petrichenko on February 14, 2013, 05:46:09 PM
You are very welcome!

And thank you for found bug in Pairing methods! if you decide to purchase WCL I would like to offer you a 10% discount (20% if you would like to use PayPal).
Title: Re: wclBluetoothDevice Pair request lock
Post by: ppaquin on February 15, 2013, 09:12:51 AM
Many thanks for offer!
Title: Re: wclBluetoothDevice Pair request lock
Post by: Mike Petrichenko on February 22, 2013, 10:02:02 AM
Updated version. One more possible issue (pairing) has been fixed.

[attachment deleted by admin]
Title: Re: wclBluetoothDevice Pair request lock
Post by: Mike Petrichenko on February 22, 2013, 03:44:14 PM
The version with all fixes has been published today. You can download it from http://www.btframework.com/download.htm