|
MODBUS commands with a CRC checksum - Sample Script: ModbusCrcScript.pts |
|
|
The Docklight script ModbusCrcScript.pts and the accompanying project file ModbusCrcTest.ptp demonstrate how to use a Docklight script 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".
Getting started
Docklight now executes the DL_OnSend() procedure which calculates the actual CRC value and overwrites the last two Send Sequence bytes with the CRC low and high bytes.
After sending "Read Input Register" commands to slaves 1 - 4, the communication window could look like this:
8/29/2008 18:45:23.193 [TX] - 01 04 00 00 00 01 31 CA 8/29/2008 18:45:23.342 [RX] - 01 04 02 FF FF B8 80 8/29/2008 18:45:33.145 [TX] - 02 04 00 00 00 01 31 F9 8/29/2008 18:45:33.292 [RX] - 02 04 02 27 10 E7 0C 8/29/2008 18:45:43.237 [TX] - 03 04 00 00 00 01 30 28 8/29/2008 18:45:43.392 [RX] - 03 04 02 00 00 C0 F0 8/29/2008 18:45:58.724 [TX] - 04 04 00 00 00 01 31 9F 8/29/2008 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
|