Encoding in serial1.readall

Hi,
I read Serial port with DataAvailable event:

TextArea1.Text= TextArea1.Text + "Receiving: " + me.ReadAll + Chr(13)

I’m sending string “1234$” every second, it reveives fine, but when I read new line, old line breaks.
I can figure that it’s because of some encodings but I can’t fix it.
Please help :slight_smile:

You could try:

TextArea1.AppendText "Receiving: " + me.ReadAll + EndOfLine

ReadAll needs an encoding parameter. e.g. encodings.UTF8.

Christian:
I tryed with encodings.UTF8

TextArea1.Text= TextArea1.Text + "Receiving: " + me.ReadAll(Encodings.UTF8) + Chr(13)

…but those scandinavian charachters was not shown at all.
I can’t understand why it’s correct when firstime inserted to TextArea, but when read from textarea and add again, it’s messed…

What’s the code you’re using to send the characters?

It is a pic microcontroller… but i guess it’s iso-latin-1.
Thanks! :slight_smile:

TextArea1.Text= TextArea1.Text + "Receiving: " + me.ReadAll(Encodings.ISOLatin1) + Chr(13)

and…

TextArea1.AppendText "Receiving: " + me.ReadAll(Encodings.ISOLatin1) + EndOfLine

both work.
Still I don’t understand why it is correct when added firstime without encoding?

Just speculating: The first time you are appending a string of unknown encoding, the string you are appending to is empty and the empty string, if I remember correctly, always has an ASCII encoding (at least that was the case when Xojo was still REALbasic). The next time the text in TextArea1 will be UTF8-encoded so you are appending a string of unknown encoding to an UTF8-encoded string.

Is textarea always utf8? If I read using encoding isolatin1, and then place it to textarea, it’s converted to utf8? Or if I place it to string variable, is it still isolatin1 or utf8?

When you put some text into a TextArea, its encoding gets converted to UTF8. You can check for yourself when you add the line

MsgBox "TextArea1.Text is encoded as " + TextArea1.Text.Encoding.internetName

before appending the incoming text. You will see that the encoding is initially ASCII but then switches to UTF8.