B4J Question Byte array to text

Discussion in 'B4J Questions' started by atiaust, Apr 7, 2019.

  1. atiaust

    atiaust Active Member Licensed User

    Hi All,

    I have a byte array data that I am sending from B4R to B4J.

    When I convert part of the byte array to a float it gives the correct value in the logs.

    When I try to convert the float to text to display on a label I get various symbols instead of the text.

    Please see the label marked Ozone on attached image.

    Any ideas ?
     

    Attached Files:

  2. Erel

    Erel Administrator Staff Member Licensed User

    Please post the relevant code as text.
     
  3. atiaust

    atiaust Active Member Licensed User

    Code:
    Sub astream_NewData (Buffer() As Byte)
        
    Log(BytesToString(Buffer, 0, Buffer.Length, "utf8"))
    '    for testing
        Dim bc As ByteConverter
        bc.LittleEndian = 
    True
        
    Dim a As String = bc.HexFromBytes(Buffer)
        
    Log("a = "&a&" len = "&Buffer.Length)
    '   
        Dim s(4As Byte
        bc.ArrayCopy(Buffer,
    6,s,0,4)
        
    Dim d() As Float = bc.FloatsFromBytes(s)
        
    Dim str As String = d(0)
        
    Dim dbl As Double = d(0)
        
    Log("d = "&d(0))
        
    Log("str = "&str)
        
    Log ("ppm = "& str.SubString2(0,5))
        
    Log ("dbl = "NumberFormat(dbl,0,3))
        lblPPM.Text = str.SubString2(
    0,5)           - displays symbols instead of text
    Thanks
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    Something is missing here. You are probably setting the label text in another place.
     
  5. atiaust

    atiaust Active Member Licensed User

    Thanks Erel,

    I had copied a block of code from another app and there was a reference to the label.

    Fixed.. Need to look closer
     
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