Decode

Hello,
i linked an arduino and a fezpanda2 by UART. But when i send for exemple 20, fez receive 48. So i saw that the message is cut in chars or something else.
Can you help me to convert to recover 20.
thx.

Show us your code, please.


byte[] recu_data = new byte[1];
bool recue = false;

 while (recue == false)
                {
                    read_count = Sender.Read(recu_data, 0, 1);
                    if (read_count > 0)
                    {
                       
                        recue = true;
                    }
                }


 Debug.Print(recu_data[0].ToString());


try…

Debug.Print(new string(Encoding.UTF8.GetChars(recu_data[0], 0, 1);

You are probably sending 20 as a string. 48 is decimal value of the ascii character ‘0’. So you probably receiving 50 and 48.

1 Like

i can’ write

 Debug.Print(new string(Encoding.UTF8.GetChars(recu_data[0], 0, 1);

there are an error. But when i write :


Debug.print(Encoding.UTF8.GetChars(recu_data).ToString();)

it print : System.Char[]

yes,i saw that i receive 2 different values : 48 and 50. How can i convert them and assemble them ?
Because i receive the second value, just if i do a second read of the message.

My bad. That was quick & dirty… Try it like this.

Debug.Print(new string(Encoding.UTF8.GetChars(recu_data, 0, 1);

no, i have an error

Debug.Print(new string(Encoding.UTF8.GetChars(recu_data, 0, read_count);
1 Like

Finally i succeeded,

fez code :


String part1 = recu_data[0].ToString();
Debug.print(par1);

but i used an other method to send message in arduino.

 Serial.write(20);

Before i used

Serial.print(20);

and it send String. But the “Serial.write” send a single byte.

Thanks for help :wink:

Excellent. I figured all you needed was to know about the Encoding library and you’d figure it out :wink: