.NET Components for Mobility

Discover Devices problem solved

Last post 04-08-2009 1:49 PM by alanjmcf. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 01-19-2009 5:43 PM

    • amidar
    • Not Ranked
    • Joined on 01-19-2009
    • Krusevac,Serbia
    • Posts 1

    Idea [I] Discover Devices problem solved

    Let's see where is (still) the problem.
    If You paired Your mobile device with some other bluetooth device, then it does not matter if You say false to DiscoveryFlags this way :

    Dim flags As New DiscoveryFlags(False, False, True)

    it will not work despite the fact that You just said False both to the authenticated and remembered parameters.
    Because You alredy paired Your device with some other, there is registry entry for that  and when those two parameters are set to False, at the end of the DiscoveryFlags function, known paired devices are deleted from the list of the discovered devices !!! Here is the code :

    ...

                    //enumerate the keys
                    foreach (string devid in devkey.GetSubKeyNames())
                    {   
                        BluetoothAddress address;

                        if (BluetoothAddress.TryParse(devid, out address))
                        {
                                //get friendly name
                                RegistryKey thisdevkey = devkey.OpenSubKey(devid);
                                string name = thisdevkey.GetValue("name", "").ToString();
                                uint classOfDevice = Convert.ToUInt32(thisdevkey.GetValue("class", 0));
                                thisdevkey.Close();

                                //add to collection
                                BluetoothDeviceInfo thisdevice = new BluetoothDeviceInfo(address, name, classOfDevice, true);

                                int devindex = al.IndexOf(thisdevice);

                                if (devindex == -1)
                                {
                                    //if we intended to search for authenticated devices add this one to the collection
                                    if (addFromRegistry)
                                    {
                                        al.Add(thisdevice);
                                    }
                                }
                                else
                                {
                                    if (addFromRegistry)
                                    {
                                        //set authenticated flag on existing discovered device
                                        ((BluetoothDeviceInfo)al[devindex]).Authenticated = true;
                                    }
                                    else
                                    {

    -----> Here is the problem !!!!

                                        //we want to exclude already authenticated devices so remove it from the collection
                                        al.RemoveAt(devindex);

                                    }
                                }
                            }
                        }

    ...

    So, i added the fourth parameter into the DiscoveryFlags function. Parameter name is noreg ! :)
    So, now when You want to see available devices and You do not want anything from the registry, just say True !

    I uploaded modified InTheHand.Net.Personal.CF2 sources and also a simple test project.

    http://rapidshare.de/files/42599377/BT_SDP.rar.html

    These are only for the testing purposes.
    This solution must be incorporated into the main project.

    Regards,
    Miodrag Jevremovic

  • 01-20-2009 10:51 AM In reply to

    Re: Discover Devices problem solved

    Good work!  Curiously I've been making the same change.  It's currently in the Widcomm branch and for the Widcomm discovery process only, but I mean to implement it for the WM/CE+MSFT stack soon.

    I've created a DiscoverDevicesMerge method that contains that code, and like you, adds a fourth boolean which I called "discoverableOnly".  Have a look at see if it matches your change.  (BluetoothClient.cs in the InTheHand.Net.Personal_Widcomm branch).

    Of course, since Win32 returns the devices *already merged* there's no way to do that there, and thus no way to "get devices in range (and discoverable mode) only". :-(

    Alan J. McFarlane
    http://www.alanjmcf.me.uk/
    Please follow-up in the newsgroup for the benefit of all.
    Have I helped? Consider visiting my Amazon wishlist, see my homepage.
  • 04-07-2009 12:57 AM In reply to

    Re: Discover Devices problem solved

    Hi,

    I am new with bluetooth programming. I am using the latest release 32feet.NET 2.3 with Windows XP sp3 and VS.NET 2005.

    I have some questions about the discover nearby bluetooth device(s) using 32feet.NET 2.3.

    - I had 5 cell phones with bluetooth turn on and set the visibility to "show to all", when my application call the function DiscoverDevices, the number of bluetooth device detected is different, sometimes 3 sometimes 5, etc. Is it correct behaviour of the bluetooth device or it is a bug in my app or bug in the library?

    - I also found the same problem that the returned bluetooth devices list still show authenticated bluetooth device even it have been turn off. I also tried to have the parametes authenticated and remembered set to false when call funciton DiscoverDevices (i.e. DiscoverDevices(999, false, false, true)). BTW, what is the default value of max devices, authenticated, remembered and unknown if I didn't pass any parameter to the function DiscoverDevices?

    - Refer to the information about the service of "ClassofDevice", if ObjectTransfer is available in the list of services of the selected bluetooth device, is it mean it is true that the selected device support file transfer thru bluetooth? I ask this question because I found out that the bluetooth device of Blackberry detected also have the service property ObjectTransfer is available, whenever the application try to send file, it always return failed. But it is okay for pairing the bluetooth device.

     Following is the my code:

                    BluetoothDeviceInfo[ ] devicesInfo = null;
                    BluetoothClient BTClients = new BluetoothClient();
                   

                    // try to set inquiry length time longer to search more nearby devices
                    BTClients.InquiryLength = TimeSpan.FromSeconds(30);
                    devicesInfo = BTClients.DiscoverDevices(999, false, false, true);

                    for (int i = 0; i < devicesInfo.Length; i++)
                    {
                        int iTries = 0;
                        while ((devicesInfo [ i ] ).DeviceName.Replace(":", "").Equals((devicesInfo [ i ] ).DeviceAddress.ToString()))                   
                        {
                            // Try to resolve device MAC address to device name;
                            devicesInfo [ i ].Refresh();
                            if (++iTries > 5) break;
                            Thread.Sleep(500);                 
                        }
                        lbxDeviceList.Items.Add(devicesInfo [ i ] .DeviceName + " " +
                                                devicesInfo [ i ] .DeviceAddress + "  " +
                                                devicesInfo [ i ] .ClassOfDevice.Service.ToString());                

    I appreciated if some one can help me out.

    Thanks in advance.

    Kalvin

     

  • 04-07-2009 12:26 PM In reply to

    Re: Discover Devices problem solved

    Your three(?) questions: 

    1. If you change the "InquiryLength" that seems to happen.  I'm not so expert in Bluetooth that I can explain exactly why. :-(

    2. The MSFT stack on desktop Windows is not good in that area. :-(  There seems no way to say "*only* devices in range" please.  It always returns them with remembered devices; or with "unknown"=true, only devices that are in range, but *not* remembered. :-(

    3. One would think so.  Are you using OBEX Push or OBEX File Transfer (FTP)?  The ClassOfDevice flag should indicate whether the former is supported, but not necessarily the latter, in my opinion.  One can use SDP (Service Discovery Protocol) to see what services a device supports, use the SdpBrowser sample app and use the <All Services over L2Cap> button (followed by the <Name & Channel of> button for simplicity).

    Alan J. McFarlane
    http://www.alanjmcf.me.uk/
    Please follow-up in the newsgroup for the benefit of all.
    Have I helped? Consider visiting my Amazon wishlist, see my homepage.
  • 04-08-2009 4:44 AM In reply to

    Re: Discover Devices problem solved

    Dear Alan,

    I used the ObexWebRequest class for transferring file(s) from Local PC to bluetooth device. I am not sure is ObexWebRequest use the method for OBEX push or OBEX File transfer.

    Please kindly advice is it true that we can use either Obex push or Obex file transfer for transfer file thru bluetooth?

    Anyway, thank you very much for replied my questions.

    Kalvin


  • 04-08-2009 1:49 PM In reply to

    Re: Discover Devices problem solved

    Maybe you need to manually enable the OBEX (push) service on the Blackberry?

     If you can try the test with the SdpBrowser app, how many services does it list?

    Alan J. McFarlane
    http://www.alanjmcf.me.uk/
    Please follow-up in the newsgroup for the benefit of all.
    Have I helped? Consider visiting my Amazon wishlist, see my homepage.
Page 1 of 1 (6 items)
Copyright © 2001-2010 In The Hand Ltd. All rights reserved. Terms of Use and Privacy Policy.