Click here to Skip to main content
15,894,017 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all, my name is Josev and I'm a newbie here.

I'm working to build receiver program with visual studio (C#) to receive data from my microcontroller. My PC connected to XBee via USB and read the data through COM port. The string data from microcontroller has been encrypted using aes128. But some characters can't be recognized by my PC, resulting in decrypting process failure. Here some example of my data :

real data : @A1@3.2@4.5@ (string)
data sent from my micro : »ËÌùû˜3ar€å*\
data received by my pc : ??????3ar??*\

Some characters can't be recognized and become "?"
I use ReadLine() to read COM port and catch it in string variable like this.
C#
String data = ComPort.ReadLine();

But when I check it by print it on my checkbox, some characters become "?". I took a screenshot in this link.

Please, really need help.
Posted

1 solution

Stop trying to receive it as a string, and fetch it as byte data instead: the chances are that the data from the microcontroller isn't Unocode, which the ReadLine method will assume it is.

So read it as bytes, and look at what values you are getting - and look at what the uController is supposed to be sending - chances are it isn't meant to be directly human readable...
https://msdn.microsoft.com/en-us/library/ms143549(v=vs.110).aspx[^] may help.
 
Share this answer
 
Comments
CPallini 24-Sep-15 6:19am    
5.
Member 12008308 24-Sep-15 23:37pm    
I try to use this method :

int databytes = ComPort.BytesToRead;
byte[] byte_buffer = new byte[databytes];
ComPort.Read(byte_buffer, 0, databytes);

I know it's catching something but I have no idea how to show the data inside databytes.
CPallini 25-Sep-15 3:03am    
You may, for instance, print out the hexadecimal representation of such bytes, e.g.
foreach (byte b in byte_buffer)
Console.Write(" {0:X2}", b);
Console.WriteLine();
Member 12008308 27-Sep-15 20:12pm    
It works. Thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900