Solved

C# Funtion Calculating UTF-8 BCC

Posted on 2010-08-26
3
1,255 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Turn Insights Into Action

You’ve already invested in ITSM tools, chat applications, automation utilities, and more. Fortify these solutions with intelligent communications so you can drive business processes forward.

With xMatters, you'll never miss a beat.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Iteration: Iteration is repetition of a process. A student who goes to school repeats the process of going to school everyday until graduation. We go to grocery store at least once or twice a month to buy products. We repeat this process every mont…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

717 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