0

I am trying to write some code to communicate with an old device over serial that uses the Siemens 3964r protocol. This includes a checksum, or more accurately a BCC (block check character) at the end of the transmission. A single char after the ETX. The docs define the BCC as this:

With the 3964R transfer protocol, data security is enhanced by sending an additional block check character (BCC = Block Check Character). The block check character is the even longitudinal parity (EXOR logic operation of all data bytes) of a sent or received block. Its calculation begins with the first byte of user data (first byte of the frame) after the connection establishment, and ends after the DLE ETX character at connection termination.

Here is some sample data in hex. 53 54 41 54 55 53 10 03 07

07 is the BCC in this one.

4d 45 41 53 4d 50 54 45 53 54 41 4e 41 50 52 47 30 30 30 55 78 30 31 31 2e 30 30 5a 30 31 31 31 30 10 03 61

61 is the BCC in this one.

I know in general how to do XOR operations, but I haven't been able to figure out any combination of things that gives me a proper BCC. I think I am interpreting the definition wrong.

My preferred language for this is javascript as it's for a node.js electron app. I can read the buffer and get the hex values. And I can construct propoer messages back. But it won't work correctly until I can include a proper BCC. So just looking for someone smarter than me that knows exactly how to produce a valid BCC.

thanks!

wookie924
  • 53
  • 6
  • 1
    Perhaps this document is relevant. [S7-300 CP 341 Point-to-Point Communication, Installation and Parameter Assignment Manual](https://support.industry.siemens.com/cs/attachments/1117397/s7300_cp341_manual_en_en-US.pdf?download=true) – kunif May 25 '19 at 17:56
  • That document looks very promising. The best bcc explanation yet at least. I’m going to work up a script calculating that. And see where I am. Thanks – wookie924 May 25 '19 at 19:39

1 Answers1

0

The document that was posted as the first comment had the right structure to calculate the 3964r BCC. That document is here:

https://support.industry.siemens.com/cs/attachments/1117397/s7300_cp341_manual_en_en-US.pdf?download=true

Here is a simple javascript function. The hexarray would be passed in, not hardcoded like here, but this accurately calculates the BCC for this particular protocol. If anyone cares or needs it. I just wrote out the bcc as a hex string to the console in this, but you can make it a function and actually return something useable.

var hexarr = ['4d', 45, 41, 53, '4d', 50, 30, 30, 10, 03];
var bcc = 0;
var xor = 0;

for(var i= 0; i< hexarr.length; i++){
    var hexint = parseInt(hexarr[i],16);
    if(i==0){ xor = hexint; }
    else {
        bcc = xor ^ hexint;
        xor = bcc;
    }
}

console.log(bcc.toString(16));
wookie924
  • 53
  • 6