PC Review


Reply
Thread Tools Rate Thread

How to calculate the checksum?

 
 
=?Utf-8?B?Q2hyaXN0aWFuIEhhdmVs?=
Guest
Posts: n/a
 
      18th Nov 2007
Hi,

how can I calculate the checksum (CRC-16) from the byte[] I retrieve from a
hardware device through the RS232 serial port?

Christian
 
Reply With Quote
 
 
 
 
Morten Wennevik [C# MVP]
Guest
Posts: n/a
 
      18th Nov 2007
Hi Christian,

Maybe this articles can give you some ideas.

[CRC Encoding]
http://www.codeproject.com/csharp/ma...select=1726104



On Sun, 18 Nov 2007 15:23:00 +0100, Christian Havel <(E-Mail Removed)> wrote:

> Hi,
>
> how can I calculate the checksum (CRC-16) from the byte[] I retrieve from a
> hardware device through the RS232 serial port?
>
> Christian
>




--
Happy coding!
Morten Wennevik [C# MVP]
 
Reply With Quote
 
=?UTF-8?B?QXJuZSBWYWpow7hq?=
Guest
Posts: n/a
 
      18th Nov 2007
Christian Havel wrote:
> how can I calculate the checksum (CRC-16) from the byte[] I retrieve from a
> hardware device through the RS232 serial port?


I have some CRC-16 code on the shelf.

I fact I have more than one version.

Do you have some sample data and an expected result to
help determine which ?

Arne
 
Reply With Quote
 
=?Utf-8?B?Q2hyaXN0aWFuIEhhdmVs?=
Guest
Posts: n/a
 
      18th Nov 2007
Hi Arne,

thanks for your help. I have the following informations:

<Sync_1 = 0x81> 8 DATA-BITS No Parity
<Sync_2 = 0x82> 8 DATA-BITS No Parity
<Cksum> = Telegramm<[pos_Sync_1]> XOR . XOR . XOR ... [<pos_Sync_2-2>]
<Cmd> = Command to modem

|<--- CheckSum : --------------- XOR ------------------->|
<Sync_1>, <DEV_ADR>, <Cmd>, <OPTION>, [<DATA>], <Chksum>, <Sync_2>

Hope this helps.
Christian

"Arne Vajhøj" wrote:

> Christian Havel wrote:
> > how can I calculate the checksum (CRC-16) from the byte[] I retrieve from a
> > hardware device through the RS232 serial port?

>
> I have some CRC-16 code on the shelf.
>
> I fact I have more than one version.
>
> Do you have some sample data and an expected result to
> help determine which ?
>
> Arne
>

 
Reply With Quote
 
Peter Ibbotson
Guest
Posts: n/a
 
      18th Nov 2007

"Christian Havel" <(E-Mail Removed)> wrote in
message news:6713ABF0-C84F-40BE-A065-(E-Mail Removed)...
> Hi Arne,
>
> thanks for your help. I have the following informations:
>
> <Sync_1 = 0x81> 8 DATA-BITS No Parity
> <Sync_2 = 0x82> 8 DATA-BITS No Parity
> <Cksum> = Telegramm<[pos_Sync_1]> XOR . XOR . XOR ... [<pos_Sync_2-2>]
> <Cmd> = Command to modem
>
> |<--- CheckSum : --------------- XOR ------------------->|
> <Sync_1>, <DEV_ADR>, <Cmd>, <OPTION>, [<DATA>], <Chksum>, <Sync_2>
>


It depends on what sort of CRC it is.

For most serial protocols it is based on the table driven one in x/y/zmodem
source code. However that isn't the correct CRC value for an ethernet packet
OR an SDLC/HDLC comms protocol.

You could use
http://sourceforge.net/projects/clas...er/?format=raw

which contains more CRC variants than I've encountered in the wild but most
comms protocols tend to use the one contained in FCS16.

I suspect from your code that actually you just want to XOR all the bytes in
the data together.

Without a sample data packet (or sample source code) it's nearly impossible
to tell if you've got it right. When I first did the ethernet one I ended up
hand decoding a packet on an oscilloscope screen to see exactly what was
transmitted!

Peter

 
Reply With Quote
 
=?UTF-8?B?QXJuZSBWYWpow7hq?=
Guest
Posts: n/a
 
      19th Nov 2007
Christian Havel wrote:
> thanks for your help. I have the following informations:
>
> <Sync_1 = 0x81> 8 DATA-BITS No Parity
> <Sync_2 = 0x82> 8 DATA-BITS No Parity
> <Cksum> = Telegramm<[pos_Sync_1]> XOR . XOR . XOR ... [<pos_Sync_2-2>]
> <Cmd> = Command to modem
>
> |<--- CheckSum : --------------- XOR ------------------->|
> <Sync_1>, <DEV_ADR>, <Cmd>, <OPTION>, [<DATA>], <Chksum>, <Sync_2>
>
> Hope this helps.


That is not sample data and sample checksum.

It looks more as simple XOR than CRC.

But without more specific information everything will just
be guesswork.

Arne
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help calculate checksum (newbie) Adriano Microsoft VB .NET 3 17th Oct 2008 01:12 AM
How to calculate a checksum by modulus 10 Hallgeir Microsoft Access Reports 3 25th Dec 2006 12:09 PM
Calculate Checksum =?Utf-8?B?U2FmaQ==?= Microsoft Excel Worksheet Functions 1 23rd Jul 2006 02:37 PM
Calculate Checksum =?Utf-8?B?U2FmaQ==?= Microsoft Excel Programming 0 23rd Jul 2006 08:36 AM
Calculate a checksum (e.g. md5) on a group of cells Tobias Gårdner Microsoft Excel Worksheet Functions 0 5th May 2004 12:34 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:08 PM.