Android Question Receiving Bytes of data between 0 and 255

Discussion in 'Android Questions' started by Danki_87, May 3, 2015.

  1. Danki_87

    Danki_87 New Member Licensed User

    Hi everyone!

    I'm having some problems receiving bytes of data over bluetooth.
    The project I'm trying to make is a bluetooth oscilloscope. I have a microcontroller that samples the signal, and then it sends it as a single byte to my android device using a TTL to bluetooth adapter. Then I want to display the signal on the screen.

    I'm sucked now in the communications. The android device receives the data as a character, then I tried to use the ByteConverter library to interpret the character:

    Dim bc As ByteConverter
    Dim Data(1) As Char
    Dim Number(1) As Byte

    Data(0) = TextReader1.ReadLine
    Number = bc.CharsToBytes(Data)

    When I receive a number between 0 and 127, this code works just fine. However, when I receive a larger number it just returns -3.

    I'd appreciate any help in other ways to change from chars to bytes.
     
    Last edited: May 3, 2015
  2. NJDude

    NJDude Expert Licensed User

    That is correct because of the BYTE limits, see more HERE, even more info HERE
     
  3. Erel

    Erel Administrator Staff Member Licensed User

    B4A (and Java) use signed bytes. The data you receive is correct. 253 is converted to -3 (256 - n).
     
    thedesolatesoul and Danki_87 like this.
  4. Danki_87

    Danki_87 New Member Licensed User

    Thanks, It's good to know I'm on the right way. I supose I can sacrifice a little bit of resolution and work with data from 0 to 127.

    However, Is there any other way to obtain the numerical information of a character sent oover the serial port? (other than using the byte converter library)
     
  5. Beja

    Beja Expert Licensed User

    Maybe I am not following.. but as far as I understand from what you wrote I was expecting to define the data array as string, not char.. or even just use one string variable to hold the incoming data. this way you end up with a string-represented byte, 7F for example.. then convert this value to a true Hex byte.
     
  6. Erel

    Erel Administrator Staff Member Licensed User

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