CRC校验和算法 [英] CRC checksum algorithm

查看:96
本文介绍了CRC校验和算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

Ia ??使用手持设备与Windows服务进行通信

串口。

设备之间的交易我的应用程序如下:


握手:

设备发送ENQ

服务响应DLE 0

设备发送DLESOH4168840000SR01L01DLEETX4 ??


正如您在字符串末尾看到的那样,在DLE ETX(数据链接转义和结束

文本)控制之后代码,设备发送另外两个字符4 ??。

如果我没有误会,这将是这个

字符串的CRC校验和的计算。


每次交易后,我需要计算CRC并与

设备发送的CRC进行比较。只是为了确保我们没有错过任何数据。

我尝试了很多不同的方法,但是我们没有想出正确的算法来

得到4 ??在这个字符串上。

有人可以帮我一个吗?


谢谢

Hello,
Ia??m working with handheld device that communicates with windows service thru
the serial port.
Transaction between device and my application looks like this:

Handshaking:
Device sends ENQ
Service responds DLE 0
Device sends DLESOH4168840000SR01L01DLEETX4??

As you see at the end of the string, after DLE ETX (Data Link escape and end
of text) control codes, device sends two more characters 4??.
If Ia??m not mistaking, this would be the calculation of CRC checksum of this
string.

After each transaction, I need to calculate CRC and compare to the one that
device sends. Just to make sure that we didna??t miss any data.
I tried many different ways, but cana??t come up with the correct algorithm to
get 4?? on this string.
Is anybody can give me a hand on this one?

Thanks

推荐答案




这可能是CRC,也许是更简单的校验和。由于它只是一个单字节,我的猜测是它不是CRC(虽然我的书中有CRC-8代码,但是它的使用非常罕见) )。


您将数据打印为ASCII / ANSI(文本),因此使用的字体可能会混淆

的东西。如果你打印出收到的实际二进制数据,我或许可以通过快速检查来查看已使用的算法。


Dick


-

Richard Grier(微软Visual Basic MVP)


参见 www.hardandsoftware.net 获取联系信息。


Visual Basic程序员的作者串行通信指南,第4版

Edition ISBN 1-890422-28-2(391页)2004年7月出版。参见
www.mabry.com/vbpgser4 订购。
Hi,

This might be a CRC or, perhaps, a simpler checksum. Since it is only a
single byte, my guess is that it is not a CRC (though I have CRC-8 code in
my book, its use is quite uncommon).

You are printing the data as ASCII/ANSI (text), so the font used can confuse
things. If you print out the actual binary data received, I may be able to
run a quick check to see what algorithm has been used.

Dick

--
Richard Grier (Microsoft Visual Basic MVP)

See www.hardandsoftware.net for contact information.

Author of Visual Basic Programmer''s Guide to Serial Communications, 4th
Edition ISBN 1-890422-28-2 (391 pages) published July 2004. See
www.mabry.com/vbpgser4 to order.


这看起来类似于Allen-布拉德利协议,所以你可能想看看

这个。由于最后一个字符只有8位,它更可能是BCC

(二进制校验字符)而不是CRC,这通常至少是b
-比特。


计算BCC的正常方法是将数据MOD 256相加。记住,

虽然,_data_并不代表整个二进制字符串BCC通常仅在字符串的一部分上计算。在Allen-Bradley

协议的情况下,这将是DLE SOH和

DLE ETX之间的所有数据(但不包括)。另外,AB实际上取得了由此产生的BCC的两个补码。


最终,唯一可以确定的方法是获得一些参考

您与制造商合作的设备。


HTH


Charles

" ValK" < Va的** @ discussions.microsoft.com>在消息中写道

news:37 ********************************** @ microsof t.com ...
This looks similar to an Allen-Bradley protocol, so you might want to look
this up. As the last character is only 8-bit it is more likely to be a BCC
(binary check character) rather than a CRC, which is usually at least
16-bit.

