How to calculate the Checksum for the RFID reader in C# | 13.56MHz RFID Module | Forum

 
You must be logged in to post Login Register


Register? | Lost Your Password?

Search Forums:


 






Minimum search word length is 4 characters – Maximum search word length is 84 characters
Wildcard Usage:
*  matches any number of characters    %  matches exactly one character

How to calculate the Checksum for the RFID reader in C#

UserPost

8:30 PM
February 6, 2012


Haz

Admin

posts 11

Post edited 8:37 PM – February 6, 2012 by Haz


This is what I did to calculate the checksum of the data in C#. Given that my program handled all data in String formatting first, I first made sure I remove custom formatting then convert to byte array.

 

private string RFID_1356MHZ_Calculate_CSUM(string CommandBuilder)

{  

byte CSUM = 0;  // strip the input of all delimiter characters and the optional 0x prefix  

string data = CommandBuilder.Replace("0x", "").Replace("0X", "").Replace("/n", "0A").Replace("/r","0D").Replace(delimiter, "").Replace(",", "").Replace(" ", "").ToUpper();  // convert the hex characters to a byte array  byte[] buffer = new byte[data.Length / 2 + lineEnding.Length];

for (int i = 0; i < data.Length; i += 2)  

{   

buffer[i / 2] = byte.Parse(data.Substring(i, 2), System.Globalization.NumberStyles.AllowHexSpecifier);  

}  

//Calculate CheckSum  

unchecked // Let overflow occur without exceptions      

{   

for(int i = 0; i < buffer.Length; i++)

{    

CSUM ^= buffer[i];   

}  

}  

return (String.Format("{0}{1:X2}{2}", hexPrefix, CSUM, delimiter));

}


About the Sole Electronics Forum

Forum Timezone: UTC -8

Most Users Ever Online: 6

Currently Online:
4 Guests

Currently Browsing this Topic:
1 Guest

Forum Stats:

Groups: 2
Forums: 11
Topics: 7
Posts: 9

Membership:

There are 14 Members

There is 1 Admin

Top Posters:

patricia – 1

Recent New Members: joelogan, jelkhoury, patricia, admin

Administrators: Haz (11 Posts)