473,412 Members | 1,944 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

CRC checksum algorithm

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

Nov 21 '05 #1
15 7698
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.
Nov 21 '05 #2
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...
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

Nov 21 '05 #3
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:
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.

Nov 21 '05 #4
wg
I am in the process of looking for code for a CRC 16H checksum algorithim.
If anyone has this or a reference to where to find one it would be greatly
appriciated. I am writing an interface to old old PLC (Programmable Logic
Controller).

Thanks

wg
"ValK" <Va**@discussions.microsoft.com> wrote in message
news:37**********************************@microsof t.com...
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

Nov 21 '05 #5
wg
Dick,

I took a look at you book on your web site. As mentioned in a post I am
working on an older PLC interafce to OPC. I have written OPC servers before
so this is not a problem. I have never writtin a serial communications in
VB.NET until now. I have gotten an example rs232 class that seems to work
fine. I will have to write a CRC algoritham and since this interface is
attached to 10 PLC's on 10 serial ports I was thinking of multi-threading
the it. What books would you recommend I look into? I would really rather
not use the MSCOMM.OCX from VB6.

Thanks
wg
"Dick Grier" <di**************@msn.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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.

Nov 21 '05 #6
I don't know if you are able to use a beta product or not, but just to let
you know, Visual Studio 2005 includes a serial communication control.

Richard Rosenheim
"wg" <wg@hotmail.com> wrote in message
news:xr****************@bignews5.bellsouth.net...
Dick,

I took a look at you book on your web site. As mentioned in a post I am
working on an older PLC interafce to OPC. I have written OPC servers before so this is not a problem. I have never writtin a serial communications in
VB.NET until now. I have gotten an example rs232 class that seems to work
fine. I will have to write a CRC algoritham and since this interface is
attached to 10 PLC's on 10 serial ports I was thinking of multi-threading
the it. What books would you recommend I look into? I would really rather
not use the MSCOMM.OCX from VB6.

Thanks
wg
"Dick Grier" <di**************@msn.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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.


Nov 21 '05 #7
wg
Richard,

I have not downloaded it yet. I am worried about it being a beta version.
Will this affect anything?
wg
"Richard L Rosenheim" <ri*****@rlr.com> wrote in message
news:uK**************@tk2msftngp13.phx.gbl...
I don't know if you are able to use a beta product or not, but just to let
you know, Visual Studio 2005 includes a serial communication control.

Richard Rosenheim
"wg" <wg@hotmail.com> wrote in message
news:xr****************@bignews5.bellsouth.net...
Dick,

I took a look at you book on your web site. As mentioned in a post I am
working on an older PLC interafce to OPC. I have written OPC servers

before
so this is not a problem. I have never writtin a serial communications in
VB.NET until now. I have gotten an example rs232 class that seems to work
fine. I will have to write a CRC algoritham and since this interface is
attached to 10 PLC's on 10 serial ports I was thinking of multi-threading
the it. What books would you recommend I look into? I would really rather
not use the MSCOMM.OCX from VB6.

Thanks
wg
"Dick Grier" <di**************@msn.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
> 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.
>
>



Nov 21 '05 #8
wg,
You have a few options:
You can get free Visual Basic Resource Kit from Microsoft. I has in it the
Sax Communications Community Edition .NET Serial control. Something like
MSComm control.

Also if you look at Dick Grier web site www.hardandsoftware.net , you can
download NETComm.ocx control.

Val
"wg" wrote:
Richard,

I have not downloaded it yet. I am worried about it being a beta version.
Will this affect anything?
wg
"Richard L Rosenheim" <ri*****@rlr.com> wrote in message
news:uK**************@tk2msftngp13.phx.gbl...
I don't know if you are able to use a beta product or not, but just to let
you know, Visual Studio 2005 includes a serial communication control.

Richard Rosenheim
"wg" <wg@hotmail.com> wrote in message
news:xr****************@bignews5.bellsouth.net...
Dick,

I took a look at you book on your web site. As mentioned in a post I am
working on an older PLC interafce to OPC. I have written OPC servers

before
so this is not a problem. I have never writtin a serial communications in
VB.NET until now. I have gotten an example rs232 class that seems to work
fine. I will have to write a CRC algoritham and since this interface is
attached to 10 PLC's on 10 serial ports I was thinking of multi-threading
the it. What books would you recommend I look into? I would really rather
not use the MSCOMM.OCX from VB6.

Thanks
wg
"Dick Grier" <di**************@msn.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
> 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.
>
>



Nov 21 '05 #9
Hi,

