Hello, with the function AsyncStream, I can send and receive data from a device. The data is sent correctly, but SOMETIMES, the response of the device, is cut off, that is, the answer is a bit slow and is cut into two parts, so I can see only the second part. Is possible to put a delay or something like that at the time of receipt of the buffer?
Excuse me, but I don't understand how to append 2 or more packets received from astreams.
I need to receive a string of bytes with 34 characters like this:
01030CAE0500320000C80500320000D84C (D84C is the calculated checksum of the string so, I can't know wich is the last character of the string because it changes every time)
Sometimes I receive
030CAE0500320000C805003200
or
01030CAE05003
Is only a part of string. The astreams (or socket) is too fast and it receive only a part of the data I need.
I've tried that code but don't work..
B4X:
Dim bytes As String
bytes = Converter.HexFromBytes(Buffer)
Dim sr As StringBuilder
sr.Initialize
sr.Append(bytes).Append(CRLF).Append(bytes)
EditText1.Text = sr
I've tried with list.addall but without success, here is my code (without list.addall)
B4X:
Sub AStreams_NewData (Buffer() As Byte) 'in questa sub devo dire cosa fare con i dati che MI ARRIVANO dallo strumento
If Buffer.Length > 0 Then 'i dati vengono scritti dentro a Buffer() ora indico (a scopo di debug) se il buffer è vuoto oppure c'è qualcosa
ToastMessageShow("ok", False)
Else
ToastMessageShow("no", False)
End If
Dim bytes As String
bytes = Converter.HexFromBytes(Buffer)
EditText1.Text = bytes
End Sub
And as I said that code don't work....
Can I set (Buffer() As Word) or (Buffer() As DWord) or something else for try? Or I'm on a wrong road?
Sub AStreams_NewData (Buffer() As Byte) 'in questa sub devo dire cosa fare con i dati che MI ARRIVANO dallo strumento
If Buffer.Length > 0 Then 'i dati vengono scritti dentro a Buffer() ora indico (a scopo di debug) se il buffer è vuoto oppure c'è qualcosa
ToastMessageShow("ok", False)
Else
ToastMessageShow("no", False)
End If
Dim lista As List
lista.Initialize
lista.AddAll(Buffer)
EditText1.Text = lista
End Sub
Can I use the FOR cycle? For example: "FOR EACH ITEMS IN BUFFER LISTA.ADDALL(BUFFER) or something similar, but I know how to write it