LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Computing CRC

Highlighted

Data array is an array of U8 that replaces the string data.  Sometimes, I have the data in a string, somes in byte array, so instead of having to do conversions every time, I put it into the subvi.  If Data string is blank, then it uses Data Array.

 

Order is the bit order of the CRC, so is typically 8, 16, or 32.

 

Matthew

0 Kudos
Message 11 of 17
(1,798 Views)
Highlighted
Why does it have the bit order choice? You allready choose your CRC-algorithm (8-bit, 16-bit, CRC-CCITT etc) from another menu.
0 Kudos
Message 12 of 17
(1,789 Views)
Highlighted

The whole CRC Parameters cluster is only used when you set CRC Calculation to Other (specify).  If you look at the block diagram, there is a case statement that has preset values for CRC Parameters.  I give the user the ability to specify their own parameters.  For example, if you select CRC-16, CRC Order will be 16. CRC Polynomial will be 0x8005, Initial CRC Value will be 0, Final CRC XOR value will be 0, and both releflections will be enabled.  If you wanted to come up with your own, non-standard CRC, you can set the same values in the CRC Parameters Cluster, changing the polynomial to 0x8023, choose Other for CRC calculation and you will have a different CRC algorithm.

 

I actually have a customer who calimed to do standard CRC-16, but didn't (at least according to all the samples I could find).  Turns out they had both the reflections disnabled.

 

 

Message 13 of 17
(1,781 Views)
Highlighted

HI Matthew K,

 

I apprecaite all of the work you put into this VI.  I am trying to learn about the CRC-16 calculation and this VI is very helpful.  I do not fully understand the process though.  One basic question I have is what comprises the message, how many bytes should this be?  I have an example that uses the following command:

 

Slave Address: 05

Function Code: 10

Head Address, High byte:  00

Head Address, Low byte: 01

Access Count, High byte: 00

Access Count, Low byte: 02

Data Byte Count: 02

Data Value1, High byte: 00

Data Value 1, Low byte: 01

Data Value 2, High byte: 17

Data Value 2, Low byte: 70

CRC-16, low byte: 78

CRC-16, high byte: 87

 

My inital CRC value is FFFF, my polynomial is A001.  How do I calculate the CRC-16 value that should come out the other end?  I believe I am looking for a CRC-16 of 118C.  Any help will be greatly appreciated.

 

Thanks

0 Kudos
Message 14 of 17
(1,754 Views)
Highlighted

You need to look at the specification of the device you are communicating with.  Sometimes, not all bytes in the message are included in the CRC.  There is no preset number of bytes that have to be there.  In your example below, I could see that several of the bytes at the beginning may not be included.

 

Why do you think you should have 118C when your example lists it as 7887?

 

You can also get into some issues with little endian, big endian.  My customer that I referenced above had outsourced the deisgn of the module with that CRC-16.  Their documentation stated a standard CRC-16 on the MSB-first data.  The CRC should have been transmitted LSB first, along with the data.  Well, the developer must have made some invalid assumptions, because the CRC was calulated on LSB-first data and was transmitted MSB first, while the data was transmitted LSB first.

 

Do you have the specification of the CRC for the device you are trying to communicate with?  You could also be running into this issue that I had trying to find the correct CRC algorithm.  If they developed their own algorithm and assumed it was correct, they may not even be using a standard algorithm.

Message 15 of 17
(1,738 Views)
Highlighted
HI Mathew K.  Thanks for replying.  I had a very poor understanding of what I was trying to do when I wrote that post.  24 hours later and with some help from the forums the CRC generation is working.  I had thought that they had generated their own CRC algorithm, but that was do to the poor wording they used to describe it.  After trying and failing to implement it I was pointed in the correct direction in this post.  I appreciate your response.
0 Kudos
Message 16 of 17
(1,736 Views)
Highlighted

@Matthew_Kelton Thanks a lot - this is what I was looking for. For others looking for a CRC-16-IBM this is worthwhile to download as you can try a few options to find the one that works for your application. I needed an 8005 polynomial for my impelementation. He is a screenshot of Mathew's code for others 🙂

LabVIEW CRC.png

0 Kudos
Message 17 of 17
(833 Views)