B4J Question Byte array to text

atiaust

Active Member
Licensed User
Longtime 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 ?
 

Attachments

  • snip_20190407181500.png
    snip_20190407181500.png
    49.4 KB · Views: 177

atiaust

Active Member
Licensed User
Longtime User
B4X:
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(4) As 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
 
Upvote 0

atiaust

Active Member
Licensed User
Longtime 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
 
Upvote 0
Top