.NET Components for Mobility

Sending a Data to a bluetooth receiver

Last post 10-07-2008 2:09 PM by alanjmcf. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 10-02-2008 2:38 AM

    Sending a Data to a bluetooth receiver

     Hello there.

    I am using Vb.net to build and API that will send let's say the letter "A" to a bluetooth receiver from a Smartphone.

    First of all I tried using the COM port on vb.net 2008 to send Data but that does not seem to work. it only knows COM1, 2 and 3 when I tried to use COM 8 it says , COM8 does not exist.

    Is there anyway I can use the in-the-hand API to do such thing?

    can anyone show me a piece of code on how to start on it using vb.net.

    Thank you

  • 10-03-2008 4:24 PM In reply to

    Re: Sending a Data to a bluetooth receiver

    Have a read of the user's guide included in the more recent release.  I'm not a fan of COM ports, so I always recommend using BluetoothClient instead.  So if you want to communicate with the serial-port service on the remote device do e.g.

    Dim addr As BluetoothAddress _
      = BluetoothAddress.Parse("001122334455") 'etc etc
    '
    Dim ep As New BluetoothEndPoint(addr, BluetoothService.SerialPort)
    Dim cli As New BluetoothClient
    cli.Connect(ep)
    Dim peerStream As Stream = cli.GetStream()
    peerStream.Write/Read ...

    More discussion is in that document.

    Alan

    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.
  • 10-05-2008 7:45 PM In reply to

    Re: Sending a Data to a bluetooth receiver

    Thank you for your Help.

     Here nw I can't get it to write to the bluetooth receiver, it will connect fine but whenever I get to the peerStream.WriteByte(a), it throws an exception.

    NullReferenceException.

    Is that because of the peerStream that does not get instancieted?

    here is my code so far

    -----------------------------------

    Imports InTheHand.Net
    Imports InTheHand.Net.Bluetooth
    Imports InTheHand.Net.Sockets
    Imports System.IO
    Imports System.Net.Sockets
    Imports System.Text
    Imports InTheHand.Net.Sockets.BluetoothClient
    Imports Microsoft.VisualBasic
    Public Class Form1
        Dim addr As BluetoothAddress = BluetoothAddress.Parse("00066600D722") 'etc etc
        Dim a As Byte = Asc("a")
        Dim b As Byte = Asc("b")
        Dim c As Byte = Asc("c")
        Dim ep As New BluetoothEndPoint(addr, BluetoothService.SerialPort)
        Dim cli As New BluetoothClient
        Dim peerStream As Stream

       
        ' Private Sub OpenDoor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenDoor.Click
        'Dim peerStream As Stream = cli.GetStream()
        ' a = "110001"


        'End Sub

        Private Sub RollDown_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RollDown.Click
            'Dim peerStream As Stream = cli.GetStream()
            ' b = "110010" 'b.
            peerStream.WriteByte(b)



        End Sub

        Private Sub TurnonH_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TurnonH.Click

           peerStream.WriteByte(c)
        End Sub

        Private Sub Close_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Close.Click
            cli.Close()
            Me.Dispose()
        End Sub

        Private Sub door_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles door.Click
            'Dim peerStream As Stream = cli.GetStream()
            '   a = "110001"
            '  cli.Connect(ep)
            peerStream.WriteByte(a)

        End Sub

        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

            'peerStream = New Stream(cli.GetStream())
            Try
                If cli.Available = True Then
                    cli.Connect(ep)
                    peerStream = cli.GetStream()
                Else
                    MessageBox.Show("Client not available,try again", "Error", MessageBoxButtons.OK, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

                End If

            Catch es As NullReferenceException
                MessageBox.Show("Connection to the receiver Failed")

            End Try
        End Sub

    End Class

    ------------------------

    Thanks for your hint.

     

  • 10-07-2008 2:09 PM In reply to

    Re: Sending a Data to a bluetooth receiver

    There's nothing 32feet/networking about your question now.  Just have to make sure that your code does what it should.  It seems like you've decided to do the connect at Form load, but I have no idea what the call to cli.Available is intended to do.  It returns an integer!  "The number of bytes of data received from the network and available to be read."  It just seems wrong.

    Alan

    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-2008 In The Hand Ltd. All rights reserved. Terms of Use and Privacy Policy.