11-29-2011 05:12 AM
Hi to all, i tryied to find an answer on how to calculate the CRC on a RS232 packet received, its really driving me crazy!
im a newby, learnt how to use labview reading on different forums, and i had managed to design really good apps, but im stucked in this, hope some one can help me...
ok, so im receiving 15byte packets constantly:
A5 09 0C 00 3F 61 05 1E 10 A0 00 05 00 04 05
A5 09 0C 00 3F 61 05 1E 10 A0 00 05 0C 2F 03
A5 09 0C 00 3F 61 05 1E 10 A0 09 05 09 04 09
the provider for the hardware gave me the following code to calculate the CRC:
CRC Check Program:
#define unsigned char uchar
uchar CRC_Bitwise8(uchar *buf, uchar size)
{
uchar i,j,b;
uchar crc=0;
for (j=0;j<size;j++)
{
b=*buf++;
for (i=0;i<8;i++)
{
if(((crc^b)&0x01)!=0)
crc^=0x18;
crc>>=1;
b>>=1;
}
}
return crc;
}
so my question is, how can i insert this code in labview? any example?
thanks in advance, this forums really helped me learn labview in a practical manner!
Solved! Go to Solution.
11-29-2011 07:19 AM
Do a search, there are numerous threads disussing this topic and lots of examples available
Christian
11-29-2011 08:32 AM
thanks, but searching didnt gave me any clue, it seems im really a starter in CRC calculation, and i really dont understand much how to calulate from the formula i wrote above.
can someone help me on this? i just need it in order to read from a sensor correctly.
thanks!
11-29-2011 08:39 AM
You find all the information about CRC online, e.g. here and there are lots of LabVIEW examples available.
Christian
11-29-2011 09:08 AM
thanks again christian, im studying those examples, but im confused as how to know and translate the code i wrote above in order to know what type of CRC calculation i need to make, or how to translate it to LV
many thanks!
11-29-2011 09:29 AM
11-29-2011 09:50 AM
LabVIEW has all of the same programming primitives (loops, logical operators, comparisons, etc.) used in the above piece of code. You simply have to pick the pieces apart and write them using native LabVIEW constructs. If you are that unfamiliar with LabVIEW itself I suggest going through the online tutorials to help familiarize yourself with the basics.
11-29-2011 10:03 AM
Thanks Mark, im studying lots of labview tutorials, and i really learnt a lot from them!
just the code above to calculate CRC is really getting me crazy, i really cant understand how to calculate crc on the packets received and its really frustrating.
if someone can help me understand how to calculate CRC in Labview from the above code i will really apprecieate it! or just a hint, i really dont know from where to start!
thanks!
11-29-2011 10:21 AM
What is the device? Is the manula online somewhere? I have a CRC package I posted in this thread that is very flixible and should handle what you need. However, you need to know which bytes in your message are included in the CRC calculation.
11-29-2011 10:30 AM
You can use my code from the thread I referenced. To play with a web version of my code go here. My code is based off the code on that website.
For my code, you will need the following settings:
CRC Calculation: Other (specify)
CRC Order: 8
CRC Polynomial: 0x30
Initial CRC Value: 0
Final CRC XOR Value: 0
Reflect Data Preprocessing: TRUE
Reflect Data Before Final XOR: TRUE
In your messages, the A5 09 0C is definitely a header. I think the following 00 is also part of the header, but without the manual, I cannot confirm. 00 will not affect the CRC calculation, so I get the same reuslts with it and without it. So, in your first example, I use 3F 61 05 1E 10 A0 00 05 00 04 and the result is 0x05.