Modbus
   HOME

TheInfoList



OR:

Modbus is a data
communications protocol A communication protocol is a system of rules that allows two or more entities of a communications system to transmit information via any kind of variation of a physical quantity. The protocol defines the rules, syntax, semantics and synch ...
originally published by Modicon (now
Schneider Electric Schneider Electric SE is a French multinational company that specializes in digital automation and energy management. It addresses homes, buildings, data centers, infrastructure and industries, by combining energy technologies, real-time automatio ...
) in 1979 for use with its
programmable logic controller A programmable logic controller (PLC) or programmable controller is an industrial computer that has been ruggedized and adapted for the control of manufacturing processes, such as assembly lines, machines, robotic devices, or any activity t ...
s (PLCs). Modbus has become a ''
de facto ''De facto'' ( ; , "in fact") describes practices that exist in reality, whether or not they are officially recognized by laws or other formal norms. It is commonly used to refer to what happens in practice, in contrast with '' de jure'' ("by l ...
'' standard communication protocol and is now a commonly available means of connecting industrial electronic devices. Modbus is popular in industrial environments because it is openly published and
royalty-free Royalty-free (RF) material subject to copyright or other intellectual property rights may be used without the need to pay royalties or license fees for each use, per each copy or volume sold or some time period of use or sales. Computer standard ...
. It was developed for industrial applications, is relatively easy to deploy and maintain compared to other standards, and places few restrictions on the format of the data to be transmitted. The Modbus protocol uses character serial communication lines,
Ethernet Ethernet () is a family of wired computer networking technologies commonly used in local area networks (LAN), metropolitan area networks (MAN) and wide area networks (WAN). It was commercially introduced in 1980 and first standardized in 1 ...
, or the
Internet protocol suite The Internet protocol suite, commonly known as TCP/IP, is a framework for organizing the set of communication protocols used in the Internet and similar computer networks according to functional criteria. The foundational protocols in the sui ...
as a transport layer. Modbus supports communication to and from multiple devices connected to the same cable or Ethernet network. For example, there can be a device that measures temperature and another device to measure humidity connected to the same cable, both communicating measurements to the same
computer A computer is a machine that can be programmed to carry out sequences of arithmetic or logical operations ( computation) automatically. Modern digital electronic computers can perform generic sets of operations known as programs. These prog ...
, via Modbus. Modbus is often used to connect a plant/system supervisory computer with a remote terminal unit (RTU) in supervisory control and data acquisition (
SCADA Supervisory control and data acquisition (SCADA) is a control system architecture comprising computers, networked data communications and graphical user interfaces for high-level supervision of machines and processes. It also covers sensors and o ...
) systems. Many of the data types are named from industrial control of factory devices, such as
ladder logic Ladder logic was originally a written method to document the design and construction of relay racks as used in manufacturing and process control. Each device in the relay rack would be represented by a symbol on the ladder diagram with connecti ...
because of its use in driving relays: a single-bit physical output is called a ''coil'', and a single-bit physical input is called a ''discrete input'' or a ''contact''. The development and update of Modbus protocols have been managed by the Modbus Organization since April 2004, when Schneider Electric transferred rights to that organization. The Modbus Organization is an association of users and suppliers of Modbus-compliant devices that advocates for the continued use of the technology. Modbus Organization, Inc. is a
trade association A trade association, also known as an industry trade group, business association, sector association or industry body, is an organization founded and funded by businesses that operate in a specific industry. An industry trade association partic ...
for the promotion and development of the Modbus protocol.


Limitations

* Since Modbus was designed in the late 1970s to communicate to programmable logic controllers, the number of data types is limited to those understood by PLCs at the time. Large binary objects are not supported. * No standard way exists for a node to find the description of a data object, for example, to learn that a register value represents a temperature between 30 and 175 degrees. * Since Modbus is a client/server (formerly master/slave) protocol, there is no way for a field device to get data by the event handler mechanism (except over Ethernet TCP/IP, called open-mbus) as the client node must routinely poll each field device and look for changes in the data. This consumes bandwidth and network time in applications where bandwidth may be expensive, such as over a low-bit-rate radio link. * Modbus is restricted to addressing 247 devices on one data link, which limits the number of field devices that may be connected to a parent station (again, Ethernet TCP/IP is an exception). * Modbus protocol itself provides no security against unauthorized commands or interception of data.


Modbus object types

The following object types may be provided by a Modbus server to a Modbus client device: The addresses are representative of the original Modicon specification. Under the current standard the address can be 0 - 65535 with the object type identified by the command used to read or write the coil or register.


Protocol versions

Versions of the Modbus protocol exist for serial ports, and for
Ethernet Ethernet () is a family of wired computer networking technologies commonly used in local area networks (LAN), metropolitan area networks (MAN) and wide area networks (WAN). It was commercially introduced in 1980 and first standardized in 1 ...
and other protocols that support the
Internet protocol suite The Internet protocol suite, commonly known as TCP/IP, is a framework for organizing the set of communication protocols used in the Internet and similar computer networks according to functional criteria. The foundational protocols in the sui ...
. There are many variants of Modbus protocols: * ''Modbus RTU'' (Remote Terminal Unit) – used in
serial communication In telecommunication and data transmission, serial communication is the process of sending data one bit at a time, sequentially, over a communication channel or computer bus. This is in contrast to parallel communication, where several bits a ...
, and is the most common implementation available for Modbus. Modbus RTU 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 A cyclic redundancy check (CRC) is an error-detecting code commonly used in digital networks and storage devices to detect accidental changes to digital data. Blocks of data entering these systems get a short ''check value'' attached, based on ...
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. * ''Modbus ASCII'' – used in serial communication and makes use of
ASCII ASCII ( ), abbreviated from American Standard Code for Information Interchange, is a character encoding standard for electronic communication. ASCII codes represent text in computers, telecommunications equipment, and other devices. Because ...
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). * ''Modbus TCP/IP'' or ''Modbus TCP'' – a Modbus variant used for communications over
TCP/IP The Internet protocol suite, commonly known as TCP/IP, is a framework for organizing the set of communication protocols used in the Internet and similar computer networks according to functional criteria. The foundational protocols in the su ...
networks, connecting over port 502. It does not require a checksum calculation, as lower layers already provide checksum protection. * ''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 over UDP'' – some have experimented with using Modbus over UDP on IP networks, which removes the overhead of TCP. * ''Modbus Plus'' (''Modbus+'', ''MB+'', or ''MBP'') – Modbus Plus is proprietary to
Schneider Electric Schneider Electric SE is a French multinational company that specializes in digital automation and energy management. It addresses homes, buildings, data centers, infrastructure and industries, by combining energy technologies, real-time automatio ...
and unlike the other variants, it supports
peer-to-peer Peer-to-peer (P2P) computing or networking is a distributed application architecture that partitions tasks or workloads between peers. Peers are equally privileged, equipotent participants in the network. They are said to form a peer-to-peer ...
communications between multiple clients. It requires a dedicated co-processor to handle fast
HDLC High-Level Data Link Control (HDLC) is a bit-oriented code-transparent synchronous data link layer protocol developed by the International Organization for Standardization (ISO). The standard for HDLC is ISO/IEC 13239:2002. HDLC provides bot ...
-like token rotation. It uses twisted pair at 1 Mbit/s and includes transformer isolation at each node, which makes it transition/edge-triggered instead of voltage/level-triggered. Special hardware is required to connect Modbus Plus to a computer, typically a card made for the
ISA Isa or ISA may refer to: Places * Isa, Amur Oblast, Russia * Isa, Kagoshima, Japan * Isa, Nigeria * Isa District, Kagoshima, former district in Japan * Isa Town, middle class town located in Bahrain * Mount Isa, Queensland, Australia * Mount ...
, PCI, or
PCMCIA The Personal Computer Memory Card International Association (PCMCIA) was a group of computer hardware manufacturers, operating under that name from 1989 to 2009. Starting with the PCMCIA card in 1990 (the name later simplified to ''PC Card''), ...
bus. * ''Pemex Modbus'' – an extension of standard Modbus with support for historical and flow data. It was designed for the
Pemex Pemex (a portmanteau of Petróleos Mexicanos, which translates to ''Mexican Petroleum'' in English; ) is the Mexican state-owned petroleum company managed and operated by the Mexican government. It was formed in 1938 by nationalization and expr ...
oil and gas company for use in process control and never gained widespread adoption. * ''Enron Modbus'' – another extension of standard Modbus developed by
Enron Enron Corporation was an American energy, commodities, and services company based in Houston, Texas. It was founded by Kenneth Lay in 1985 as a merger between Lay's Houston Natural Gas and InterNorth, both relatively small regional compani ...
with support for 32-bit integer and floating-point variables, and historical and flow data. Data types are mapped using standard addresses. The historical data serves to meet an
American Petroleum Institute The American Petroleum Institute (API) is the largest U.S. trade association for the oil and natural gas industry. It claims to represent nearly 600 corporations involved in production, refinement, distribution, and many other aspects of the ...
(API) industry standard for how data should be stored. 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.


