Click here to Skip to main content
15,919,028 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hai guys,

Please help me to sort out this issue. I wan to read from COM7 port. I tried every means to grab the values. What i am expecting from serial port is

"0A 0D AE E6 D6 6F D7 0F 0B 9B BF E2 41 A3 3A CF 67 CB D7 EE 6F 58 8B DB 7D 79 BE 6C 69 FE F3 B0 8D DD"

But i am getting the following value:

"x10 x13 x10 x13 x63 x63 x10 x13 x63 x63 x63 x111 x10 x13 x63 x63 x63 x111 x63 x15"

The code i am using is :
C#
String Rxstring="";
char[] result = new char[1];
     for (int len = 0; len < result.Length; )
        len += serialPort1.Read(result, len, result.Length - len);
     foreach (char c in result)
        RxString += String.Format("x{0}", Convert.ToUInt16(c).ToString()) + "    ";

I am writing 1 byte of data to COM port using a device(arduino uno). i changed the baud rate but no change in the data. is It the problem of conversion(Convert.ToUint16). Hot to convert it into HEX value.

Please help me guys.

additional information copied from non solution below (it came after solution 1)
Thanks my friend, I edited my code as you mentioned, again the problem exist. Now i am getting values as:

"0A 0D 3F 3F 3F 6F 3F 0F 1B 3F 3F 3F 41 3F 3A 3F 67 3F 3F 3F 6F 58 0B 3F 7D 79 3F 6C 69 3F 3F 3F 3F 3F"

Why i am getting "3F" most times and its ASCII equivalent is "?" ?.Some data matches exactly.But...

I am writing 1 byte of data to COM port using a device(arduino uno). I have changed the baud rate but no change in the data received . is It the problem of conversion(Convert.ToUint16) or does c# cannot recognize the character or problem with visual studio encoding.
Posted
Updated 4-Apr-14 23:36pm
v2

You're simply not formatting the value correctly; "x{0}" should be "{0:X2}" and remove the ToString.


And that's some seriously strange code that probably needs a lot more help.
 
Share this answer
 
v3
Comments
Nelek 5-Apr-14 5:37am    
OP posted a non solution to speak with you and ask more, I have updated the question to add the content there
PIEBALDconsult 5-Apr-14 11:43am    
Thanks.
Thanks my friend, I edited my code as you mentioned, again the problem exist. Now i am getting values as:

"0A 0D 3F 3F 3F 6F 3F 0F 1B 3F 3F 3F 41 3F 3A 3F 67 3F 3F 3F 6F 58 0B 3F 7D 79 3F 6C 69 3F 3F 3F 3F 3F"

Why i am getting "3F" most times and its ASCII equivalent is "?" ?.Some data matches exactly.But...

I am writing 1 byte of data to COM port using a device(arduino uno). I have changed the baud rate but no change in the data received . is It the problem of conversion(Convert.ToUint16) or does c# cannot recognize the character or problem with visual studio encoding.
 
Share this answer
 
Comments
Nelek 5-Apr-14 5:35am    
Please don't post solutions to chat with people asking or answering. The messages are not always sorted by date, so it can be a bit difficult to follow them correctly.
The best option is to use the "Have a question or comment?" (or the tiny "reply" on another comment). Another advantage is, that the person you write to will get a notification, otherwise it could be that he/she doesn't see your additional message.

If you need to add or change content to your question or a previous solution, please use the "improve question / solution" instead of writing a lot of messages. It will keep readability and help other users with similar problems to find it faster.
PIEBALDconsult 7-Apr-14 0:34am    
What does your code look like now?

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