Table of Contents

lamaPLC Communication: Modbus

Modbus logo Not to be confused with M-Bus!

Modbus is a data communications protocol first released by Modicon (now Schneider Electric) in 1979 for use with its programmable logic controllers (PLCs). It has become a standard communication protocol and is now a widely used way to connect industrial electronic devices.

Modbus is widely used in industrial settings because it is openly published and free of royalties. It was designed for industrial use, is easier to deploy and maintain than other standards, and imposes few restrictions on the data format.

The Modbus protocol uses serial character communication lines, Ethernet, or the Internet protocol suite as a transport layer. Modbus supports communication with multiple devices connected to the same cable or Ethernet network. For example, a device that measures temperature and another that measures humidity can be connected to the same cable, both transmitting data to the same computer via Modbus.

Modbus is commonly used to connect a plant or system supervisory computer with a remote terminal unit (RTU) in supervisory control and data acquisition (SCADA) systems. Many data types are named based on industrial control of factory devices, such as ladder logic because of its role in operating relays: a single-bit physical output is called a coil, and a single-bit physical input is called a discrete input or contact.

The development and updates of the Modbus protocols have been overseen by the Modbus Organization since April 2004, when Schneider Electric transferred rights to that organization. The Modbus Organization is a group of users and suppliers of Modbus-compatible devices that support the ongoing use of the technology. Modbus Organization, Inc. is a trade association dedicated to promoting and developing the Modbus protocol.

Modbus TCP

Modbus TCP/IP or Modbus TCP – a Modbus variant used for communications over TCP/IP networks, connecting over port 502. It does not require a checksum calculation, as lower layers already provide checksum protection.

Important: Modbus over TCP/IP, Modbus over TCP, or Modbus RTU/IP – a variant that differs from Modbus TCP in that a checksum is included in the payload, as with Modbus RTU.

Modbus RTU

Modbus RTU (Remote Terminal Unit) – used in serial (typically RS485 2W-cabling or RS-232) communication, and is the most common implementation available for Modbus. Modbus RTU uses a compact binary representation of data for protocol communication.

The RTU format uses a cyclic redundancy check (CRC) to verify data integrity. A Modbus RTU message must be transmitted continuously without delays between characters. Modbus messages are separated by idle (silent) periods.

Limitations

Modbus Monomaster

Modbus Multimaster

Modbus Object Types and Addresses

Object typeAccessSizeOriginal address spaceExtended addressing*
CoilRead-write1 bit00001 – 09999000001-065535
Discrete inputRead-only1 bit10001 – 19999100001-165535
Input registerRead-onlyword (16 bits)30001 – 39999300001-365535
Holding registerRead-writeword (16 bits)40001 – 49999400001-465535


*: for example, with Simatic

Modbus Function Codes

The Modbus protocol defines several function codes for accessing registers. It specifies four different data blocks, and the addresses or register numbers in each overlap. Therefore, fully identifying a piece of data requires both the address (or register number) and the function code (or register type).

Most manufacturers only implement the “common” function codes, so you should always verify which codes are compatible with the specific equipment.

Function CodeRegister Typefrequency
1Read Coilcommon
2Read Discrete Inputcommon
3Read Holding Registerscommon
4Read Input Registerscommon
5Write Single Coilcommon
6Write Single Holding Registercommon
15Write Multiple Coilscommon
16Write Multiple Holding Registersrare
21Write File recordrare
22Mask Write Registerrare
23Read/Write Multiple Registersrare
24Read FIFO queuerare
8Diagnosticrare
11Get Com event counterrare
12Get Com Event Lograre
17Report Slave IDrare
43Read device Identificationrare
43CANopen General Referencerare

Exception codes

The exception codes as explained in the Modbus specification are:

Exception Code Name Meaning
01
(01 hex)
Illegal
Function
The function code received in the query is not a valid action for the slave. This could be because the function code is only supported on newer devices and was not implemented on the selected unit. It might also mean that the slave is in an incorrect state to handle this type of request, for example, if it is unconfigured and asked to return register values. If a Poll Program Complete command was issued, this code indicates that no program function was executed beforehand.
02
(02 hex)
Illegal Data Address The data address received in the query is not a valid address for the slave. Specifically, the combination of reference number and transfer length is invalid. For a controller with 100 registers, a request with offset 96 and length 4 will succeed, but a request with offset 96 and length 5 will generate exception 02.
03
(03 hex)
Illegal Data Value A value found in the query data field is not an acceptable value for the slave. This suggests a fault in the structure of the rest of a complex request, such as an incorrect implied length. It specifically does NOT mean that a data item submitted for storage in a register has a value outside what the application program expects, since the MODBUS protocol does not recognize the significance of any specific value in any register.
04
(04 hex)
Slave Device Failure An unrecoverable error occurred while the slave was attempting to perform the requested action.
05
(05 hex)
Acknowledge

The slave has accepted the request and is processing it, but it will take a long time to complete. This response prevents a timeout error from occurring in the master. The master can then send a Poll Program Complete message to check if processing is finished. |

06
(06 hex)
Slave Device Busy Specialized use with programming commands.
The slave is processing a long-duration program command. The master should retransmit the message later when the slave is free.
07
(07 hex)
Negative Acknowledge The slave cannot execute the program function received in the query. This code is sent back for an unsuccessful programming request using function code 13 or 14 decimal. The master should request diagnostic or error information from the slave.
08
(08 hex)
Memory Parity Error Specialized use with function codes 20 and 21 and reference type 6 to indicate that the extended file area failed a consistency check.
The slave attempted to read extended memory or record file but detected a parity error in memory. The master can retry the request, but service might be needed on the slave device.
10
(0A hex)
Gateway Path Unavailable Specialized use with gateways indicates that the gateway was unable to allocate an internal communication path from the input port to the output port for processing the request. Usually, this means the gateway is misconfigured or overloaded.
11
(0B hex)
Gateway Target Device Failed to Respond Specialized use with gateways indicates that no response was received from the target device. Usually, it means that the device is not on the network.

Sources

Wikipedia (here)
MODBUS over Serial Line Specification & Implementation guide V1.0 here


Modbus topics on lamaPLC

PageDateTags
2023/05/26 15:15, , , ,
2024/11/18 21:46, , , , , , ,
2024/11/18 21:55, , , , , , ,
2025/11/19 21:42, , , , , , , , ,
2025/11/23 21:24, , , , , , , ,
2025/03/07 09:20, , , ,
2024/08/18 14:48, , , ,
2025/09/23 19:08, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
2025/12/10 15:22, , , , , , ,
2024/11/18 17:55, , , , , , , ,
2023/06/24 22:42, , , , , , , , , ,
2023/06/19 21:24, , , , , , , , , , , , ,
2025/11/13 21:50, , , , , , , , ,
2025/11/13 22:42, , , , ,
2023/06/24 22:43, , , , , ,
2024/12/06 22:10, , , , , , ,
2024/08/18 14:52, , , , , , ,
2023/06/01 11:49, , ,
2026/01/22 20:43, , , , , ,
2025/11/13 22:59, , , , , , , , , , , , , , , ,
2023/06/17 19:43, , , , ,
2023/06/01 11:45, , , , , , ,



This page has been accessed for: Today: 7, Until now: 373