What is Modbus?

Modicon created the serial communication protocol known as Modbus and released it in 1979 for use with its programmable logic controllers (PLCs). It is a technique to transmit data over serial lines between electronic devices. The devices supplying the information are referred to as Modbus Slaves, while the device requesting the information is known as the Modbus Master. A typical Modbus network has one Master and up to 247 Slaves, each with a unique Slave Address ranging from 1 to 247. Information can also be written to the Slaves by the Master. For a comprehensive overview, you can visit the Modbus Wikipedia page.

The main reasons for the use of Modbus in the industrial environment are

  • With industrial applications in mind, it was created.
  • It has no hidden fees and is freely distributed.
  • Both deployment and maintenance are simple.
  • It transfers unprocessed bits or words without imposing many constraints on vendors.
  • Modbus protocols-based SCADA systems are easily accessible.

There are different flavors of Modbus Protocol

  •  Modbus TCP
  •  Modbus RTU
  •  Modbus ASCII
  •  Modbus Plus
  •  Modbus Daniels
  •  Modbus Tek-Air
  •  Modbus Omniflow

Modbus RTU and Modbus TCP/IP are the two most widely used of these.

Modbus RTU

It is a serial communication protocol that links various devices on the same network and enables inter-device communication.

Modbus TCP

Schneider Automation’s Modbus Messaging Implementation Guide details a modified protocol designed specifically for use over TCP/IP. Visit www.modbus.org/specs.php to access the official Modbus specification. These key distinctions between Modbus RTU and Modbus TCP are listed here.

MODBUS MEMORY MODEL/ MODBUS STORAGE MODEL

MODBUS has a distinct addressing pattern. Every value in a Modbus device is stored at a specific address. For instance, a Volt A-N value will only be stored by an EATON power metre at Modbus address 40001.

There four Modbus DATA Type

Types  of Modbus DataData format and common nameAddress where they begin Type
Modbus CoilsBits, Binary values00001This type of data can be provided by an I/O system.
Digital InputsBinary values10001This type data can be changed by an application layer.
Analog InputsBinary values30001This type of data can be provided by an I/O system.
Modbus Registers/ Holding registersAnalog values40001This type data can be changed by an application layer.

How does MODBUS RTU work?

  • Modbus is communicated between devices via serial lines. The simplest configuration would involve connecting two devices, a Master and a Slave, using a single serial cable to connect their serial ports.
  • The data is transmitted as a series of ones and zeroes known as bits. Every bit is transmitted as a voltage. Positive voltages are sent as zeroes, while negative voltages are sent as ones. The bits are transmitted quickly. The average transmission speed is 9600 baud (bits per second).

How does Modbus TCP work?

Utilising the gateway‘s Ethernet port, the Modbus device can be connected. We can run a query with any standard Modbus Scanner to extract the value from a Modbus device. All requests are routed through TCP/IP on the registered port 502.

How is data stored in Standard Modbus?

The Slave device stores information in four different tables.

In two tables, discrete on/off values (coils) are stored, and in the other two, numerical values (registers). Each coil and register has its own read-only and read-write table.

Each table has 9999 values.
Each coil or contact is 1 bit and assigned a data address between 0000 and 270E.
Each register is 1 word = 16 bits = 2 bytes and also has data address between 0000 and270E.

Coil/Register NumbersData AddressesTypeTable Name
1-99990000 to 270ERead-WriteDiscrete Output Coils
10001-199990000 to 270ERead-OnlyDiscrete Input Contacts
30001-399990000 to 270ERead-OnlyAnalog Input Registers
40001-499990000 to 270ERead-WriteAnalog Output Holding Registers

Since Coil/Register Numbers do not appear in the actual messages, they can be regarded as location names. In the messages, the Data Addresses are utilised.

For instance, the Data Address for the first Holding Register, 40001, is 0000.

The offset is defined as the difference between these two values.

The offset varies for every table. 1, 10001, 30001 and 40001.

What is the Slave ID?

A unique unit address between 1 and 247 is given to each slave in a network. The Slave address is the first byte the master sends when making a data request. This way, each slave can decide whether to ignore the message after the first byte.

What is a Modbus Map?

Simply put, a Modbus map is a list of slave devices that specifies:

– what the data is (for example, pressure or temperature readings)

– where the data is stored (which tables and data addresses)

– how the data is stored (data types, byte and word ordering)

Some devices have a fixed map that the manufacturer predetermines, while other devices let the user programme or customise a map to meet their specific needs.

MODBUS ERROR CHECKING

MODBUS networks use two error-checking methods: parity checking

  1. Data character frame parity checking (even, odd, or no parity)
  2. Frame verification for the message frame (Cyclical Redundancy Check in RTU Mode, or Longitudinal Redundancy Check in ASCII Mode).

