Example Code

Checksum generator XOR 8 bit, 8 bit sum, LRC 8 bit, 16 bit sum, Modbus 16 bit CRC

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW 2014

    Operating System

  • Windows

Code and Documents

Attachment

Description

The checksum generator is a sub vi that accepts a text and returns the checksum of the text

 

The following checksums are supported:

 

0: XOR of characters (8 bit)
1: Modulo 100h of sum of characters (8 bit sum)
2: LRC (8 bit), 256 - Modulo 100h of sum of characters
3: Modulo 10000h of sum of characters (16 bit sum)
4: MODBUS 16 bit CRC

photo.jpg

Using the vi:

  1. Add the sub vi to your vi
  2. Call the sub vi with a text in String and specify type of checksum in Type where Type is a number from 0 to 4, see above
  3. Check Invert if you want to invert the checksum, that is negate all bits
  4. The sub vi outputs the checksum as a 2 byte (8 bit checksum) or 4  byte (16 bit checksum) hex number in the string Checksum hex. It also outputs the checksum as 1 or 2 ASCII characters in the string Checksum dec

You can add more checksum methods by expanding the outer case structure. If your checksum will include more than 16 bits you must add a case to the string conversion case on the right and let the case be called by the number of bytes in the checksum

 

An older version of the vi is used in my String inspector, https://forums.ni.com/t5/Example-Code/Inspect-strings-compute-and-add-checksums-add-non-printable/ta...

 

 

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Contributors