01-13-2014 07:53 AM
Turn it into a subVI and call it. Pass in whatever data you need to into it. It is just like reusing any other piece of code.
12-02-2015 04:35 PM
Old thread, I know, but I'm looking at a similar problem...I need to turn the C routine below into a subvi. I've tried many different variations of many different solutions and cannot get the CRC shown in below to match. Does this make any sense to anyone here?
CRC is a 16-bit CRC of sync, address, command type, length, and data fields. The algorithm used is CCITT-16 (0x1021 or 0x8408 reversed).The remainder is initialized to all 1’s (0xFFFF) and the CRC is inverted before being sent, LSB first. (NOTE: Previous versions of this document specified MSB first, but actual implementations have been using LSB-first.) Following is a sample C routine which implements the algorithm using the “reversed” technique:
WORD crc16_lsb(BYTE *pData, WORD length)
{
BYTE i;
WORD data, crc;
crc = 0xFFFF;
if (length == 0)
return 0;
do
{
data = (WORD)0x00FF & *pData++;
crc = crc ^ data;
for (i = 8; i > 0; i--)
{
if (crc & 0x0001)
crc = (crc >> 1) ^ 0x8408;
else
crc >>= 1;
}
}
while (--length);
crc = ~crc;
return (crc);
}
For example, a Status Request command:
1b ff 91 00
Would generate the following CRC:
1c 39
12-03-2015 07:30 AM - edited 12-03-2015 07:30 AM
With the right parameters, this works perfectly with my standard CRC calculator.
12-03-2015 07:39 AM
Thanks, crossrulz. You're right, it works exactly as it should. You da man!
10-09-2018 03:32 AM
Hi,
I noticed that the marked solution is not the correct one, at least for me. If it is so for others as well, could someone please mark the correct reply as the solution? It is a bit misleading as it is.
So the correct one according to my tests iiis:
https://forums.ni.com/t5/LabVIEW/CRC-16-CCITT-Calculation/m-p/3224707/highlight/true#M937083
10-09-2018 04:06 AM - edited 10-09-2018 04:08 AM
@bela.komoroczy wrote:
Hi,
I noticed that the marked solution is not the correct one, at least for me. If it is so for others as well, could someone please mark the correct reply as the solution? It is a bit misleading as it is.
So the correct one according to my tests iiis:
https://forums.ni.com/t5/LabVIEW/CRC-16-CCITT-Calculation/m-p/3224707/highlight/true#M937083
I did mark that one as 2nd solutions. I can't unmark the other one. Not sure if a moderator can do that, or if only OP has the power to do that...
Not that helpful as it is, as there's no "go to next solution" button...
10-09-2018 06:20 AM
@bela.komoroczy wrote:
Hi,
I noticed that the marked solution is not the correct one, at least for me. If it is so for others as well, could someone please mark the correct reply as the solution? It is a bit misleading as it is.
That is part of the problem with people resurrecting old threads. The post that was originally marked as the solution was the solution for the OP. Somebody later resurrected the thread with a different problem.
10-09-2018 06:38 AM
@crossrulz wrote:
@bela.komoroczy wrote:
Hi,
I noticed that the marked solution is not the correct one, at least for me. If it is so for others as well, could someone please mark the correct reply as the solution? It is a bit misleading as it is.
That is part of the problem with people resurrecting old threads. The post that was originally marked as the solution was the solution for the OP. Somebody later resurrected the thread with a different problem.
I figured that was going on here (TL;DR).
Anyway, you have an extra solution, and I can't unmark it as solution anyway!
10-09-2018 07:30 AM
I see your point. Anyway, the "good" one is aslo marked, I hope it helps people like me.
10-24-2019 04:41 PM
I ran into this same problem several years ago. I am not a C programmer whereas I was given the C code that generated the CRC. I had a C program explain in detail what the C code was doing and I created a LabVIEW vi that worked. Once you understand what is being done in the C code, you will be able to reproduce the algorithm in LabVIEW.