Communications and devices

Each device communicating (i.e., transferring data) on a Modbus is given a unique address. In Modbus RTU, Modbus ASCII, and Modbus Plus (which are all RS-485 single-cable multi-drop networks), only the node assigned as the 'master' may initiate a command. All other devices are 'slaves' which respond to requests and commands. Nomenclature is different for the protocols using Ethernet, such as Modbus TCP. Here any device can send out a Modbus command, and as is usual in computer networks, the device sending the command is the 'client' and the response comes from a 'server'. Many modems and gateways support Modbus, as it is a simple and often-copied protocol. Some of them were specifically designed for this protocol. Different implementations use wireline or wireless communication, such as in the
ISM radio band The ISM radio bands are radio band, portions of the radio spectrum reserved internationally for industrial, scientific and medical (ISM) purposes, excluding applications in telecommunications. Examples of applications for the use of radio frequenc ...
, and even
Short Message Service Short Message/Messaging Service, commonly abbreviated as SMS, is a text messaging service component of most telephone, Internet and mobile device systems. It uses standardized communication protocols that let mobile devices exchange short tex ...
(SMS) or
General Packet Radio Service General Packet Radio Service (GPRS) is a packet oriented mobile data standard on the 2G and 3G cellular communication network's global system for mobile communications (GSM). GPRS was established by European Telecommunications Standards Ins ...
(GPRS).


