LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

CRC-16 CCITT Calculation

Solved!
Go to solution

I am needing help in generating a CRC-16 CCITT.  I have searched high and low and can't find the correct one.  Here is a list of the sites that I have accessed to try to find a LabVIEW VI to do the trick:

 

http://zone.ni.com/devzone/cda/epd/p/id/1660

https://decibel.ni.com/content/docs/DOC-1103

http://forums.ni.com/t5/LabVIEW/CRC-CCITT-16bit-Initial-Value-of-0xFFFF-or-0x1D0F/td-p/896664

http://forums.ni.com/t5/LabVIEW/CRC-16-CCITT-of-serial-packets/td-p/1471386

http://forums.ni.com/t5/LabVIEW/Trying-to-find-VI-in-Labview-to-calculate-CRC-CCITT-1021-X-25/td-p/1...

http://forums.ni.com/t5/LabVIEW/CRC-CCITT/td-p/109061

http://forums.ni.com/t5/LabVIEW/Computing-CRC/td-p/825325

 

Some of these even have multiple CRCs to choose from.

 

Now, what I DO have is a piece of C code.  And that is where I'm asking for help because I don't have a clue how to turn C into G.  And I'm certainly not sure just why this CRC is different from the "standard" ones found in the links above.

 

I have attached the .pdf file with the code.

 

Here are a few strings in hex and their corresponding CRCs:

 

String:  00 08                              CRC: 1D 07

String:  00 09                              CRC: 1D 06

String:  02 22 03 E8                     CRC:  E5 6A

String:  02 27 03 E8                     CRC:  B5 CF

String:  02 29 00 02                     CRC:  57 EB

String:  04 29 00 01 00 03            CRC:  CC 94

String:  02 3D 00 64                     CRC:  05 38

 

If there is anybody out there willing to give this a shot I would CERTAINLY appreciate it!!!

 

Paul.

 

 

0 Kudos
Message 1 of 30
(33,833 Views)

Where did you get the test cases you list?

 

There is a CCITT standard specifying the algorithm and what the results are to be for specific input datasets.

 

What are you trying to talk to?

 

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 2 of 30
(33,816 Views)

Your test list is not matching the code you gave, at least based on the comments of what your parameters should be.  Do you know what your CRC parameters are (polynomial, initial CRC, final XOR)?


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
0 Kudos
Message 3 of 30
(33,801 Views)

Gentlemen,

 

Thanks for your replies.  You may have to kinda shepherd me through some of this because I don't understand C at all.

 

So, on with the quest.....

 

To answer your questions:

 

1.  The example String and CRC values are direcly out of the user manual.  And they DO work because I can communicate with the unit.

 

2.  I am communicating with a ThingMagic M4e Passive RFID module.  I have used an RS-232 sniffer and a manufacturer supplied MS-DOS program to capture some of the codes that I use in LabVIEW VISA.  So, I've been able to get it to work.

 

I managed to find the "CrcUtils.c" called out in the manual.  Although I don't have a C complier on my machine, it does show in the view window and the code looks completely different from the attached PDF file that I included earlier.  I can attach the .c and .h files but it won't let me attach the crc.mk and the module.mk files.

 

Thanks so much for your help!!!

Paul.

Download All
0 Kudos
Message 4 of 30
(33,761 Views)
Solution
Accepted by topic author PaulB1310

Ah.  There's a small tweak in there that makes it different from the "standard" CRC.  How sneaky of them.  This code gives me the results you are looking for.


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 5 of 30
(33,739 Views)

crossulz,

 

Thanks for your help!!!

 

I have recreated the VI from the .png that you posted but I'm not getting the same answer.  I suspect there are two possibilities:  There is something in the false case that I can't see or the Data In array has some type of error in it since your array shows two bits per element and mine only shows one.  Seems like it shouldn't matter, but.........

 

I have attached my VI.

 

Thanks!!

 

Paul.

0 Kudos
Message 6 of 30
(33,719 Views)

It's a snippet.  You don't need to recreate it.

 

Just drag and drop the image from your browser into a block diagram.  Voila!  Code, including the case diagrams you can't see.

0 Kudos
Message 7 of 30
(33,717 Views)

That is a cool feature that I've not used.

 

However, you created the VI in LV 2013, right?

 

Could you post it in LV 2012?

 

Thanks,

Paul.

0 Kudos
Message 8 of 30
(33,712 Views)

Your problem is that you used the Rotate Right With Carry when you need the Rotate LEFT With Carry.  You need the MSB to be pulled out.


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 9 of 30
(33,699 Views)

Chiming in late here, but I've been following this thread with some interest.  I've coded a couple of different CRC implementations over the years in LabVIEW for different instruments, but none of my routines gave the results you quoted in your initial post.  When I saw Crossrulz's snippet, I first identified it as nearly identical in form to one I'd done - including the same polynomial mask - but on closer inspection his snippet (relative to my closest version) is missing an XOR operation outright, and doing an extra shift.

 

My go-to site for example code and a handy online CRC calculator is one published by Lammert Bies and none of the common implementations he lists match yours.  I'll admit I didn't take more than a cursory look through the .c file you posted, but clearly Crossrulz's snippet is a faithful G-code implementation of the one you need.

 

I just don't know what "standard" your device is claiming to be - but it certainly does *NOT* match CCITT.

 

Hey, whatever works!

 

Dave

 

 

 

 

David Boyd
Sr. Test Engineer
Abbott Labs
(lapsed) Certified LabVIEW Developer
Message 10 of 30
(33,695 Views)