The normal way to calculate a BCC is to sum the data MOD 256. Bear in mind,
though, that _data_ does not mean the entire binary string. BCC is usually
calculated on only a part of the string. In the case of an Allen-Bradley
protocol this would be all data between (but not including) the DLE SOH and
DLE ETX. Also, A-B actually takes the two''s complement of the resulting BCC.

Ultimately, the only way to know for certain is to get some reference for
the equipment you are working with from the manufacturer.

HTH

Charles
"ValK" <Va**@discussions.microsoft.com> wrote in message
news:37**********************************@microsof t.com...
你好,
我正在使用手持设备与windows服务进行通信
通过串口。
设备与我的应用程序之间的交易如下:

握手:
设备发送ENQ
服务响应DLE 0
设备发送DLESOH4168840000SR01L01DLEETX4á

正如您在字符串末尾看到的那样,在DLE ETX(数据链接转义和文本结束)控制代码之后,设备再发送两个字符4á。
如果我不是错误,这将是这个
字符串的CRC校验和的计算。

每次交易后,我需要计算CRC并与之比较那个
设备发送。只是为了确保我们不会错过任何数据。
我尝试了很多不同的方法,但是不能提出正确的算法
来获得4字符串。
有人可以帮我一个吗?

谢谢
Hello,
I''m working with handheld device that communicates with windows service
thru
the serial port.
Transaction between device and my application looks like this:

Handshaking:
Device sends ENQ
Service responds DLE 0
Device sends DLESOH4168840000SR01L01DLEETX4á

As you see at the end of the string, after DLE ETX (Data Link escape and
end
of text) control codes, device sends two more characters 4á.
If I''m not mistaking, this would be the calculation of CRC checksum of
this
string.

After each transaction, I need to calculate CRC and compare to the one
that
device sends. Just to make sure that we didn''t miss any data.
I tried many different ways, but can''t come up with the correct algorithm
to
get 4á on this string.
Is anybody can give me a hand on this one?

Thanks



迪克,

这是这个字符串的实际二进制数据:


?bRead()

{Length = 23}

(0):16

(1):1

(2):52

(3):49

(4):54

(5):56

(6):56

(7):52

(8):48

(9):48

(10):48

(11):48

(12):83

(13):82

(14):48

(15):49

(16):76

(17):48

(18):49

(19) :16

(20):3

(21):52

(22):225

" ;迪克格里尔写道:
Dick,
Here is the actual binary data of this string:

?bRead()
{Length=23}
(0): 16
(1): 1
(2): 52
(3): 49
(4): 54
(5): 56
(6): 56
(7): 52
(8): 48
(9): 48
(10): 48
(11): 48
(12): 83
(13): 82
(14): 48
(15): 49
(16): 76
(17): 48
(18): 49
(19): 16
(20): 3
(21): 52
(22): 225
"Dick Grier" wrote:


这可能是CRC,或者更简单的校验和。由于它只是一个单字节,我的猜测是它不是CRC(虽然我的书中有CRC-8代码,但它的使用非常罕见)。

迪克

-
Richard Grier(Microsoft Visual Basic MVP)

请参阅 www.hardandsoftware .net 获取联系信息。

Visual Basic程序员串行通信指南的作者,第4版
Edition ISBN 1-890422-28-2(391页)已发布2004年7月。请参阅
www.mabry.com/vbpgser4 进行订购。
Hi,

This might be a CRC or, perhaps, a simpler checksum. Since it is only a
single byte, my guess is that it is not a CRC (though I have CRC-8 code in
my book, its use is quite uncommon).

You are printing the data as ASCII/ANSI (text), so the font used can confuse
things. If you print out the actual binary data received, I may be able to
run a quick check to see what algorithm has been used.

Dick

--
Richard Grier (Microsoft Visual Basic MVP)

See www.hardandsoftware.net for contact information.

Author of Visual Basic Programmer''s Guide to Serial Communications, 4th
Edition ISBN 1-890422-28-2 (391 pages) published July 2004. See
www.mabry.com/vbpgser4 to order.



这篇关于CRC校验和算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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