Commands

Modbus commands can instruct a Modbus device to: * change the value in one of its registers, that is written to Coil and Holding registers * read an I/O port: read data from a Discrete Input or from a Coil * command the device to send back one or more values contained in its Coil and Holding registers A Modbus command contains the Modbus address of the device it is intended for (1 to 247). Only the addressed device will respond and act on the command, even though other devices might receive it (an exception is specific broadcastable commands sent to node 0, which are acted on but not acknowledged). All Modbus commands contain checksum information to allow the recipient to detect transmission errors.


Frame formats

A Modbus "frame" consists of an Application Data Unit (ADU), which encapsulates a Protocol Data Unit (PDU): * ADU = Address + PDU + Error check. * PDU = Function code + Data. In Modbus data frames, the most significant byte of a multi-byte value is sent before the others. All Modbus variants use one of the following frame formats.


Modbus RTU frame format

This format is primarily used on asynchronous serial data lines like RS-485/ EIA-485. Its name refers to a remote terminal unit. CRC calculation: * Polynomial: ''x''16 + ''x''15 + ''x''2 + 1 (CRC-16-ANSI also known as CRC-16-IBM, normal hexadecimal algebraic polynomial being 8005 and reversed A001). * Initial value: 65,535. * Example of frame in hexadecimal: 01 04 02 FF FF B8 80 (CRC-16-ANSI calculation for the 5 bytes from 01 to FF gives 80B8, which is transmitted least significant byte first).


Modbus ASCII frame format

Primarily used on 7-bit or 8-bit asynchronous serial lines. 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 Two's complement is a mathematical operation to reversibly convert a positive binary number into a negative binary number with equivalent (but negative) value, using the binary digit with the greatest place value (the leftmost bit in big- endian ...
) 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 frame format

Primarily used on
Ethernet Ethernet () is a family of wired computer networking technologies commonly used in local area networks (LAN), metropolitan area networks (MAN) and wide area networks (WAN). It was commercially introduced in 1980 and first standardized in 1 ...
networks. ''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. Natively Modbus/TCP-capable devices usually ignore the Unit Identifier.


Functions and commands

Prominent conceptual entities in a Modbus server include the following: * Coils: readable and writeable, 1 bit (off/on) * Discrete Inputs: read only, 1 bit (off/on) * Input Registers: read only measurements and statuses, 16 bits (0–65,535) * Holding Registers: readable and writeable configuration values, 16 bits (0–65,535) The commands to read and write these entities are summarized in the following table. The most primitive reads and writes are shown in bold. Some sources use terminology that differs from the standard; for example ''Force Single Coil'' instead of ''Write Single Coil''.


