.NET Components for Mobility

Searching Bluetooth devices in background Visual Studio C#??

Last post 11-19-2009 3:28 PM by alanjmcf. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 11-16-2009 4:30 AM

    Searching Bluetooth devices in background Visual Studio C#??

     Hello everyone,

    I wondered if somebody could help me. Im progamming in Visual Studio C# and I´d like that as soon as I execute my program it starts searching for bluetooth devices, without showing anything, in background. And when I push a button, the box with the BT devices available appear. Any suggestion?

    Thanks a lot

     

     

     

     

  • 11-17-2009 9:10 AM In reply to

    Re: Searching Bluetooth devices in background Visual Studio C#??

    You just need to run BluetoothClient.DiscoverDevices in the background (don't use selectdevicesdialog as that will require popping up the window).  There are multiple ways to run things in the background on .NET.  One is to use the class I added recently "BluetoothComponent' you can do the following, hopefully you can *read* VB :-):

        Public Sub DiscoDevicesAsync()
            Dim bco As New BluetoothComponent()
            ' Or add a VB: Sub BT_DiscoverDevicesComplete(...) HANDLES bco.DiscoverDevicesComplete
            AddHandler bco.DiscoverDevicesComplete, AddressOf HandleDiscoDevicesAsync
            bco.DiscoverDevicesAsync(255, True, True, True, False, Nothing)
        End Sub
        ///
        Private Sub HandleDiscoDevicesAsync(ByVal sender As Object, ByVal e As DiscoverDevicesEventArgs)
            If e.Cancelled Then
                Console.WriteLine("DiscoDevicesAsync cancelled.")
            ElseIf e.Error IsNot Nothing Then
                Console.WriteLine("DiscoDevicesAsync error: {0}.", e.Error.Message)
            Else
                Console.WriteLine("DiscoDevicesAsync found {0} devices.", e.Devices.Length)
            End If
        End Sub

    Download the source file from https://32feet.svn.codeplex.com/svn/InTheHand.Net.Personal/InTheHand.Net.Personal/Net.Bluetooth/BluetoothComponent.cs and add it to your own project.  (The next release of the library will have it built-in).

    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.
  • 11-19-2009 8:55 AM In reply to

    Re: Searching Bluetooth devices in background Visual Studio C#??

    Hello,

    I was also looking for such functionality. I took the .cs file you reference but upon compilation receive messages:

     C:\vsteam\BioFoundation\Main\Source\BioBase\Shared Code\cmtbtobex\BluetoothComponent.cs(116,19): error CS0117: 'InTheHand.Net.Sockets.BluetoothClient' does not contain a definition for 'BeginDiscoverDevices'
    C:\vsteam\BioFoundation\Main\Source\BioBase\Shared Code\cmtbtobex\BluetoothComponent.cs(127,51): error CS0117: 'InTheHand.Net.Sockets.BluetoothClient' does not contain a definition for 'EndDiscoverDevices'

     Am using released version of InTheHand.Net.Personal.dll 2.3.0.0. Sounds like need a new released version to utilize these two new methods?

     Thank you!

    Ed Ruffing
    Software Engineer
  • 11-19-2009 3:28 PM In reply to

    Re: Searching Bluetooth devices in background Visual Studio C#??

    Either use 2.4 :-), or I've added support to that class for library version 2.3.  Download the code file again, set PRE_V2_4 as a #define or in your project, and it should work. :-)

    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 (4 items)
Copyright © 2001-2010 In The Hand Ltd. All rights reserved. Terms of Use and Privacy Policy.