MODBUS RTU With CRC checksum - Sample Project: ModbusRtuCrc.ptp

<< Click to Display Table of Contents >>

Navigation:  Examples and Tutorials >

MODBUS RTU With CRC checksum - Sample Project: ModbusRtuCrc.ptp

The Docklight project file ModbusRtuCrc.ptp demonstrates how to automatically calculate the CRC value required to send a valid MODBUS RTU frame.

 

The project file uses the communication settings listed below, according to the MODBUS implementation class "Basic".

 

Communication Mode

Send/Receive

Send/Receive on comm. channel

COM1

COM Port Settings

9600 Baud, Even parity, 8 Data Bits, 1 Stop Bit

 

Getting started

 

Open the project file ModbusRtuCrc.ptp (menu OPEN Open Project ...). The file is located in the \Samples folder.

Connect the PC's COM port to your MODBUS network. Open the PROPERTIES Project Settings... dialog and make sure you have selected the correct COM Port for Send/Receive on comm. channel.

Use the Pt_Send_Button Send button to read input register no. 1 from a slave.

Enter a slave number in the Send Sequence Parameter dialog, e.g. "01" for addressing slave no. 1.

 

After sending "Read Input Register" commands to slaves 1 - 4,  the communication window could look like this:

 

5/29/2015 18:45:23.193 [TX] - 01 04 00 00 00 01 31 CA

5/29/2015 18:45:23.342 [RX] - 01 04 02 FF FF B8 80

5/29/2015 18:45:33.145 [TX] - 02 04 00 00 00 01 31 F9

5/29/2015 18:45:33.292 [RX] - 02 04 02 27 10 E7 0C

5/29/2015 18:45:43.237 [TX] - 03 04 00 00 00 01 30 28

5/29/2015 18:45:43.392 [RX] - 03 04 02 00 00 C0 F0

5/29/2015 18:45:58.724 [TX] - 04 04 00 00 00 01 31 9F

5/29/2015 18:45:58.870 [RX] - 04 04 02 04 00 77 F0

 

The [RX] channel shows the responses from the MODBUS slaves:

slave 1 responded value "-1",

slave 2 responded "10000",

slave 3 responded "0" and

slave 4 responded "1024".

 

NOTE: If you are using the Docklight MODBUS example on a RS485 bus, you need to check if your RS485 hardware correctly switches between transmit and receive state. You might need to use Docklight's RS485 Transceiver Control feature.

 

Further Information

 

The CRC calculation is made according to the specifications for MODBUS serial line transmission (RTU mode). Docklight's checksum function supports a "CRC-MODBUS" model for this purpose. See Calculating and Validating Checksums for more general information on implementing checksum calculations.

If you do not have any MODBUS slave devices available, you can use a software simulator. See http://www.modbus.org, "Modbus Technical Resources", "MODBUS Serial RTU Simulator". This simulator was used to produce the sample data shown above.