The problem STRING.CharAt (i) with more than 128 characters
For all values of greater than 128 returns -3
For all values of greater than 128 returns -3
My mistake, CharAt does indeed return a Char data type and not a Byte as I first assumed.String.CharAt() returns a char type, not a byte type. In Java, the char type is 16 bits wide and can range from 0 to ~65k. It is used to store a 16-bit Unicode character reference, so it should be able to easily accommodate your ASCII codes. Can you show some sample code and a String that produces this behavior?
Dim SB As StringBuilder
SB.Initialize
For i = 0 To 255
SB.Append(Chr(Rnd(65,99)))
Next
Dim s As String = SB.ToString
Log(s)
For i = 0 To s.Length - 1
Log(i & ": " & s.CharAt(i))
Next
Without knowing where your AsyncStream is getting its data, I can only make some guesses. It might be that your data source only sends data in frames of 128 bytes. If you know your data is going to be interpreted as text, you might be better off using the AsyncStreamsText class. It collects frames of raw bytes until it reads a newline character and then raises the _NewText(Text as String) event. This allows you not to bother with collecting byte buffers and turning them into text and just deal with the text directly, as a String.
Also, are you sure ASCII is a supported character set? I seem to recall ASCII was deprecated a while ago and it is now considered a subset of UTF-8.
Furthermore, I'm not sure what the mapping is between UTF-8/ASCII and UTF-16 is but I know Java stores Strings internally as UTF-16 (that's why char is 16-bit). Even though you specified that BytesToString use ASCII, the resulting String s will still be represented in UTF-16. So when you call Asc(c), this value (which is of int type) could easily overflow the limits of the byte type. Like Random said, if you just need the bytes, you should just work with them directly. If you need Strings, you should use the AsyncStreamsText class.