计算块检查字符(BCC)的串行通信 [英] Calculate Block Check Character (BCC) for serial communication

查看:791
本文介绍了计算块检查字符(BCC)的串行通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个设备通过通过SerialPort类的.NET串行通信,并根据我需要计算一个块校验字符第三方设备规范要求。据我所知的唯一信息是,它是一个异或运算(XOR),它必须对所有字符进行。

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.

所以,如果我有字符串鲍勃,001如何将一个计算BCC?

So if I have the string "Bob,001" how would one calculate the BCC?

推荐答案

最有可能的是基于字符的XOR。你需要让他们的样本来验证,但大多数校验通常最终会在0。

Most likely is character based XOR. You'll need to get samples of them to verify but most checksums usually end up at 0.

那么,对于一个XOR校验,你会包:

So, for an XOR checksum, you would have the packet:

Bob,001X

其中X是校验和,当你XOR所有这些字符在一起,你最有可能得到0。

where X is the checksum and, when you XOR all those characters together, you'd most likely get 0.

所以,制定出X,在鲍勃,001你刚才XOR所有字符。这是由于这样的事实在于n异或N是始终为0,对于任意的n

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.

现在则可能是X将是两个十六进制字符,如果你只能有是字母数字。这就是为什么你需要或者样本数据(这样我们就可以做出来),或者一个适当的规范(这应该由设备制造商提供)。

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.

基于更新:

这是一个Amadeus的招待费PMS装置。没有所有他们说的是,它必须执行对所有字符。不包括STX和ETX。

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.

这篇关于计算块检查字符(BCC)的串行通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