Modbus is a communication protocol developed by Modicon (now Schneider Automation) and was initially for use with their own PLC Programmable Logic Controllers. Its originators maintain the protocol specification, independently of any professional body or association.
The protocol defines a message structure and format, and determines how a slave will recognize messages sent to it by the master. Standardization of these elements means that Modbus devices from different manufacturers can be interconnected, without the need for specialized software drivers.
Modbus controllers communicate using a master-slave technique, in which only one device (the master) can initiate a communication sequence.
The sequence begins with the master issuing a request or command on the bus (a 'query'), which is received by the slaves.
The slaves respond by taking appropriate action, supplying requested data to the master or informing the master that the required action could not be carried out. The master can address individual slaves or can transmit a message to be received by all slaves through a broadcast message. The response confirms that the message was received, understood and acted upon, or it informs the master that the action required could not be carried out.
If the query requests data from the slave, this will be returned as part of the response. Messages broadcasted to all slaves do not require responses.
Modbus slaves will only transmit on the network when required to do so by the master. Slaves never transmit unsolicited messages.
If the slave cannot carry out the requested action, then it will respond with an error message. This error message, known as an exception response, indicates to the master:
- the address of the responding slave
- the action it was requested to carry out
- an indication of why the action could not be completed
If the slave identifies an error during receipt of the message, the message will be ignored. This ensures that a slave does not take actions that was intended for another slave, and does not carry out actions other than those it is commanded to. Should, for some reason, the message be ignored, the master will know that it's query has not been received correctly, as it has not received a response, and will resend it.
Modbus does not specify how numerical data shall be encoded within a message. This is decided by the equipment manufacturer and a wide range of options are available.
Modbus ports frequently employ RS232-C compatible serial interfaces, although RS422/RS485 interfaces are also used. The type of interface used defines the connector pin-outs, the cabling and the signal levels; these are not defined in Modbus. Transmission rates and parity checking are not defined either and will depend on the serial interface used and the options made available by the manufacturer of each individual Modbus device.
Modbus supports up to 247 slaves from addresses 1 to 247 (JBUS 1 to 255), address 0 is reserved for broadcast messages. In practice, the number of slaves that can be used is determined by the physical communication link that is chosen. For example RS485 is limited to a total of 31 slaves.
The query-response cycle forms the basis of all communication on a Modbus network. In all situations it is the master that initiates the query and the slave that responds.
The query is mode up of four parts: 1. the device address; 2. the function code; 3. eight bit data bytes; 4. and an error check.
A slave will normally be required to provide a response (when a query has been addressed to that slave specifically, and not broadcast to all slaves), which will have the same overall structure format as was used for query.
There are two modes available for transmitting serial data over a Modbus network RTU and ASCII. The two transmission modes differ in a number of ways: the way that the bit contents of the message are defined, the way that information is packed into the message fields, the way it will be decoded and the speed of operation at a given baud rate. They cannot be used together and the mode used must be adopted by all the Modbus devices throughout the network.
The Remote Terminal Unit RTU mode is faster and more robust than ASCII and it is for these reasons that it is widely used in Modbus interfaces.