I'm new to C# and I built an application that receives bytes from a Serial Port and parses the bytes.
In one scenario, the application receives an array of bytes that represents a string. My idea is to convert the bytes to string ad visualise the string into a text box.
With this code:
textSerialNumber.Text = Encoding.UTF8.GetString(readData.payload, 0, readData.payload.Length);
I obtain the string but there is a problem: the first byte receive on the serial port is a 0x00 ( it represents an ack ). When i convert the payload (ack + string ) the first character is a NULL and text box assignments fails.
If I modify the code to start form the first element of the byte array:
textSerialNumber.Text = Encoding.UTF8.GetString(readData.payload, 1, readData.payload.Length);
Also in this case the text box assignment fails.
I try to skip the text box assignment:
string x = Encoding.UTF8.GetString(readData.payload, 1, readData.payload.Length);
But also int this case the encoding fails.
Any suggestion to find the error?
Thanks in advance.
string base64 = Convert.ToBase64String(readData);