.NET Components for Mobility

Cannot connect to another device! Help!

Last post 11-21-2008 9:26 AM by alanjmcf. 6 replies.
Page 1 of 1 (7 items)
Sort Posts: Previous Next
  • 11-18-2008 2:03 PM

    • melilla
    • Top 50 Contributor
    • Joined on 11-18-2008
    • Republica Dominicana
    • Posts 9

    Cannot connect to another device! Help!

    Hi, im new trying with bluetooth. Im trying to use Inthehand in vb .net  2005 with a htc. I want to connect to another device, but i got an error: Null reference y the line with ****** next, here is my code, thanks for the atention.

     

        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim BlueC As New BluetoothClient
            Dim BlueI As BluetoothDeviceInfo() = BlueC.DiscoverDevices(6)

            cmbname.DataSource = BlueI
            cmbname.DisplayMember = "DeviceName"

            cmbaddress.DataSource = BlueI
            cmbaddress.DisplayMember = "DeviceAddress"

        End Sub

        Private Sub bconectar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bconectar.Click
            Dim address As New BluetoothAddress(Long.Parse(cmbaddress.Text, Globalization.NumberStyles.HexNumber))
            Dim ep As New BluetoothEndPoint(address, BluetoothService.SerialPort)
            bc.Connect(ep)                                                                            **************************************************
        End Sub                      

     

    Help me, please!

  • 11-20-2008 5:08 AM In reply to

    Re: Cannot connect to another device! Help!

    Looks as if bc is not initialised...  Change to:

       Private Sub bconectar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bconectar.Click
            Dim address As BluetoothAddress.Parse(cmbaddress.Text)
            Dim ep As New BluetoothEndPoint(address, BluetoothService.SerialPort)
            Dim bc As New BluetoothClient
            bc.Connect(ep)
        End Sub

     

    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-20-2008 7:52 AM In reply to

    • melilla
    • Top 50 Contributor
    • Joined on 11-18-2008
    • Republica Dominicana
    • Posts 9

    Re: Cannot connect to another device! Help!

    Good morning! Thanks for the reply. THAT SOLVE MY PROBLEM. I did declare the BluetoothClient but whitout the word "New". Thank you so much.

     

    Now i have another question: when i try to connect without activating first the bluetooth i have an error. I need to activate it by code. How can i do it??

  • 11-20-2008 10:45 AM In reply to

    • melilla
    • Top 50 Contributor
    • Joined on 11-18-2008
    • Republica Dominicana
    • Posts 9

    Re: Cannot connect to another device! Help!

     Now i activate and diactivate the bluetooth. But i have another problem, when i connect then disconnect and try to connect a second time, doesnt matter witch bluetoothdevice i got the error: InTheHand.Net.Sockets.BluetootClient

     

    My code for connect:

     If br.PrimaryRadio.Mode = RadioMode.PowerOff Then
                Try : br.PrimaryRadio.Mode = RadioMode.Discoverable
                Catch ex As Exception : MsgBox("No se pudo activar el bluetooth")
                End Try
            End If

            Try
                bc.Connect(ep)
            Catch ex As Exception
                MsgBox("No se ha podido conectar " & ex.Message)
                Exit Sub
            End Try
            MsgBox("Se ha conectado")

     

    My code for disconnect:

    Try
                bc.Close()
                bc.Dispose()
            Catch ex As Exception
                MsgBox("No se pudo cerrar " & ex.Message)
                Exit Sub
            End Try
            MsgBox("Se ha cerrado")

            Try : br.PrimaryRadio.Mode = RadioMode.PowerOff
            Catch ex As Exception : MsgBox("No se pudo apagar el bluetooth")
            End Try

  • 11-20-2008 11:20 AM In reply to

    Re: Cannot connect to another device! Help!

    You need a new BluetoothClient each time.  Add the initialisation of the bc just before you call Connect -- I presume at the moment you are only doing it once each time the program runs.  If that's not the problem copy the whole error here -- including the exception stack trace (e.g. FooBarException: Some Message
      at foo
      at bar)

    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-20-2008 12:42 PM In reply to

    • melilla
    • Top 50 Contributor
    • Joined on 11-18-2008
    • Republica Dominicana
    • Posts 9

    Re: Cannot connect to another device! Help!

     Perfect!!Party!!!

     I change the declaration of the client for this: 

        Dim bc As BluetoothClient

     And add bc=new BluetoothClient before connect.

    Thanks a lot!! Big Smile

     

  • 11-21-2008 9:26 AM In reply to

    Re: Cannot connect to another device! Help!

    Pleased to hear you got it working. :-)

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