11-13-2009 01:23 PM
I have been given a CRC algorithim written in C for checking the packets of data coming down a serial link.
Have had a look on the forum and found examples of code suitable for CRC checking. Problem is that when I try the various Vi examples none give me the same result as that given by the one suggested by using C.
Pehaps I am missing something but from my dim and distant past I always thought that a fixed polynomial equation was used on each of the packets of data to arrive at a CRC value? If that assumption is correct then could that be why I do not get the same CRC value as the one given if implemented in the C example?
I have tried to execute the C code example but it failed on the compiler (it is just extracts of core code apparently) and I have hardly any knowledge of C so struggling to say the least.
11-16-2009 10:19 AM
Hi Jack,
This isn't something I've seen before but I would be more than happy to look into the issue with you, do you have the C code example you mention or the CRC type you are attempting under LabVIEW? Also which LabVIEW VI have you been using that gives you a different CRC result so I can take a look?
Thanks,
11-16-2009 11:05 AM
The link for CRC Vi is:- http://zone.ni.com/devzone/cda/epd/p/id/1568
and the C code I have been given for guidance is:-
First block of code:-
unsigned crc_table [256]
unsigned crc(unsigned char*buffer, unsigned count)
{
unsigned i;
unsigned c = 0;
for (i = 0; i<count; i++)
{
c = (c >> 😎 ^ crc_table[buffer[i] ^ (unsigned char)c];
}
return c;
Second block of code:-
void init_crc_table()
{
unsigned z,i;
for (i = 0, z = 0; i < 256; i++)
{
z = i ^ (i << 4);
crc_table [i] (z << 😎 ^ (z << 3) ^ (z >> 4);
}
}
It seems that a table is being created to run the packets of data through but really no idea.
The data given to confirm correct operation is a 10 Byte sequence:-
0xb0, 0x3b, 0x4f, 0xfa, 0x00, 0x55, 0x89, 0x4c, 0x01, 0x35 result should be CRC value of 0xf268 (MSB first)
Thanks Jack
11-17-2009 02:30 AM
Hi Jack,
Just so I can understand what is your core aim from this, to create a CRC in C that is the same as in LabVIEW, vice versa or doesn't it matter just so long as they match for C and LabVIEW with regards to the outcome? Looking at the C code you provided it looks like just a few of the functions and doesn't appear to match the LabVIEW one at all, for example the LabVIEW application has initial CRC values set, and then runs 8 times every interation of the packet length where as the C code you have provided runs for the value of "count" and then runs for 256 times per iteration of count. I know you mentined you were unable to get the code to execute but do you have any CRC-16 C code that runs (with source) to verify the behaviour?
Once we have one that works as you require it's just a case of transferring the logic to the other language.
Kind Regards,
11-17-2009 02:40 AM
Hi Rob
At the moment there is a main control program that I have written in Labview 8.6 to run/monitor a combustion engine.
I now need to access the engines ECU to obtain temps/pressures from it and this information is available in serial format.
The serial data has a CRC check tacked onto the end of it for conformation that the data is valid.
The information given on the structure of that CRC routine is the one I detailed earlier.
So basically I need to be able to implement in Labview a CRC routine that can perform the same operations on the serial data packets so I can integrate the CRC Labview code into my main program.
Thanks Jack
11-17-2009 04:25 AM
Hi Jack,
Thanks for the additional information, as the serial CRC is already created (from what I understand) do you know exactly which type it uses as CRC-16 has many variants?
Thanks,
11-17-2009 04:37 AM
Hi Rob
That's the main problem. I know of the wide variation in CRC Polynomials and have tried quite a few of them without success. When the question was asked all I was told was that the C Code was written to carry out this function and no polynomial was available.
Could the C code given generate a CRC result that has no relationship to the standard CRC-16?
Thanks
jack
11-17-2009 04:50 AM
Hi Jack,
Is it that they don't wish to give you the polynomial/know what it is or does the CRC actually not use a polynomial? As you can see from this link: http://en.wikipedia.org/wiki/Cyclic_redundancy_check#Commonly_used_and_standardized_CRCs the majority of CRC's have a polynomial associated with them, one that doesn't is Fletcher's Checksum however looking at the C Code you included this doesn't appear to be it.
Without knowing the type of CRC it is (as it may be one of there own) then this might be quite a challenge!
11-17-2009 05:07 AM
Hi Rob
Unsure if they do not know or as you say are unwilling to let me know. That's the same link where I found all of (or most) of the CRC codes from originally when I thought this was going to be a 5 minute job!
I will contact them today and see if I can get more detail. Its just that I thought there was something obvious in the C code given that would have revealed all, glad there was not in one way because I could not see anything and makes me feel better!!
Will let you know how I get on,
Thanks Jack
11-17-2009 05:19 AM