Android Question Bluetooth receiving data

Discussion in 'Android Questions' started by bogdanc, Mar 13, 2015.

  1. bogdanc

    bogdanc Active Member Licensed User

    Hello:)
    That is my firs post here.
    So welcome everybody:)

    I have problem with communication via Bluetooth.

    I wrote small app on my phone. I connected to PC.
    From PC i sending via Bleutooth from Putty terminal some data.

    I have declared in Sub Globals:
    Code:
    Dim Stream As AsyncStreams
    Dim Data_receive as String
    Dim Label1 as Label
    Also I have:
    Code:
    Sub Stream_NewData (Buffer() As Byte)
    Data_receive = 
    BytesToString(Buffer, 0, Buffer.Length, "UTF8")
    Label1.Text=Data_receive

    If Data_receive.lenght=7 Then
    If Data_receive.EndsWith( Chr(13)) Then
    Try
                
    ' Do something
                Catch
                
    End Try
            
    End If
          Data_receive =
    ""
    End If
    End Sub
    I displaying on Label1 all incoming data from Bluetooth and I don't receiving all data.

    What Am I doing wrong?
     
  2. walterf25

    walterf25 Well-Known Member Licensed User

    Are you using prefix mode?
     
  3. bogdanc

    bogdanc Active Member Licensed User

    I just trying to send from PC or any my device via Bluetooth simple string value
    example: 2201100\n and I receiving random value of string.
    sometimes full(what i wanted) string and many times just part of it.
     
  4. bogdanc

    bogdanc Active Member Licensed User

    Any idea what am I doing wrong?

    How to init prefix or non prefix mode on Bluetooth AsyncStream?
     
  5. Erel

    Erel Administrator Staff Member Licensed User

  6. bogdanc

    bogdanc Active Member Licensed User


    Thank You Erel for Your respond.
    I saw this tutorial.

    I still have problem and I cant resolve it.

    Sending works fine, but receiving is not :(


    I use a non prefix mode.
    My init code:

    Code:
    Dim Adapter As Serial
      
    Sub Adapter_Connected (Flag As Boolean)
        
    'IF connected - init a Stream
        If Powodzenie=True Then
            Stream.Initialize(Adapter.InputStream, Adapter.OutputStream, 
    "Stream")
        
    End If
    End Sub




    From my app I sending to microcontroller a query via Bluetooth.
    Code:
    ?

    On Every query I send a string from microcontroller to my phone:
    Code:
    123456\r



    And on Stream_NewData I chcecikng incoming data.

    Code:
    Sub Stream_NewData (Buffer() As Byte)
    Data_receive = 
    BytesToString(Buffer, 0, Buffer.Length, "UTF8")
    Label1.Text=Data_receive

    Label2.Text=Buffer.Length

    If Data_receive.lenght=7 Then
    If Data_receive.EndsWith( Chr(13)) Then
    Try
                
    ' Do something
    i=i+1
    Label3.Text=i

                
    Catch
                
    End Try
            
    End If
          Data_receive =
    ""
    End If
    End Sub

    And every time when my Data_recive has lenght a 7 char's and ended ASCII char code 13 I increment variable i to see how many goods I revived.

    And is only 30% of goods
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    bogdanc likes this.
  8. bogdanc

    bogdanc Active Member Licensed User

    Last edited: Mar 16, 2015
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice