Modbus standards or buses include:8
To support Modbus communication on a network, many modems and gateways incorporate proprietary designs (refer to the diagram: Architecture of a network for Modbus communication). Implementations may deploy either wireline or wireless communication, such as in the ISM radio band, and even Short Message Service (SMS) or General Packet Radio Service (GPRS).
Modbus defines client which is an entity that initiates a transaction to request any specific task from its request receiver.9 The client's "request receiver", which the client has initiated the transaction with, is then called server.10 For example, when a Microcontroller unit (MCU) connects to a sensor to read its data by Modbus on a wired network, e.g RS485 bus, the MCU in this context is the client and the sensor is the server. In former terminology, the client was named master and the server named slave.
Modbus defines a protocol data unit (PDU) independently to its lower layer protocols in its protocol stack. Mapping MODBUS protocol on specific buses or networks requires some additional fields, defined as the application data unit (ADU). The ADU is formed by a client inside a Modbus network when the client initiates a transaction. Contents are:11
The ADU is officially called a Modbus frame by the Modbus Organization,12 although frame is used as the data unit in the data-link layer in the OSI and TCP/IP model (while Modbus is an application layer protocol).
PDU max size is 253 bytes. ADU max size on RS232/RS485 network is 256 bytes, and with TCP is 260 bytes.13
For data encoding, Modbus uses a big-endian representation for addresses and data fields. Thus, for a 16-bit value, the most significant byte is sent first. For example, when a 16-bit register has value 0x1234, byte 0x12 is sent before byte 0x34.14
Function code is 1 byte which gives the code of the function to execute. Function codes are integer values, ranging from 1 to 255, and the range from 128 to 255 is for exception responses.
The data field of the PDU has the address from 0 to 65535 (not to be confused with the address of the Additional address field of ADU).15 The data field of the PDU can be empty, and then has a size of 0. In this case, the server will not request any information and the function code defines the function to be executed. If there is no error during the execution process, the data field of the ADU response from server to client will include the data requested, i.e. the data the client previously received. If there is any error, the server will respond with an exception code.16
A Modbus transaction between client and server includes:1718
Based on that, Modbus defines 3 PDU types:19
Modbus defines its data model based on a series of tables of four primary types:22
For each of the primary tables, the protocol allows individual selection of 65536 data items, and the operations of read or write of those items are designed to span multiple consecutive data items up to a data size limit which is dependent on the transaction function code.24
Modbus defines three types of function codes: Public, User-Defined and Reserved.25
Note: Some sources use terminology that differs from the standard; for example Force Single Coil instead of Write Single Coil.26
Function code 01 (read coils) allows reading the state from 1 to 2000 coils of a remote device. mb_req_pdu (request PDU) will then have 2 bytes to indicate the address of the first coil to read (from 0x0000 to 0xFFFF), and 2 bytes to indicate the number of coils to read. mb_req_pdu defines coil address by index 0, i.e the first coil has address 0x0. On a successful execution, mb_rsp_pdu will return one byte to note the function code (0x01), followed by one byte to indicate the number of data bytes it is returning (n), which will be the number of coils requested by mb_req_pdu, divided by 8 bits per byte, and rounded up. The remainder of the response will be the specified number (n) of data bytes.27 That is, the mb_req_pdu and mb_rsp_pdu of function code 01 will take the following form:28
For instance, mb_req_pdu and mb_rsp_pdu to read coils status from 20-38 will be:29
User-Defined Function Codes are function codes defined by users. Modbus gives two range of values for user-defined function codes: 65 to 72 and 100 to 110. Obviously, user-defined function codes are not unique.30
Reserved Function Codes are function codes used by some companies for legacy product and are not available for public use.31
When a client sends a request to a server, there can be four possible events for that request:32
Exception response message includes two other fields when compared to a normal response message:33
All Modbus exception code:34
Modbus standard also defines Modbus over Serial Line, a protocol over the data link layer of the OSI model for the Modbus application layer protocol to be communicated over a serial bus.35 Modbus Serial Line protocol is a master-slave protocol which supports one master and multiple slaves in the serial bus.36 With Modbus protocol on the application layer, client/server model is used for the devices on the communication channel. With Modbus over Serial Line, client's role is implemented by master, and the server's role is implemented by slave.3738
The organization's naming convention inverts the common usage of having multiple clients and only one server. To avoid this confusion, the RS-485 transport layer uses the terms "node" or "device" instead of "server", and the "client" is not a "node".39
The (Modbus Organization) is using "client-server" to describe Modbus communications, characterized by communication between [client device (s), which initiates communication and makes requests of server device(s), which process requests and return an appropriate response (or error message).
A serial bus for Modbus over Serial Line can have a maximum of 247 slaves communicating with one master. Those slaves have a unique address ranging from 1 to 247 (decimal value).40 The master doesn't need to have an address.41 The communication process is initiated by the master, as only it can initiate a Modbus transaction. A slave will never transmit any data or perform any action without a request from the master, and slaves cannot communicate with each other.42
In Modbus over Serial Line, the master initiates requests to the slaves in unicast or broadcast modes. In unicast mode, the master will initiate a request to a single slave with a specific address. Upon receiving and finishing the request, the slave will respond with a message to the master.43 In this mode, a Modbus transaction includes two messages: one request from the master and one reply from the slave. Each slave must have a unique address (from 1 to 247) to be addressed independently for the communication.44 In broadcast mode, the master can send a request to all the slaves, using the broadcast address 0,45 which is the address reserved for broadcast exchanges (and not the master address). Slaves must accept broadcast exchanges but must not respond.46 The mapping of PDU of Modbus to the serial bus of Modbus over Serial Line protocol results in Modbus Serial Line PDU.47
Modbus Serial Line PDU = Address + PDU + CRC (or LRC)
With PDU = Function code + data
On the physical layer, MODBUS over Serial Line performs its communication on bit by RS485 or RS232, with TIA/EIA-485 Two-Wire interface as the most popular way. RS485 Four-Wire interface is also used. TIA/EIA-232-E (RS232) can also be used but is limited to point-to-point short-range communication.48 MODBUS over Serial Line has two transmission modes RTU and ASCII which are corresponded to two versions of the protocol, known as Modbus RTU and Modbus ASCII.49
Modbus RTU (Remote Terminal Unit), which is the most common implementation available for Modbus, makes use of a compact, binary representation of the data for protocol communication. The RTU format follows the commands/data with a cyclic redundancy check checksum as an error check mechanism to ensure the reliability of data. A Modbus RTU message must be transmitted continuously without inter-character hesitations. Modbus messages are framed (separated) by idle (silent) periods. Each byte (8 bits) of data is sent as 11 bits:5051
The default is even parity, while odd or no parity may be implemented as additional options.52
A Modbus RTU frame then will be:53
The CRC calculation is widely known as CRC-16-MODBUS, whose polynomial is x16 + x15 + x2 + 1 (normal hexadecimal algebraic polynomial being 8005 and reversed A001).54
Example of a Modbus RTU frame in hexadecimal: 01 04 02 FF FF B8 80 (CRC-16-MODBUS calculation for the 5 bytes from 01 to FF gives 80B8, which is transmitted least significant byte first).
To ensure frame integrity during the transmission, the time interval between two frames must be at least the transmission time of 3.5 characters, and the time interval between two consecutive characters must be no more than the transmission time of 1.5 characters.55 For example, with the default data rate of 19200 bit/s, the transmission times of 3.5 (t3.5) and 1.5 (t1.5) 11-bit characters are:
t 3.5 = 3.5 ∗ ( 11 ∗ 1000 19200 ) = 2.005 m s {\displaystyle t3.5=3.5*\left({\frac {11*1000}{19200}}\right)=2.005ms}
t 1.5 = 1.5 ∗ ( 11 ∗ 10 6 19200 ) = 859.375 μ s {\displaystyle t1.5=1.5*\left({\frac {11*10^{6}}{19200}}\right)=859.375\mu s}
For higher data rates, Modbus RTU recommends to use the fixed values 750 μs for t1.5 and 1.750 ms for t3.5.56
Modbus ASCII makes use of ASCII characters for protocol communication. The ASCII format uses a longitudinal redundancy check checksum. Modbus ASCII messages are framed by a leading colon (":") and trailing newline (CR/LF).
A Modbus ASCII frame includes:57
Address, Function, Data, and LRC are ASCII hexadecimal encoded values, whereby 8-bit values (0–255) are encoded as two human-readable ASCII characters from the ranges 0–9 and A–F. For example, a value of 122 (7A16) is encoded as two ASCII characters, "7" and "A", and transmitted as two bytes, 55 (3716, ASCII value for "7") and 65 (4116, ASCII value for "A").
LRC is calculated as the sum of 8-bit values (excluding the start and end characters), negated (two's complement) and encoded as an 8-bit value. For example, if Address, Function, and Data are 247, 3, 19, 137, 0, and 10, the two's complement of their sum (416) is −416; this trimmed to 8 bits is 96 (256 × 2 − 416 = 6016), giving the following 17 ASCII character frame: :F7031389000A60␍␊. LRC is specified for use only as a checksum: because it is calculated on the encoded data rather than the transmitted characters, its 'longitudinal' characteristic is not available for use with parity bits to locate single-bit errors.
Modbus TCP or Modbus TCP/IP is a Modbus variant used for communications over TCP/IP networks, connecting over port 502.58 It does not require a checksum calculation, as lower layers already provide checksum protection.
Modbus TCP nomenclature is the same as for the Modbus over Serial line protocol, as any device which send out a Modbus command, is the 'client' and the response comes from a 'server'.59
The ADU for Modbus TCP is officially called Modbus TCP/IP ADU by the Modbus organization60 and is also called Modbus TCP frame by other parties.61
MODBUS TCP/IP ADU = MBAP Header + Function code + Data
Where MBAP - which stands for MODBUS Application Protocol header - is the dedicated header used on TCP/IP to identify the MODBUS Application Data Unit.
The MBAP Header contains the following fields:62
Unit identifier is used with Modbus TCP devices that are composites of several Modbus devices, e.g. Modbus TCP to Modbus RTU gateways. In such a case, the unit identifier is the Server Address of the device behind the gateway.
A MODBUS TCP/IP ADU/Modbus TCP frame format then will be:6364
12 34 00 00 00 06 01 03 00 01 00 01
Besides the widely used Modbus RTU, Modbus ASCII and Modbus TCP, there are many variants of Modbus protocols:
Data models and function calls are identical for the first four variants listed above; only the encapsulation is different. However the variants are not interoperable, nor are the frame formats.
Another de facto protocol closely related to Modbus appeared later, and was defined by PLC maker April Automates, the result of a collaborative effort between French companies Renault Automation and Merlin Gerin et Cie in 1985: JBUS. Differences between Modbus and JBUS at that time (number of entities, server stations) are now irrelevant as this protocol almost disappeared with the April PLC series, which AEG Schneider Automation bought in 1994 and then made obsolete. However, the name JBUS has survived to some extent.
JBUS supports function codes 1, 2, 3, 4, 5, 6, 15, and 16 and thus all the entities described above, although numbering is different:
MODBUS Application Protocol 2012, p. 2. - MODBUS Application Protocol (2012). Modbus application protocol specification V1.1b3 (PDF). The Modbus Organization. Retrieved 2023-10-10. https://modbus.org/docs/Modbus_Application_Protocol_V1_1b3.pdf ↩
MODICON, Inc. 1996, "Preface" - MODICON, Inc. (1996). Modicon Modbus Protocol Reference Guide/Modbus Over Serial Line (for legacy application only) (PDF). https://modbus.org/docs/PI_MBUS_300.pdf ↩
Drury, Bill (2009). Control Techniques Drives and Controls Handbook (PDF) (2nd ed.). Institution of Engineering and Technology. pp. 508–. https://app.knovel.com/kn/resources/kpCTDCHE08/toc ↩
"Modbus FAQ". Modbus. Modbus Organization, Inc. Retrieved 1 November 2012. https://modbus.org/faq.php ↩
"About Modbus Organization". Modbus. Modbus Organization, Inc. Retrieved 8 November 2012. https://modbus.org/about_us.php ↩
MODBUS Application Protocol 2012, p. 4, "4.1 Protocol description" - MODBUS Application Protocol (2012). Modbus application protocol specification V1.1b3 (PDF). The Modbus Organization. Retrieved 2023-10-10. https://modbus.org/docs/Modbus_Application_Protocol_V1_1b3.pdf ↩
MODBUS Application Protocol 2012, p. 3, "4.1 Protocol description" - MODBUS Application Protocol (2012). Modbus application protocol specification V1.1b3 (PDF). The Modbus Organization. Retrieved 2023-10-10. https://modbus.org/docs/Modbus_Application_Protocol_V1_1b3.pdf ↩
MODBUS Application Protocol 2012, p. 5, "4.1 Protocol description" - MODBUS Application Protocol (2012). Modbus application protocol specification V1.1b3 (PDF). The Modbus Organization. Retrieved 2023-10-10. https://modbus.org/docs/Modbus_Application_Protocol_V1_1b3.pdf ↩
MODBUS Application Protocol 2012, p. 7, "4.4 MODBUS Addressing model" - MODBUS Application Protocol (2012). Modbus application protocol specification V1.1b3 (PDF). The Modbus Organization. Retrieved 2023-10-10. https://modbus.org/docs/Modbus_Application_Protocol_V1_1b3.pdf ↩
MODBUS Application Protocol 2012, p. 9, "Figure 9 MODBUS Transaction state diagram" - MODBUS Application Protocol (2012). Modbus application protocol specification V1.1b3 (PDF). The Modbus Organization. Retrieved 2023-10-10. https://modbus.org/docs/Modbus_Application_Protocol_V1_1b3.pdf ↩
MODBUS Application Protocol 2012, p. 6, "4.3 MODBUS Data model" - MODBUS Application Protocol (2012). Modbus application protocol specification V1.1b3 (PDF). The Modbus Organization. Retrieved 2023-10-10. https://modbus.org/docs/Modbus_Application_Protocol_V1_1b3.pdf ↩
"Modpoll Modbus Master Simulator". modbusdriver.com. Retrieved 2023-10-13"-t 0" is for "Discrete output (coil) data type"{{cite web}}: CS1 maint: postscript (link) https://www.modbusdriver.com/modpoll.html ↩
MODBUS Application Protocol 2012, p. 10, "5 Function Code Categories" - MODBUS Application Protocol (2012). Modbus application protocol specification V1.1b3 (PDF). The Modbus Organization. Retrieved 2023-10-10. https://modbus.org/docs/Modbus_Application_Protocol_V1_1b3.pdf ↩
Clarke, Gordon; Reynders, Deon (2004). Practical Modern Scada Protocols: Dnp3, 60870.5 and Related Systems. Newnes. pp. 47–51. ISBN 0-7506-5799-5. 0-7506-5799-5 ↩
MODBUS Application Protocol 2012, p. 11 - MODBUS Application Protocol (2012). Modbus application protocol specification V1.1b3 (PDF). The Modbus Organization. Retrieved 2023-10-10. https://modbus.org/docs/Modbus_Application_Protocol_V1_1b3.pdf ↩
MODBUS Application Protocol 2012, p. 12, "6.1 01 (0x01) Read Coils" - MODBUS Application Protocol (2012). Modbus application protocol specification V1.1b3 (PDF). The Modbus Organization. Retrieved 2023-10-10. https://modbus.org/docs/Modbus_Application_Protocol_V1_1b3.pdf ↩
MODBUS Application Protocol 2012, p. 47, "7 MODBUS Exception Responses" - MODBUS Application Protocol (2012). Modbus application protocol specification V1.1b3 (PDF). The Modbus Organization. Retrieved 2023-10-10. https://modbus.org/docs/Modbus_Application_Protocol_V1_1b3.pdf ↩
MODBUS Application Protocol 2012, p. 48, "7 MODBUS Exception Responses" - MODBUS Application Protocol (2012). Modbus application protocol specification V1.1b3 (PDF). The Modbus Organization. Retrieved 2023-10-10. https://modbus.org/docs/Modbus_Application_Protocol_V1_1b3.pdf ↩
MODBUS over Serial Line protocol 2006, p. 4 - MODBUS over Serial Line protocol (2006). MODBUS over Serial Line Specification & Implementation guide V1.02 (PDF). https://modbus.org/docs/Modbus_over_serial_line_V1_02.pdf ↩
MODBUS over Serial Line protocol 2006, p. 5 - MODBUS over Serial Line protocol (2006). MODBUS over Serial Line Specification & Implementation guide V1.02 (PDF). https://modbus.org/docs/Modbus_over_serial_line_V1_02.pdf ↩
"Modbus Organization Replaces Master-Slave with Client-Server (press release)" (PDF). modbus.org. 9 July 2020. Retrieved 11 July 2023. https://modbus.org/docs/Client-ServerPR-07-2020-final.docx.pdf ↩
MODBUS over Serial Line protocol 2006, p. 8 - MODBUS over Serial Line protocol (2006). MODBUS over Serial Line Specification & Implementation guide V1.02 (PDF). https://modbus.org/docs/Modbus_over_serial_line_V1_02.pdf ↩
MODBUS over Serial Line protocol 2006, p. 7 - MODBUS over Serial Line protocol (2006). MODBUS over Serial Line Specification & Implementation guide V1.02 (PDF). https://modbus.org/docs/Modbus_over_serial_line_V1_02.pdf ↩
MODBUS over Serial Line protocol 2006, p. 12 - MODBUS over Serial Line protocol (2006). MODBUS over Serial Line Specification & Implementation guide V1.02 (PDF). https://modbus.org/docs/Modbus_over_serial_line_V1_02.pdf ↩
MODBUS over Serial Line protocol 2006, p. 13, "2.5.1.1 MODBUS Message RTU Framing" - MODBUS over Serial Line protocol (2006). MODBUS over Serial Line Specification & Implementation guide V1.02 (PDF). https://modbus.org/docs/Modbus_over_serial_line_V1_02.pdf ↩
MODBUS over Serial Line protocol 2006, p. 39 - MODBUS over Serial Line protocol (2006). MODBUS over Serial Line Specification & Implementation guide V1.02 (PDF). https://modbus.org/docs/Modbus_over_serial_line_V1_02.pdf ↩
MODBUS over Serial Line protocol 2006, p. 17, "2.5.2.1 MODBUS Message ASCII Framing" - MODBUS over Serial Line protocol (2006). MODBUS over Serial Line Specification & Implementation guide V1.02 (PDF). https://modbus.org/docs/Modbus_over_serial_line_V1_02.pdf ↩
MODBUS Messaging on TCP/IP 2006, p. 6 - MODBUS Messaging on TCP/IP (2006). MODBUS Messaging on TCP/IP Implementation Guide V1.0b (PDF). Modbus Organization. https://www.modbus.org/docs/Modbus_Messaging_Implementation_Guide_V1_0b.pdf ↩
Prat, Jérôme (13 February 2017). "Crash Course: Client/Server/Master/Slave". ProSoft Technology. Retrieved 2022-10-17. https://www.prosoft-technology.com/insights/technology-focus/# ↩
MODBUS Messaging on TCP/IP 2006, p. 4, "3.1.2 MODBUS On TCP/IP Application Data Unit" - MODBUS Messaging on TCP/IP (2006). MODBUS Messaging on TCP/IP Implementation Guide V1.0b (PDF). Modbus Organization. https://www.modbus.org/docs/Modbus_Messaging_Implementation_Guide_V1_0b.pdf ↩
MODBUS Messaging on TCP/IP 2006, p. 5, "3.1.3 MBAP Header description" - MODBUS Messaging on TCP/IP (2006). MODBUS Messaging on TCP/IP Implementation Guide V1.0b (PDF). Modbus Organization. https://www.modbus.org/docs/Modbus_Messaging_Implementation_Guide_V1_0b.pdf ↩
"Java Modbus Library - About". 2010. Retrieved 2017-02-07. http://jamod.sourceforge.net ↩
"What is the difference between Modbus and Modbus Plus?". Schneider Electric. 21 August 2004. Retrieved 2017-02-07. https://www.se.com/ca/en/faqs/FA198221/ ↩
"Modbus Plus - Modbus Plus Network - Products overview - Schneider Electric United States". Schneider-electric.com. Retrieved 2014-01-03. https://www.se.com/us/en/product-range/576-modbus-plus/ ↩
"Simply Modbus - About Enron Modbus". Simply Modbus. Retrieved 2017-02-07. https://www.simplymodbus.ca/Enron.htm ↩
Palmer; Shenoi, Sujeet, eds. (23–25 March 2009). Critical Infrastructure Protection III. Third IFIP WG 11. 10 International Conference. Hanover, New Hampshire: Springer. p. 87. ISBN 978-3-642-04797-8. 978-3-642-04797-8 ↩