beautypg.com

Appendix c: modbus protocol serial commands – Kistler-Morse KM STXPlus User Manual

Page 54

background image

APPENDIX C: MODBUS PROTOCOL SERIAL COMMANDS

APPENDIX C: MODBUS PROTOCOL SERIAL COMMANDS

INTRODUCTION

This appendix contains the serial commands and Modbus protocol syntax used for serial
communications between the host or Master (PLC or PC, etc.) and the STXplus. Detailed
explanations and examples of the commands are included. If any parameter or set of parameters
that are transmitted by the master are outside of the acceptable range an ‘N’ will be transmitted
back by the STXplus.

MODBUS IMPLEMENTATION

Modbus is a multipoint protocol. This means that one PC/PLC can communicate with multiple
devices on the same communication line. Due to this a given device must have a unique ID with
which to address it – a Modbus device address. A device’s device address MUST be unique on a
given communication network – duplicate addresses lead to bus collision.

Modbus Device

addresses must lie in the range 1 to 247 (1 Byte). The Modbus Device supports broadcast
addressing. On receiving a valid request from a PC/PLC with a valid device address, the device
replies the PC/PLC with an appropriate frame. The Modbus Device supports exception
response also.

Modbus is a request/reply protocol and offers services specified by function codes. The function
indicates what kind of action to perform. The Modbus application protocol establishes the format
of the request. The function code field of a Modbus data unit is coded in one byte. Valid codes
are in the range of 1 ... 255 decimal (128 – 255 reserved for exception responses). When a
message is sent the function code field tells what kind of action to perform. Function code “0” is
not valid. Sub-function codes are added to some function codes to define multiple actions. The
data field of messages sent contains additional information that can be used to take the action
defined by the function code. This can include items like discrete and register addresses, the
quantity of items to be handled, and the count of actual data bytes in the field. The data field may
be nonexistent (of zero length) in certain kinds of requests. In this case the function code alone
specifies the action. If no error occurs related to the Modbus function request the data field of a
response from a server to a client contains the data requested. If an error related to the Modbus
function request occurs, the field contains an exception code that the server application can use
to determine the next action to be taken. For a normal response, the device simply echoes to the
request the original function code. For an exception response, the server returns a code that is
equivalent to the original function code with its most significant bit set to logic 1.

The Modbus error-checking field contains a 16-bit value (2 Bytes).
The error check value is the result of a Cyclical Redundancy Check calculation performed on the
message contents. The CRC value is calculated by the transmitting device, which appends the
CRC to the message. The receiving device recalculates a CRC during receipt of the message,
and compares the calculated value to the actual value it received in the CRC field. If the two
values are not equal, an error results.

C-1