Click here to Skip to main content
14,172,909 members
Rate this:
Please Sign up or sign in to vote.
See more:
I am working on a project,In which we are trying to transmitting the data from zigbee using API format.But,while getting data from serial port in software the receiving output is not same as the output getting in the xctu software.Can anyone help me in the decoding the received data.I tried to convert received data from ascii to both Big endian and small that didnot work for me.Please anyone can help me.I am sending data in frame where .Thank you so much in advance.

1.Receiving the data in ascii form like this.
2.I want to get mac address which is 64bit in string from 6th to 13th byte.
3.Converting received data to hexa.
4.Same data received in XCTU software.
7E 00 15 90 00 13 A2 00 41 54 EC 8E 5C 9F 01 23 31 32 23 31 32 23 52 23 0B

What I have tried:

text = serialPort2.ReadExisting();
byte[] LogoDataBy = ASCIIEncoding.ASCII.GetBytes(text);
string wholeframe = ByteArrayToString(LogoDataBy);
var arr = LogoDataBy.Skip(5).Take(8).ToArray();

string macaddress = ByteArrayToString(arr);
Updated 2-Jan-18 19:50pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

What you see that input string are Unicode escape sequences. So you have to un-escape them. Since we're dealing with byte arrays though and not wide characters (double byte arrays) we then convert them to ascii after the un-escaping to get the final result in a byte array. So, try something like this...
static void Main(string[] args)
   // do not use the @ literal here
   var encodedString = "~\0\u0015?\0\u0013?\0AT??\\?\u0001#12#12#R#\v";

   // create two different encodings
   var ascii = Encoding.ASCII;
   var unicode = Encoding.Unicode;

   // asciiBytes will have your MAC address in decimal
   byte[] unicodeBytes = unicode.GetBytes(encodedString);
   byte[] asciiBytes = Encoding.Convert(unicode, ascii, unicodeBytes);

   // show the MAC address in hex
Akhand Jyoti 3-Jan-18 4:44am
Thank u so much for your reply.But this answer do not give what i want.
when i am converting asciiByte to hex i am getting the same result as previous.
after conversion of whole unicode escape sequence result should look like.
7E 00 15 90 00 13 A2 00 41 54 EC 8E 5C 9F 01 23 31 32 23 31 32 23 52 23 0B

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web02 | 2.8.190524.3 | Last Updated 3 Jan 2018
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100