This project has moved. For the latest updates, please go here.

Odd behavior with DiscoverDevicesInRange()

Topics: Bluetooth - Microsoft
Jan 16, 2012 at 4:21 PM

Hello,

I've been working on a Windows Forms application that uses 32Feet.NET to get the list of Bluetooth devices in range. It's behaving strangely, though. Unless I call DiscoverDevicesInRange() in Program.cs, before calling Application.Run(new ScannerForm()), DiscoverDevicesInRange() doesn't work once ScannerForm starts.

 

    static class Program
    {
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            // Unless we do this, scanning doesn't work once we've started the Application
            BluetoothClient client = new BluetoothClient();
            client.DiscoverDevicesInRange();
            client.Close();

            Application.Run(new ScannerForm());
        }
    }

Later calls to DiscoverDevicesInRange() return an empty list, even when I have my phone's Bluetooth enabled and in discoverable mode. I must be missing something obvious, and I'd be grateful if someone could point it out. I'm using Visual Studio 2010 on 32-bit Windows 7.

 

Also, thanks for such a great Bluetooth library! 32feet.NET has been an invaluable part of my .NET projects, and I don't know where I'd be without it.

Thanks,

Darren

Developer
Jan 18, 2012 at 9:15 AM
Edited Jan 18, 2012 at 9:23 AM

Presumably you mean just client.DiscoverDevices(); There's no DiscoverDevicesInRange method.  Sorry I'm talking complete nonsense!!!  Of course that method exists.

On Windows we need to use the events API to find the devices in range, see http://32feetnetdev.wordpress.com/2010/11/15/device-discovery-improvements-on-msftwin32/  This starts its own window message loop.  I guess that can be getting confused with your own UI.  I've never seen any problems here however...

 

What platform is this on desktop or Windows Mobile?  Which stack?  What does BluetoothRadio.PrimaryRadio.SoftwareManufacturer say?

Is there any Bluetooth code in the form constructor/Load/Show methods?