I have a piece of hardware which sends data via bluetooth. I'm trying to read them, but the info doesn't correspond to the original data.
I'm using ReadByte to receive the data which are sent one by one.
int i1 = 0;
byte[] datum = new byte[6144];
while (i1 < 6144)
{
datum[i1] = await Task.Run(() => (byte)InmStream.ReadByte());
i1++;
}
string string_ascii = (System.Text.Encoding.ASCII.GetString(datum));
string string_bit = BitConverter.ToString(datum);
string string_base64 = Convert.ToBase64String(datum);
Results:
If I display the elements from the strings created, I get:
string_ascii[0] and [3] = 3 and 3 ([1] and [2] are \r & \n)
string_bit[0] and [3] = 3 and 0 ([1] and [2] are \r & \n)
string_base64[0] and [3] = M and K ([1] and [2] are \r & \n)
Should be always: 3 and 35 (Data format sent from hardware: integer\r\n)
Obsviously if I try to convert the same elements to integers, the results won't be what I need.
ascii[i] = (int)Char.GetNumericValue(string_ascii[i]);
bit[i] = (int)Char.GetNumericValue(string_bit[i]);
base64[i] = (int)Char.GetNumericValue(string_base64[i]);
I get:
ascii[0] and [3] = 3 and 3
bit[0] and [3] = 3 and 0
base64[0] and [3] = -1 and -1
PS. I noticed that when there are 1 digit integers, the code works fine.
How do I fix this ? Thanks in advance.