Android Question Convert EditText to hex

Discussion in 'Android Questions' started by TMEA, Apr 21, 2015.

  1. TMEA

    TMEA New Member

    Hello.
    I'm Thomas and I'm new user this forum. I have problem with transmision data via bluetooth. I have connect bluetooth module with MSP430 and tablet. I use :

    Dim Strumien As AsyncStreams
    Strumien.Initialize(Adapter.InputStream, Adapter.OutputStream, "Strumien")
    MyReceiveData=BytesToString(Buffer, 0, Buffer.Length, "UTF8")

    x=EditText1.Text ' adr1 device
    Strumien.Write(x.GetBytes("UTF8"))

    my msp430 have instruction if(buffer=80) then instructions}
    so if i write in TextEdit value 80 MSP don't work
    if I write in TextEdit value P (ASCIO 80) MSP430 working.
    I want write toTextEdit value 80 because i must sending dex values not strings.

    best regards
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Please use [code]code here...[/code] tags when posting code.

    Write 80 in the EditText and then send it with:
    Code:
    Strumien.Write (Array As Byte(EditText.Text))
     
    TMEA likes this.
  3. Straker

    Straker Active Member Licensed User

    Probably you need to send bytes
    Try this:
    Code:
    EditText.Text="80"
    dim b(1as byte
    b(
    0)= EditText.text 'vba should convert "80" in the number 80 (aka ASCII P)
    'now b(0) contains the number 80, as a single byte
    strumien.Write2(b,0,1'write a single byte
    I think the Erel's solution is not working. If you convert "80" in in a byte array I suppose that it will create a 2 bytes array with ascii 56 and 48 ("8" + "0")
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    [​IMG]

    My solution is correct.


    Array As Byte(x) creates an array of bytes with a single element. As x expected to be a byte, the compiler will automatically add code that parse EditText.Text as number.
     
    Peter Simpson likes this.
  5. Straker

    Straker Active Member Licensed User

    Thank you Erel, you are correct (as always).
    I didn't thought that there was an implicit conversion.
     
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