Generating Checksums for Send Sequences (Scripting)

Top  Previous  Next

Many communication protocols include additional checksum fields to ensure data integrity and detect transmission errors. A common algorithm is the CRC (Cyclic Redundancy Code) method, which is used in different variations for different protocols. The following step-by-step example describes how to implement a checksum algorithm, and how to define Send Sequences with a simple checksum that is calculated on-the-fly.

 

TIP: For a working example to address a MODBUS slave device, see the step-by-step tutorial Sending MODBUS commands with CRC-16 checksum.

 

Preconditions

 

You need a specification for your protocol messages, in particular the message length, the position of the checksum / CRC bytes, and how the checksum is calculated.

 

Defining Send Sequences that include a checksum

 

1.Create a new Send Sequence. Enter a Name for the sequence.
2.Enter the data part of your message in the Sequence section. We use a very simple message as an example here:

01 | 02 | 03 | 04 | 05

3.Now add one or several additional HEX 00 value(s) as a placeholder for the checksum. In our example, we choose a single byte checksum at the end of the sequence:

01 | 02 | 03 | 04 | 05 | 00

4.Click OK to add the new sequence to the Send Sequence list.

 

Repeat steps 1 - 4 to define other commands needed to perform your test.

 

5.Define your checksum algorithm inside a DL_OnSend() procedure of a Docklight script. See the DL_OnSend() Example for a simple one byte checksum.

 

TIP: CRC checksums are especially easy to implement using Docklight Scripting's CRC functionality. See the DL.CalcChecksum method for details.

 

Performing the test

 

1. Choose Scripting > Startscript_new Run Script to enable the checksum calculation.

2. Use the Pt_Send_Button Send button to send one of the predefined commands.

 

Docklight now executes the DL_OnSend() procedure code which calculates the actual checksum and overwrites the "00" placeholder with the checksum value. For our simple example command defined above, and the checksum algorithm from the DL_OnSend() Example, the transmitted sequence looks like this:

 

8/29/2008 21:07:23.251 [TX] - 01 02 03 04 05 0F

 

The placeholder has been replaced by the sum over the message bytes: 1 + 2 + 3 + 4 + 5 = 15 or HEX 0F