Reputation: 391
I have an application that allow exchange messages and I'm trying to send a string with special characters
string my_str = "isto não está a funcionar! (pt)";
comPort1.Write(my_str);
But I receive isto n?o est? a funcionar! (pt)
.
I tried to put comPort1.Encoding = Encoding.UTF8;
before but it's not working yet. I tried diferent encodings.
Upvotes: 3
Views: 3902
Reputation: 667
If you write the encoded bytes of your string to the port, they will be sent correctly. This piece of code will do the trick for you:
string my_str = "isto não está a funcionar! (pt)";
byte[] my_bytes = System.Text.Encoding.UTF8.GetBytes(str);
comPort1.Write(my_bytes, 0, my_bytes.Length);
Upvotes: 4