I will have to write a CRC algoritham and since this interface is
attached to 10 PLC's on 10 serial ports I was thinking of multi-threading
the it. What books would you recommend I look into? I would really rather
not use the MSCOMM.OCX from VB6.
<<

Threading is OK.

Easiest my be to download DesktopSerialIO dll from my homepage. It already
implements threaded receive, so you don't really need anything more. It is
practical to simply use the OnComm events, which execute in the object's
worker thread context.

I have CRC examples in my book, and I suspect that the CRC-16 (CCITT) is the
one that you need.

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.
Nov 21 '05 #10
Actually, the DesktopSerialIO dll that I have placed on my site is better
(IMO) than NETComm.ocx for .NET applications, unless you are porting from
VB6 -- where it is just about a wash.

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.
Nov 21 '05 #11
Hi,

This looks like:
DLE-STX[data]DLE-ETX[2-byteCS]

Is that your understanding? If so, then this probably is a 16-bit CRC, not
a simple checksum. The trick is to determine what CRC (or, perhaps some
other form of 2-byte checksum). Do you have any description from the vendor
on what it is, or how it is calculated?

I've tried your data with a standard CRC-16, and the result is D066, not
34FF (hex format), so my guess it that this CS is different.

Can you get any more information on what or how this CS is 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.
Nov 21 '05 #12
Hi,

I have two different CRC-16 algorithms in my book. You also can download
from my homepage. However, there are lots of possible algorithms, so you
need to know for sure which one is being used. Probably the CCITT CRC-16,
but...

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.
Nov 21 '05 #13
wg
Dick,

I just ordered you book to help out. I also downloaded the DestopIO dll to
ty. The algorithm is CRC-16H or CCITTA.

Thanks,
wg
"Dick Grier" <di**************@msn.com> wrote in message
news:O0**************@TK2MSFTNGP14.phx.gbl...
Hi,

I have two different CRC-16 algorithms in my book. You also can download
from my homepage. However, there are lots of possible algorithms, so you
need to know for sure which one is being used. Probably the CCITT CRC-16,
but...

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.

Nov 21 '05 #14
Hi,

What protocol? Some protocols calculate the CRC over only the data (not the
packet header and trailer), and some calculate the CRC over the entire
packet.

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.
Nov 21 '05 #15
wg
Dick,

Not sure the protocal, just rs232 serial string. It calculates it over the
data only, not using the header, not sure if there is a trailer. From the
PLC manual I am to send a request and the PLC responses with the data. Both
the send a receive have a checksum of CITTA.

I had sent you an email asking about the DesktopIO form you site. How would
you use this control and look for a delimeter? Specifically if the buffer is
of size catch a string message and keep the rest.

Thanks

wg

"Dick Grier" <di**************@msn.com> wrote in message
news:u5**************@TK2MSFTNGP12.phx.gbl...
Hi,

What protocol? Some protocols calculate the CRC over only the data (not
the packet header and trailer), and some calculate the CRC over the entire
packet.

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.

Nov 21 '05 #16

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Mercuro | last post by:
Hello i'm looking for a simple way to checksum my data. The data is 70 bytes long per record, so a 32 byte hex md5sum would increase the size of my mysql db a lot. I'm looking for something...
3
by: wilk | last post by:
I have a problem witch calculating TCP or UDP checksum. This is what I found: u16 in_cksum(u16 *addr,int count) { register long sum = 0; /* add 16-bit words */ while (count > 1) { /* this...
4
by: Abby | last post by:
I have an array which contain Hex no. in each position. For examples, unsigned char data; data = 0x00; data = 0x01; data = 0x02; data = 0xE; data = 0xEF; --> This is the checksum value
6
by: Kevin | last post by:
I'm on Sun 0S 5.8 and need to calculate the checksum of certain sections in an ELF binary file. Specifically .text to .rodata. I'm able to parse through to the program header table and then find...
1
by: Terry | last post by:
I'm trying to calculate the checksum for UDP packet. The algorithm itself is not difficult (lots of examples out there), but what I'm having the most trouble with is determining the byte order...
1
by: Ali | last post by:
Hi What is the algorithm of checksum in windows file thanks Ali.
24
by: Bob | last post by:
Hi there, I am working on an application to be used in our local Forensics department... Among other things the app will connect to a digital camera and download the images to the hard drive....
34
by: Zahid Faizal | last post by:
Kindly suggest a good opensource package (in C or C++) that can compute the checksum of a file. SHA2 would be preferable, but SHA1/SHA0/MD5 would be acceptable as well. We have cards with...
2
by: ManDev | last post by:
Hi, We have checksum function in sql server 2000,i would like to implement same in .Net.Can some one provide checksum algorithm. Thanks ManDev.
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.