software / rapidq / Examples / Algorithm & Maths / ModbusCRCcalc / Readme.txt

Search 搜索
Home Home

File...... ModbusCRCcalc.bas
Purpose... calculates a Modbus cyclic redundancy check (CRC)
Software.. Rapid-Q Basic
Author.... Brandon Tarr
Background:  Modbus is a popular RS-485 or RS-422 comunication protocal used extensivly in industrial automation.

Modbus Packet format: nn | nn | nnnn… | nnnn
address | command | registers and/or data | CRC

controller address (one byte)
read command (0x03)
starting register high byte
starting register low byte
number of registers high byte (0x00)
number of registers low byte
CRC low byte
CRC high byte

Example: if you would like to read register #0 of a controller on the network with an address of 1, you would need to send the following:  01 03 00 00 00 01 84 0A

This program calculates the CRC to append to the message i.e.

input:  010300000001
output: 0x0A84

Note that you must include the zeros in the string where necessary, and do not use any commas or spaces between values.  Also, you must reverse the MSB and LSB of the CRC, as per the Modbus standard, before you append the values to the end of the packet to be sent.
© Tue 2022-10-4  Guidance Laboratory Inc. Hits:0 Last modified:2004-03-22 09:38:46