Calculate Block Check Character (BCC) for serial communication

…衆ロ難τιáo~ 提交于 2019-12-07 07:46:08

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/891664/calculate-block-check-character-bcc-for-serial-communication

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!