Calculate Block Check Character (BCC) for serial communication

12,232

Most likely is character based XOR. You'll need to get samples of them to verify but most checksums usually end up at 0.

So, for an XOR checksum, you would have the packet:

Bob,001X

where X is the checksum and, when you XOR all those characters together, you'd most likely get 0.

So, to work out X, you just XOR all the characters in "Bob,001". That's by virtue of the fact that N xor N is always 0, for any N.

Now it may be that X will be two hex characters if all you're allowed to have is alphanumerics. That's why you need either sample data (so we can work it out) or a proper spec (which should be provided by the device manufacturer).

What is the actual device you're referring to? It may be there's info on the web that shows how to do it.

Based on update:

It's an Amadeus Hospitality PMS device. No all they say is that it must be performed over all chars. excluding the STX and ETX.

You'll need to get some sample data to confirm but it's likely to a data stream something like:

        Running
Data     ChkSum
======  =======
STX 02
B   42     42
o   6f     2d
b   62     4f
,   2c     63
0   30     53
0   30     63
1   31     52
4   52     00
ETX 03

The position of the checksum may vary and, indeed, it's calculation may vary too though that's much less likely. I don't think much more can be done without sample data or further information from the vendor. A cursory search of the internet turned up no technical details.

Share:
12,232
GONeale
Author by

GONeale

Full time thinker. Overtime coder. Part time real world. Follow me on Twitter

Updated on June 04, 2022

Comments

  • GONeale
    GONeale almost 2 years

    I am communicating with a device via serial via the SerialPort class of .NET and based on third-party device specification requirements I need to calculate a "block check character". The only information I am told is that it is an exclusive OR operation (XOR) and it must be performed over all characters.

    So if I have the string "Bob,001" how would one calculate the BCC?