Format of requests and responses

Requests and responses follow the frame formats described above. This section gives details of the data formats of the most often used function codes.


Function codes 1 (read coils) and 2 (read discrete inputs)

Request: *Address of first coil/discrete input to read (16-bit) *Number of coils/discrete inputs to read (16-bit) Normal response: *Number of bytes of coil/discrete input values to follow (8-bit) *Coil/discrete input values (8 coils/discrete inputs per byte) Value of each coil/discrete input is binary (0 for off, 1 for on). First requested coil/discrete input is stored as least significant bit of first byte in reply. If number of coils/discrete inputs is not a multiple of 8, most significant bit(s) of last byte will be stuffed with zeros. For example, if eleven coils are requested, two bytes of values are needed. Suppose states of those successive coils are ''on, off, on, off, off, on, on, on, off, on, on'', then the response will be 02 E5 06 in hexadecimal. Because the byte count returned in the reply message is only 8 bits wide and the protocol overhead is 5 bytes, a maximum of 2008 (251 x 8) discrete inputs or coils can be read at once.


Function code 5 (force/write single coil)

Request: *Address of coil (16-bit) *Value to force/write: 0 for off and 65,280 (FF00 in hexadecimal) for on Normal response: same as request.


Function code 15 (force/write multiple coils)

Request: *Address of first coil to force/write (16-bit) *Number of coils to force/write (16-bit) *Number of bytes of coil values to follow (8-bit) *Coil values (8 coil values per byte) The value of each coil is binary (0 for off, 1 for on). The first requested coil is stored as the least significant bit of the first byte in the request. If a number of coils is not a multiple of 8, the most significant bit(s) of the last byte should be stuffed with zeros. See example for function codes 1 and 2. Normal response: *Address of first coil (16-bit) *Number of coils (16-bit)


Function codes 4 (read input registers) and 3 (read holding registers)

Request: *Address of first register to read (16-bit) *Number of registers to read (16-bit) Normal response: *Number of bytes of register values to follow (8-bit) *Register values (16 bits per register) Because the maximum length of a Modbus PDU is 253 (inferred from the maximum Modbus ADU length of 256 on RS485), up to 125 registers can be requested at once when using the RTU format, and up to 123 over TCP.


Function code 6 (preset/write single holding register)

Request: *Address of holding register to preset/write (16-bit) *New value of the holding register (16-bit) Normal response: same as request.


Function code 16 (preset/write multiple holding registers)

Request: *Address of first holding register to preset/write (16-bit) *Number of holding registers to preset/write (16-bit) *Number of bytes of register values to follow (8-bit) *New values of holding registers (16 bits per register) Because the maximum length of a Modbus PDU is 253 (inferred from the maximum Modbus ADU length of 256 on RS485), up to 123 registers can be written at once. Normal response: *Address of first preset/written holding register (16-bit) *Number of preset/written holding registers (16-bit)


Exception responses

For a normal response, the server repeats the function code. Should a server want to report an error, it will reply with the requested function code plus 128 (hex 0x80) (3 becomes 131 = hex 0x83), and will only include one byte of data, known as the ''exception code''.


Main Modbus exception codes


Entity numbers and addresses

