Android Question Bluetooth

Discussion in 'Android Questions' started by Cenny, Jun 10, 2015.

  1. Cenny

    Cenny Member Licensed User

    Hi,

    Can somebody help me solving my next problem:
    I want to receive a stream of 260 8 bits values in the range from 0-255 from some device via bluetooth.
    Bluetooth is expecting the incoming stream to be of type byte (-128 to 127)
    I was told to use the Byteconverter library, but I have no idea how.

    Cenny
     
  2. derez

    derez Expert Licensed User

    Code:
    Dim bc As ByteConverter
    Sbuffer = bc.StringToBytes( data_string ,
    "UTF8"
    AStream.Write(Sbuffer)
    and back:
    Code:
    Dim st As String
    st = 
    BytesToString(buffer, 0, buffer.Length, "UTF8")
     
    Erel likes this.
  3. Erel

    Erel Administrator Staff Member Licensed User

    Note that you can also convert a string to bytes with:
    Code:
    buffer = data_string.GetBytes("UTF8"'this is also possible: "some text".GetBytes("UTF8")
     
  4. Cenny

    Cenny Member Licensed User

    Thanks for your reaction, but this is all about strings.
    Is there something for numbers as wel?
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    Code:
    AStream.Write(Array As Byte(1,22502000xEA)) 'it will work correctly
     
  6. Cenny

    Cenny Member Licensed User

    Thank you Erel.
     
Loading...