I have a simple UART routine not returning the correct string. Im sending “AAABBBCCC” and can clearly see the bytes in the b array when I inspect it but when I do the …GetChars it return “~~”
private void gprs_DataReceivedEvent(object state)
{
int read, pos;
int NumberOfBytesToRead = gprs_serial.BytesToRead;
if (NumberOfBytesToRead > 0)
{
byte[] b = new byte[NumberOfBytesToRead];
read = gprs_serial.Read(b, 0, b.Length); //
string word= new String(Encoding.UTF8.GetChars(b, 0, b.Length)); //always return ~~
}
}