B4J Question AsyncStreams and ASCII stream of data

fabton1963

Member
Licensed User
Longtime User
Hello,
I try to connect to a serial device using Serial lib and AsyncStreams.
B4X:
Sub btnOpen_Action
    
    
    sp.Open(cmbPort.Value)
    sp.SetParams(38400, 8,0,1)
    astream.Initialize(sp.GetInputStream, sp.GetOutputStream, "astream")

    btnOpen.Enabled = False

End Sub

Sub MainForm_Closed
    sp.Close
End Sub

Sub AStream_NewData (Buffer() As Byte)

    Dim i As Int   
    Dim s As String = BytesToString(Buffer, 0, Buffer.Length, "UTF-8")
    Log(s)
    For i = 0 To Buffer.Length -1   
        Log(Buffer(i) & "- "&Chr(Buffer(i)))
    Next

End Sub
The device send the following ASCII string through serial :

thi sis what I get using putty opening COM11 38400,n,8,1
{"msg":"No_Card"}
I receive the following data:

How may I convert the ASCII stream to UTf-8 for reading/writing using AsyncStreams?
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…