The Modbus Organization mentions the following in the Modbus Application Protocol v1.1b: * The Modbus application protocol defines the PDU addressing rules: In a PDU, each data item is addressed from 0 to 65535. * It also defines a MODBUS data model composed of four blocks that comprise several elements numbered from 1 to n. * In the Modbus data model, each element within a data block is numbered from 1 to n. Some conventions govern how Modbus entities (coils, discrete inputs, input registers, holding registers) are referenced. It is important to make a distinction between entity ''number'' and entity ''address'': * Entity ''numbers'' combine entity type and entity location within their description table * Entity ''address'' is the starting address, a 16-bit value in the data part of the Modbus frame, ranging from 0 to 65,535 (0000 to FFFF in the packets) In the traditional convention, entity ''numbers'' start with a digit representing the entity type, followed by four digits representing the entity location: * coils ''numbers'' start with 0 and span from 00001 to 09999, * discrete input ''numbers'' start with 1 and span from 10001 to 19999, * holding register ''numbers'' start with 4 and span from 40001 to 49999. For data communications, the entity ''location'' (1 to 9,999) is translated into a 0-based entity ''address'' (0 to 9,998) by subtracting 1. For example, in order to read holding registers starting at ''number'' 40001, the data frame will contain function code 3 (as seen above) and ''address'' 0. For holding registers starting at ''number'' 40100, the ''address'' will be 99. This limits the number of ''addresses'' to 9,999 for each entity. A ''
de facto ''De facto'' ( ; , "in fact") describes practices that exist in reality, whether or not they are officially recognized by laws or other formal norms. It is commonly used to refer to what happens in practice, in contrast with '' de jure'' ("by l ...
'' standard extends this to 65,536 by adding one digit to the previous list: * coil ''numbers'' span from 000001 to 065536, * discrete input ''numbers'' span from 100001 to 165536, * input register ''numbers'' span from 300001 to 365536, * holding register ''numbers'' span from 400001 to 465536. When using extended referencing, all ''number'' references must have exactly 6 digits to avoid confusion between coils and other entities. For example, to distinguish between holding register #40001 and coil #40001, if coil #40001 is the target, it must appear as #040001. Another way to note the data addresses is to use the hexadecimal value, which clarifies the use of the four digits in the traditional convention mentioned previously. * coil ''numbers'' span from 0x0000 to 0xFFFF * discrete input ''numbers'' span from 1x0000 to 1xFFFF * input register ''numbers'' span from 3x0000 to 3xFFFF * holding register ''numbers'' span from 4x0000 to 4xFFFF The advantage of this notation is that the same numbers are found when decoding Modbus packets.


JBUS mapping

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 Groupe Renault ( , , , also known as the Renault Group in English; legally Renault S.A.) is a French multinational automobile manufacturer established in 1899. The company produces a range of cars and vans, and in the past has manufactured ...
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: * Number and address coincide: entity #''x'' has address ''x'' in the data frame. * Consequently, entity number does not include the entity type. For example, holding register #40010 in Modbus will be holding register #9, at address 9 in JBUS. * Number 0 (and thus address 0) is not supported. The server should not implement any real data at this number and address, and it can return a null value or throw an error when requested.


Implementations

Almost every implementation has variations from the official standard. Different varieties might not communicate correctly between equipment of different suppliers. Some of the most common variations are: * Data types **
IEEE 754 The IEEE Standard for Floating-Point Arithmetic (IEEE 754) is a technical standard for floating-point arithmetic established in 1985 by the Institute of Electrical and Electronics Engineers (IEEE). The standard addressed many problems found ...
floating-point number ** 32-bit integer ** 8-bit data ** Mixed data types ** Bit fields in integers ** Multipliers to change data to/from integer. 10, 100, 1000, 256, ... * Protocol extensions ** 16-bit server addresses ** 32-bit data size (1 address = 32 bits of data returned) ** Word-swapped data


Modbus Plus

Despite the name, Modbus Plus is not a variant of Modbus. It is a different
protocol Protocol may refer to: Sociology and politics * Protocol (politics), a formal agreement between nation states * Protocol (diplomacy), the etiquette of diplomacy and affairs of state * Etiquette, a code of personal behavior Science and technology ...
, involving
token passing On a local area network, token passing is a channel access method where a packet called a ''token'' is passed between nodes to authorize that node to communicate. In contrast to polling access methods, there is no pre-defined "master" node. The mos ...
. It is a proprietary specification of Schneider Electric, though it is unpublished rather than patented. It is normally implemented using a custom chipset available only to partners of Schneider.


See also

*
CAN bus A Controller Area Network (CAN bus) is a robust vehicle bus standard designed to allow microcontrollers and devices to communicate with each other's applications without a host computer. It is a message-based protocol, designed originally for m ...


References


External links

Specifications
Modbus Organization
– links to protocol specifications
Modbus over serial line V1.0
– Modbus Organization (2002)
Modicon Modbus Protocol Reference Guide
– Modbus Organization (1996). This is an obsolete Modbus specification, should only be used to address legacy issues. Other
Modbus for Field Technicians
at modbusbacnet.com

at RF Wireless World {{Computer bus Building automation Industrial computing Industrial Ethernet Network protocols