ASTM uses a two-byte checksum method. The checksum is initialized to zero with each <STX> character. The count begins with the frame number FN, and includes each character of the text ending with either the <ETB> or <ETX> characters (modulo 256). The count excludes the <STX>, <CR> <LF>, and the checksum characters themselves.The checksum is an integer represented by eight bits having two groups of four bits each. It is provided as an ASCII representation of its hexadecimal equivalent. The two ASCII checksum characters in the ASTM frame begin with the most significant.
Hexdata = "2020202020442042497c31323334414243353637387c"
calculation = 20+20+20+20+20+44+20+42+49+7c+31+32+33+34+41+42+43+35+36+37+38+7c = 4f1
resutl = 4f1
Here is a sample code that I want apply in vb.net
public String getCheckSum(String msg)
{
int sum = 0;
for (int i = 0; i < msg.length(); i++) {
sum += msg.charAt(i);
}
sum += 16; //adding CR and ETX AND ETB
sum = sum % 256;
String checksum = Integer.toHexString(sum).toUpperCase();
if (checksum.length() == 1) {
checksum = "0" + checksum;
}
//System.out.println("\n Check Sum is ="+checksum);
return checksum;
}