LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

CRC generator problem

Solved!
Go to solution

Hi everyone,

 

I have a problem with CRC generator that I found on this forum and I was hopeing that someone can help me. 

 

I must send following structure to device:

image005.jpg

 

You see at the end that I must calculate CRC-16 but the vi that I use does not give me the right values and I don't know why. (have in mind I'm total beginner in CRC)

 

This is what the result should look like:

STX Slave ID LENGTH DATA CRCL CRCH
7F 80 01 11 65 82
7F 80 01 0C 2B 82
7F 80 01 05 1D 82
7F 00 09 4A 2B6D 4F25 0000 0000 AA 5A
7F 80 09 4B  51EF D04F 0000 0000 7D 6D
7F 00 09 4C CA2D 222C 0000 0000 5A 42

 

 

Please help! 

0 Kudos
Message 1 of 18
(6,911 Views)

The first issue is that there are about a thousand different ways to calculate a CRC. You first of all need to make sure you are using the right algorithm. The documentation on your device gives you examples. All you have to do is find the one that gives the correct result. The good news is that there are 3 or 4 common ones that are used most often. The way a CRC is defined in by the polynomial that defines it. Google CRC and the article will fill in a lot of blanks for you.

 

Like, the one you are using is defined as:

 

CRC-16-IBM x^{16} + x^{15} + x^2 + 1 (Bisync, Modbus, USB, ANSI X3.28, many others; also known as CRC-16 and CRC-16-ANSI)

 

Mike...

 

PS: You also need to make sure that you are including the right things (the device documentation will tell you what to include in the CRC), that the resulting bytes are put in the right order, and that the algorithm is initialized correctly, this algorithm can be initialized with 0xFFFF, 0x0000 or some custom value. Also note that if you are wanting to check the response, if you run the same CRC on the entire message including the CRC the device transmitted, the result will always be 0x0000.


Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 2 of 18
(6,880 Views)

The first issue is that there are about a thousand different ways to calculate a CRC. You first of all need to make sure you are using the right algorithm. The documentation on your device gives you examples. All you have to do is find the one that gives the correct result. The good news is that there are 3 or 4 common ones that are used most often. The way a CRC is defined in by the polynomial that defines it. Google CRC and the article will fill in a lot of blanks for you.

 

Like, the one you are using is defined as:

 

CRC-16-IBM x^{16} + x^{15} + x^2 + 1 (Bisync, Modbus, USB, ANSI X3.28, many others; also known as CRC-16 and CRC-16-ANSI)

 

Mike...

 

PS: You also need to make sure that you are including the right things (the device documentation will tell you what to include in the CRC), that the resulting bytes are put in the right order, and that the algorithm is initialized correctly, this algorithm can be initialized with 0xFFFF, 0x0000 or some custom value. Also note that if you are wanting to check the response, if you run the same CRC on the entire message including the CRC the device transmitted, the result will always be 0x0000.


Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 3 of 18
(6,880 Views)

Thank you for answer mike,

 

device documentation says thic about CRC:

Capture.PNG

 

So the method is CRC-16, Polynomial (0x8005 or 0x1021) and seed 0xFFFF.

 

When I use seed 0x0FFFF and plynomial 0x8005 for first sequence --> 80 01 11 (all except STX) I get result 1F 94 insted 65 82

1.PNG

 

When I use seed 0x0FFFF and plynomial 0x1021 for first sequence --> 80 01 11 I get result 1F 94 insted 65 82

2.PNG

 

With polynomial  0xA001 the result is B1 B4

With polynomial  0xC002 the result is 6A 2B 

 

(http://en.wikipedia.org/wiki/Polynomial_representations_of_cyclic_redundancy_checks)

 

Any idea why?

 

0 Kudos
Message 4 of 18
(6,873 Views)

This would not be the first time I ran across some "Documentation" of a CRC calculation that diverged between what the tech writer wrote and what the firmware engineer actually implemented in both sides of the code he used to validate his CRC implementation was correct.  (guess what? it wasn't but the code worked and it sort of looked like a CRC to him)

 

This gets painful fast and you are going to need to see an example of a working algorithym and duplicate it.


"Should be" isn't "Is" -Jay
0 Kudos
Message 5 of 18
(6,851 Views)

One problem that I can see is that you are converting every character in the string to a byte and NOT the numbers them self.

 

So a string of "80 01 11" will become 0x38, 0x30, 0x30, 0x31, 0x31 and 0x31.

0 Kudos
Message 6 of 18
(6,827 Views)
Solution
Accepted by topic author SuperbrainBug

This seems to work...


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 7 of 18
(6,821 Views)

@crossrulz wrote:

This seems to work...


I have no Idea how you reverse engineerd that!  no XOR between Data In[i] and Remainder Polynomial.  Yeah, that's not a "CRC" in a strict sense.  but probably what got implemented.

 

My hats off to you my friend 


"Should be" isn't "Is" -Jay
0 Kudos
Message 8 of 18
(6,808 Views)
There are a variety of potential algorithms for accomplishing the same mathematical operation -- including one that optimizes operation by generating a lookup table of intermediate values...

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 9 of 18
(6,802 Views)

@mikeporter wrote:
There are a variety of potential algorithms for accomplishing the same mathematical operation -- including one that optimizes operation by generating a lookup table of intermediate values...

Mike...

Yeah,  but this isn't one of those methods that generate the same result.


"Should be" isn't "Is" -Jay
0 Kudos
Message 10 of 18
(6,796 Views)