Function to calculate block check character (BCC) in C #

Block Check Character (BCC) I need a function to compute a Block Check Character (BCC) in C #. 01 30 02 4D 21 20 20 03 This is a line, how can I calculate the "Character Check Character" for this line.

BCC = Exclusive OR from SOH to ETX SOH ID STX CODE ETX BCC 0x01 0x30 0x02 0x40 0x03

I need to add BCC and send data to COM. If possible, please give me a function so that I can send "01 30 02 4D 21 20 20 03" and get a BCC.

thanks

+3
source share
1 answer

, , , BCC XOR , SOH STX ETX EOT. ETX BCC. ETX , BCC.

 public static byte GetBCC(this byte[] inputStream)
    {
        byte bcc = 0;

        if (inputStream != null && inputStream.Length > 0)
        {
            // Exclude SOH during BCC calculation
            for (int i = 1; i < inputStream.Length; i++)
            {
                bcc ^= inputStream[i];
            }
        }

        return bcc;
    }
+3

Source: https://habr.com/ru/post/1717373/


All Articles