Parity Checking

A MODBUS device can be set to check for even or odd parity or to check for no parity at all. This determines how the character’s data frame’s parity bit is set. The number of 1 bits in each character frame’s data section is counted, depending on whether even or odd parity checking is chosen. In RTU mode, each character contains 8 bits. As a result, the total number of 1 bits will either be even (even parity) or odd (odd parity), depending on whether the parity bit is set to 0 or 1.

If you encounter specific issues, you may find answers on Stack Overflow.

Frame checking

The LRC—Longitudinal Redundancy Check (ASCII Mode Only) The character frame in ASCII transmission mode has an LRC field as the final field before the CRLF characters. Except for the starting colon character and the final CRLF pair of characters, this field contains two ASCII characters representing the outcome of a longitudinal redundancy calculation for all fields.

CRC Error Checking (RTU Mode Only)

Cyclical Redundancy Check (CRC) based error checking is included in RTU Mode message frames. A message frame’s error-checking field holds a 16-bit value (two 8-bit bytes) representing the outcome of a Cyclical Redundancy Check (CRC) calculation on the message contents.

Function codes Defined by Modbus:

The Master’s second byte is the Function code. The slave is instructed by this number to read from or write to the table and to access the appropriate table.

Function CodeActionTable Name
01 (01 hex)ReadDiscrete Output Coils
05 (05 hex)Write singleDiscrete Output Coil
15 (0F hex)Write multipleDiscrete Output Coils
02 (02 hex)ReadDiscrete Input Contacts
04 (04 hex)ReadAnalog Input Registers
03 (03 hex)ReadAnalog Output Holding Registers
06 (06 hex)Write singleAnalog Output Holding Register
16 (10 hex)Write multipleAnalog Output Holding Registers

Modbus Exception Codes

CodeNameMeaning
01ILLEGAL FUNCTIONThe function code received in the query is not an allowable action for the server (or slave). This may be because the function code is only applicable to newer devices, and was not implemented in the unit selected. It could also indicate that the server (or slave) is in the wrong state to process a request of this type, for example because it is unconfigured and is being asked to return register values.
02ILLEGAL DATA ADDRESSThe data address received in the query is not an allowable address for the server (or slave). More specifically, the combination of reference number and transfer length is invalid. For a controller with 100 registers, the PDU addresses the first register as 0, and the last one as 99. If a request is submitted with a starting register address of 96 and a quantity of registers of 4, then this request will successfully operate (address-wise at least) on registers 96, 97, 98, 99. If a request is submitted with a starting register address of 96 and a quantity of registers of 5, then this request will fail with Exception Code 0x02 “Illegal Data Address” since it attempts to operate on registers 96, 97, 98, 99 and 100, and there is no register with address 100.
03ILLEGAL DATA VALUEA value contained in the query data field is not an allowable value for server (or slave). This indicates a fault in the structure of the remainder of a complex request, such as that the implied length is incorrect. It specifically does NOT mean that a data item submitted for storage in a register has a value outside the expectation of the application program, since the MODBUS protocol is unaware of the significance of any particular value of any particular register.
04SLAVE DEVICE FAILUREAn unrecoverable error occurred while the server (or slave) was attempting to perform the requested action.
05ACKNOWLEDGESpecialized use in conjunction with programming commands. The server (or slave) has accepted the request and is processing it, but a long duration of time will be required to do so. This response is returned to prevent a timeout error from occurring in the client (or master). The client (or master) can next issue a Poll Program Complete message to determine if processing is completed.
06SLAVE DEVICE BUSYSpecialized use in conjunction with programming commands. The server (or slave) is engaged in processing a long–duration program command. The client (or master) should retransmit the message later when the server (or slave) is free.
08MEMORY PARITY ERRORSpecialized use in conjunction with function codes 20 and 21 and reference type 6, to indicate that the extended file area failed to pass a consistency check The server (or slave) attempted to read record file, but detected a parity error in the memory. The client (or master) can retry the request, but service may be required on the server (or slave) device.
0AGATEWAY PATH UNAVAILABLESpecialized use in conjunction 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 means that the gateway is not configured correctly or is overloaded.
0BGATEWAY TARGET DEVICE FAILED TO RESPONDSpecialized use in conjunction with gateways, indicates that no response was obtained from the target device. Usually means that the device is not present on the network.

ProtoConvert offers outstanding solutions for every type of protocol such as ‘Modbus’, ‘BACnet’, ‘LonWorks‘, ‘SNMP‘, etc. Explore our gateway page for details or send an inquiry for personalized assistance. Visit our Protoconvert Home page for more information about our services. Also Check out our All Tutorials page for more helpful guides. Learn more about our mission on our About Us page.

Get in Touch