# Calculating BCC (Block Check Character)

Hi Everybody,

Can someone help me out please?, i need a BCC (Block Check Character) calculator function.

What, exactly is it for? There are many algorithms for this type of thing (checksums, CRCs, etc).

Hi Hugo,

I am trying to connect imp(with serial uart12) to a CleanCash (http://www.retailinnovation.se) module, which registers transactions initiated by a Point of Sale Service. I can send and receive, no problems there.

The commands to CleanCash module requires an ascii data sequence wrapped between STX(2) …ETX(3) and at the and the BCC value.

with my BCC function i can process this ascii data sequence:
2,48,48,48,48,48,48,53,48,51,3,53
the 53 at the end being the BCC checksum char value, which is according to this manuals is correct. http://www.rakurs.su/files/ControlComponents/H158-E1-01+E5_N+CommManual.pdf

The CleanCash module BCC function calculates this sequence:
2,73,49,52,48,3,34
to 34 BCC checksum char.

but according to my BCC function with this sequence :
2,73,49,52,48,3,127
its the 127 BCC checksum char.

what am i doing wrong?

Here is my BCC Function:

function getCheckSum(s)
{
local i;
local CalcCS=0; // calculated checksum
local len = s.len()-1; // don’t include checksum bytes
for (i=1;i<len;i++) //skip first char (2)
{
CalcCS = CalcCS ^ s[i];
}
return CalcCS;
}

Hi Hugo,

Here is a modified BCC function:

function getCheckSum(s)
{
//s=“2,73,49,52,48,3,34”;

``````local i;
local CalcCS=0;     // calculated checksum
local len = s.len()-2;  // don't include checksum bytes and ETX(3)
for (i=1;i<len;i++) //skip first char STX (2)
{
CalcCS = (CalcCS + s[i]) & 0xFF;
}

CalcCS =  (((CalcCS ^ 0xFF) + 1) & 0xFF);

return CalcCS;
``````

}

Yeah, that’s quite a different algorithm to the one you found in the omron datasheet. People just tend to invent their own ones…