09-25-2013 10:15 PM
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/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.
Solved! Go to Solution.
09-26-2013 12:48 AM
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...
09-26-2013 07:08 AM
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)?
09-26-2013 08:01 PM
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.
09-27-2013 07:37 AM - edited 09-27-2013 07:38 AM
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.
09-27-2013 12:49 PM
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.
09-27-2013 01:15 PM
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.
09-27-2013 01:22 PM
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.
09-27-2013 04:54 PM
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.
09-27-2013 05:49 PM
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