hi,
Now I need your help. I have the following code:
B4X:
Sub AStream2_NewData (Buffer2() As Byte)
Dim s2 As String = BytesToString(Buffer2, 0, Buffer2.Length, "UTF8")
If s2.Length > 5 Then n2 = st.Right(s2,5)
Log ("L2:" & n2)
End Sub
Sub AStream3_NewData (Buffer3() As Byte)
Dim s3 As String = BytesToString(Buffer3, 0, Buffer3.Length, "UTF8")
If s3.Length > 5 Then n3 = st.Right(s3,5)
Log ("L3:" & n3)
End Sub
Sub TC1_Tick
Dim niv As String
niv = n2 & n3
Log (niv)
niv = ""
End Sub
N2 and N3, are string format 0191 and 2345 ... so four-digit number.
Expecting string composed in the form as: 01912345
What is wrong in this code? It is always compose strings worked without problems.
Through the serial port I read two sensors for distance measurement. In the picture you can see that I get information about stream2 received information (L2, L3). I get the data every few milli seconds.
I would like to put the data in the form of 12345678, sequentially excluding L2 and L3.
and why do you check for a length of 5 when you expect a 4 digit number?
You should use AsyncStreamsText. It will take care of removing the end of line characters and only raising the event when a full message is available. https://www.b4x.com/search?query=AsyncStreamsText