Solved

C# Funtion Calculating UTF-8 BCC

Posted on 2010-08-26
3
1,151 Views
Last Modified: 2013-12-17
Hello guys,
I have a string and convert it into UTF-8 byte array, so this array needs to be an parameter of a function, that will return the BCC. But I need the function.
0
Comment
Question by:IncognitoMan
  • 3
3 Comments
 
LVL 4

Accepted Solution

by:
ricovox earned 500 total points
ID: 33535695
Hello,

I believe by BCC you mean byte,block, and checksum, right?
Can you tell me a little more about the way your data is formatted?

What I mean is that usually you send the data in a transmission that includes additional information like this:
<data...><additional bytes><checksum>

Where "additional bytes" are 1 or 2 additional random bytes that you add to the transmission to ensure better verification accuracy. These would be optional, and maybe you have them and maybe you don't. It depends on your application.

Usually you want to compare the calculated checksum of the data plus the additional bytes AFTER transmission with the checksum calculated BEFORE transmission. Does this sound about right? Do you use the additional bytes or not?

I don't know if the definition for BCC is standardized, but I saw an 8-bit BCC calculated by XORing all the bytes in the data:

private byte CalcBCC(byte[] buffer)
{
    byte calc = 0x00;
   
    //XOR with each byte in the buffer
    for (int i = 1; i < buffer.Length - 1; i++)
    {
        calc ^= buffer[i];
    }
    return calc;
}

You would just have to be consistent in using the same function both before and after transmission to obtain the same checksum. Also make sure to be consistent with what part of the datastream you calculate. I.e. if there are "additional bytes" then make sure to include them in both calculations for consistency.

Hope that helps.
0
 
LVL 4

Expert Comment

by:ricovox
ID: 33535827
After more searching I found another reference about BCC.
This is a PDF that is probably for a specific RS232 instrument.
http://www.bttautomatyka.com.pl/pdf/HA466357.pdf

In it, they have data formatted like this:
<STX><DATA><ETX><CHECKSUM>
Where STX and ETX are each single bytes representing the start and end of the data, respectively.
The BCC is calculated exactly as I specified in the code in my previous post, but it INCLUDES both the STX and ETX. So you have to make sure that these are included in the byte array you pass in to the function. Then you have to remember that the data does NOT include these two characters. The data also does not include the checksum at the end, which is another single byte.

I can send you some more code if you need additional help.
0
 
LVL 4

Expert Comment

by:ricovox
ID: 33535834
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now