Modbus is an application protocol (seventh) of the OSI model (Open Systems Interconnection model). It does not depend on the lower levels. Can use it in conjunction with other protocols, for example, Ethernet TCP / IP or UDP / IP.
It uses serial interfaces RS-232, RS-422, RS-485, fiber optics, radio channels, and others as a physical medium for signal transmission. Let’s describe the differences between the most famous implementations of the Modbus protocol: RTU, ASCII, and TCP.
Modbus RTU (Remote Terminal Unit). This type of protocol most often uses the RS-485 serial interface as the physical layer of the network, less often RS-232 and RS-422. All these interfaces define communication using twisted pairs but differ in characteristics such as the maximum cable length, the number of nodes, etc.
The Modbus RTU packet format is broadly the same as the generalized form previously described: no additional fields are used. Packet integrity is monitored using the CRC-16 algorithm. An essential feature of Modbus RTU is that time pauses with at least 3.5 * t, where t is the transmission time of one byte in the current network, must be used to separate packets.
And the transfer of data bytes within one package is performed sequentially with a time interval between adjacent bytes no more than 1.5 * t. Otherwise, the transfer will be considered false. These rules prevent the use of Modbus RTU on slow, e.g., modem networks. Modbus ASCII. This is a kind of protocol that also works over RS-232 / RS-485 interfaces but uses ASCII characters to encode messages.
Compared to Modbus RTU, two more fields are added in the packet format – special characters for marking the beginning and end of a message: colon and carriage return/line feed characters. There is no need for time pauses between packets.
The LRC-8 algorithm is used to check the integrity. Generally, this version of the protocol is rarely used due to the complexity of the encoding and messages. However, it can be an excellent alternative to Modbus RTU on network delays and equipment with less accurate timers. Modbus TCP. It is an implementation of ModBus on Ethernet networks. Works on top of the TCP / IP stack. Unlike Modbus RTU and ASCII, in Modbus TCP, a connection is established with a specific device using TCP / IP.
Therefore, the address in the Modbus packet is most often ignored, and broadcast messages are not used.
The address may be required if the connection is established with gateway outputs to the RS485 network to further communicate with devices already in the Modbus language. Packet integrity control is also provided using the TCP / IP protocol, so there is no need for its Modbus implementation.
Along with the address, the Modbus TCP packet header contains several additional fields:
Transaction ID (Or Exchange ID)
Most often filled with zeros. It is necessary for cases when the client device sends several messages without waiting for a response to the previous ones to then associate responses with requests.
Always filled with zeros, reserved for future use
Remaining Bag Length
The length of the remainder of the packet: addresses and PDUs (function code and data). We have considered only the open and most common implementations of the Modbus protocol. But there are many more, for example, MODBUS Plus, a proprietary protocol from Schneider Electric that supports Multi-Master mode.