Kistler-Morse KM STXPlus User Manual

Page 55

Advertising
background image

APPENDIX C: MODBUS PROTOCOL SERIAL COMMANDS

The CRC is started by first preloading a 16-bit register to all 1’s. Then a process begins of
applying successive eight-bit bytes of the message to the current contents of the register. Only
the eight bits of data in each character are used for generating the CRC. Start and stop bits, and
the parity bit, do not apply to the CRC. During generation of the CRC, each eight-bit character
is exclusive ORed with the register contents. Then the result is shifted in the direction of the least
significant bit (LSB), with a zero filled into the most significant bit (MSB) position. The LSB is
extracted and examined. If the LSB was a 1, the register is then exclusive ORed with a preset,
fixed value. If the LSB was a 0, no exclusive OR takes place.

This process is repeated until eight shifts have been performed. After the last (eighth) shift, the
next eight-bit byte is exclusive ORed with the register’s current value, and the process repeats for
eight more shifts as described above. The final contents of the register, after all the bytes of the
message have been applied, is the CRC value. When the CRC is appended to the message, the
low-order byte is appended first, followed by the high-order byte.

Modbus PDU for serial line communication = 256 - Server address (1 byte) - CRC (2bytes) = 253
bytes.
The Modbus protocol defines three PDUs. They are:

• Modbus Request PDU, mb_req_pdu
• Modbus Response PDU, mb_rsp_pdu
• Modbus Exception Response PDU, mb_excep_rsp_pdu

The mb_req_pdu is defined as: mb_req_pdu = {function_code, request_data}, where:

function_code = [1 byte] Modbus function code corresponding to the desired Modbus
function code or requested through the client API
request_data = [n bytes] This field is function code dependent and usually contains
information such as variable references, variable counts, data offsets, sub-function codes etc.

The mb_rsp_pdu is defined as:
mb_rsp_pdu = {function_code, response_data}, where:

function_code = [1 byte] Modbus function code
response_data = [n bytes] This field is function code dependent and usually contains
information such as variable references, variable counts, data offsets, sub-function
codes, etc.

For additional information on the Modbus protocol, refer to the “Modbus Application Protocol
Specification “ which can be found on the www.modbus.org website.

C-2

Advertising