I use AsyncStreams in non-prefix mode for receiving bluetooth messages
(HC 05, controlled by a STM32). The messages end on chr(13), only then they are
complete. I observe that the messages are transmitted over bluetooth in pieces,
so I use a global buffer (aStrHlp). This buffer is filled as long as no chr(13) is received,
then the complete message is merged :
strNewData = aStrHlp & BytesToString(Buffer, 0, len, "UTF8")
and aStrHlp is cleared. For short messages (about 100 ... 150 byte) I can observe in the log
how everything works.
But there are also longer messages with about 1600 bytes.
I can control this kind of messages in a terminal program (HTerm) and see the
correct end with chr(13).
In AStream_NewData (Buffer() As Byte) it does not work.
The buildup of aStrHlp is slow (??) and the complete message seems to have the double
length as expected. In release mode it does not run correctly either.
private Sub AStream_NewData (Buffer() As Byte)
Private aStr As String
Private strNewData As String
Private len As Int = Buffer.Length
If Buffer(Buffer.Length - 1) = 13 Then
len = len - 1
strNewData = aStrHlp & BytesToString(Buffer, 0, len, "UTF8")
Log("new_data : " & strNewData)
aStrHlp = ""
For Each Target In Array(Main, EM_SerialBT_Test, EM_Scan2, EM_Frequency, EM_OffsetGain)
CallSub2(Target, "UG12Message", strNewData)
Next
Else
aStr = BytesToString(Buffer, 0, len, "UTF8")
aStrHlp = aStrHlp & aStr
Log("new_data strHlp: " & aStrHlp)
End If
End Sub
It seems that chr(13) is not / not always recognized.
Once again : in a terminal program I see the long message practically "immediately" and also chr(13) is present at the end.
I am grateful for any advice