What is Modbus and how does it work?

freeFree Technical Resource

This content is free to read, suitable for basic learning and search traffic.

What is Modbus and how does it work?
What is Modbus and how does it work?Figure

What is Modbus?

Modbus RTU and Modbus ASCII use the same protocol. The only difference is that the bytes transmitted over the wire are presented in binary form with the RTU, and when using Modbus RTU, they are presented in readable ASCII form. It should be noted that RTU messages do not have the Start_of_text flag. The receiver in communication uses a 'silent' time to determine the start of a new message. ASCII has text tags. Binary messages are shorter than ASCII messages, so theoretically they have faster transmission/reception speeds. You may be satisfied with the update speed of about 100 milliseconds in HMI/SCADA, and can choose any communication method.

What is it used for?

Modbus It is an open protocol, This means that manufacturers can build it into their devices, Without the need to pay patent fees. It has become the standard communication protocol in the industrial sector, And now it is the most common means of connecting industrial electronic devices. It is widely used in various industries by many manufacturers. Modbus Usually used to transmit signals from instruments and control equipment to the main controller or data acquisition system, For example, a system used to measure temperature and humidity and transmit the results to a computer. Modbus Usually used to connect monitoring computers with remote terminal units (RTU) come together, This is in monitoring and data collection (SCADA) Used in the system. Modbus The version of the protocol exists on the serial line (Modbus RTU and Modbus ASCII) And Ethernet (Modbus TCP)In the middle.

How does it work?

Modbus It is transmitted between devices through serial lines. The simplest setup is to connect the serial ports of two devices with a single serial cable, I.e. client and server.

What is Modbus and how does it work?Figure1

The data is sent as a series of ones and zeros called bits. Each bit is sent as a voltage. Sending with zero positive voltage, And sending with negative voltage. These bits are sent very quickly. The typical transmission speed is 9600 Baud rate (Bit per second) .

What is hexadecimal?

When solving problems, It is helpful to see the actual raw data being sent. Long strings of 1 and 0 are difficult to read, So the bits are combined and displayed in hexadecimal format. each 4 The block is composed of 0 to F One of the sixteen characters represents.

What is Modbus and how does it work?Figure2

each 8 Position block (Known as bytes) From 00 to FF of 256 One character pair represents.

How data is stored in standards Modbus In the middle?

Information is stored in server devices, There are four different types of tables. Two tables store discrete values for on/off (coil) , And the other two tables store numerical values (register) . Both coils and registers have read-only tables and read-write tables. Each table has 9999 Individual Value. Each coil or contact is 1 Position,And assigned data addresses from 0000 to 270E. Each register is 1 character = 16 bit = 2 byte, There are also data addresses from 0000 to 270E.

What is Modbus and how does it work?Figure3

The coil/register number can be seen as a position name, Because they do not appear in actual messages. The data address is used in the message. for example, The first hold register, numbered as 40001, Having a data address 0000. The difference between these two values is the offset. Each table has a different offset, respectively 1, 10001, 30001 and 40001.

Server ID What is it?

Each server in the network is assigned a unique unit address, from 1 to 247. When the client requests data, The first byte it sends is the server address. like this, Each server knows whether to ignore the message after the first byte.

What is a function code?

The second byte sent by the client is the function code. This number tells the server which table to access, And whether to read or write from the table.

What is Modbus and how does it work?Figure4

CRC What is it?

CRC Represents cyclic redundancy check. It is added to every Modbus Two bytes at the end of the message for error detection. Each byte in the message is used for computation CRC. The receiving device also calculates CRC And connect it with the sending device's CRC Compare and contrast. If a bit in the message is received incorrectly, CRC Will be different, Will lead to errors.

Modbus What is the format of commands and responses?

What is the data type?

FC03 Example display, register 40108 Contain AE41, It is converted to 16 bit 1010 1110 0100 0001. But what does this meanWell,It can represent several different types 16 Bit data type:

  • 16 Unsigned integer (between 0 to 65535 Integer between) register 40108 Contain AE41 = 44609 (Convert hexadecimal to decimal)
  • 16 Signed integer (between -32768 to 32767 Integer between) AE41 = -20927 (Convert hexadecimal to decimal packaging, If greater than 32767, Then subtract 65536)
  • Two character ASCII string (2 One character letter) AE41 = ® A
  • Discrete on/off values(With) 16 Same bit integer, Having value 0 or 1. Hexadecimal data will be 0000 or 0001) register 40108 You can also communicate with 40109 Combine to form these 32 Any type of bit data:
  • 32 Unsigned integer (between 0 to 4,294,967,295 Numbers between them) 40108,40109 = AE41 5652 = 2,923,517,522
  • 32 Signed integer (between -2,147,483,648 to 2,147,483,647 Numbers between them) AE41 5652 = -1,371,449,774
  • 32 Double precision IEEE floating-point number. This is a system that allows the use of approximately seven decimal places 32 The number of digits represents any real number (Numbers with decimal points) The mathematical formula. AE41 5652 = -4.395978E-11. This is a tool used for 4 Byte or 2 The input of a single character IEEE Floating point calculator. To download a copy, Please right-click and select“Save As…”.
  • Four character ASCII string (4 One character letter) AE41 5652 = ® A V RMore registers can be combined to form longer ones ASCII string. Each register is used to store two ASCII character (Two bytes) .

What is byte and word sorting?

Modbus The specification does not precisely define the way data is stored in registers. Therefore, Some manufacturers have implemented it in their devices Modbus To store and transmit high byte data, Then there are the low bytes (AE in 41 previously) .

Besides, Other devices store and transmit low byte data (41 in AE previously) . also, When registers are combined to represent 32 When dealing with data types, Some devices will be high 16 Position(High character) Stored in the first register, The remaining low words are stored in the second register (AE41 in 5652 previously) , And other devices are the opposite (5652 in AE41 previously) .

Sending bytes or words in any order doesn't matter, As long as the receiving device knows which way to expect it. for example, If you want to 29,235,175,522 as 32 Send unsigned integers, It can be arranged in one of these four ways.

AE41 5652 High byte first, high word first

5652 AE41 High byte first, low word first

41AE 5256 Low byte first, high word first

5256 41AE Low byte first, low word first

What is Modbus Mapping?

Modbus Mapping is just a list defined for an individual server device, It defines what data is (For example, pressure or temperature readings) , Where is the data stored (Which table and data address)

How to store data (data type, Byte and word sorting)

Some devices have built-in manufacturer defined fixed maps. Other devices allow operators to configure or program custom maps to meet their needs

Modbus ASCII and Modbus RTU What is the difference between them?

Modbus RTU and Modbus ASCII Using the same protocol. The only difference is that the bytes transmitted over the wire are RTU Presented in binary form, and use Modbus RTU Readable in time ASCII Form presentation. It should be noted that, RTU No newsStart_of_text logo. The recipient's use in communication“Silence”Time determines the start of new messages. ASCII Having text tags. Binary message ratio ASCII The message should be short, Therefore, theoretically, the transmission/reception speed is faster. You may be interested in HMI/SCADA The update speed is about 100 Milliseconds satisfied, You can choose any communication method.

Summary: Recommended for general use RTU; If in WinNT Use on top RTU There is a timeout issue or using slower communication media, such as 300 bps When using a dial-up modem, Please use ASCII. Regarding Modbus Most of them OPC Server support ASCII and RTU Communication.

What is an extended register address?

Due to the analog output maintaining a register range of 40001 to 49999, This means that the register cannot exceed 9999 One.Although this is usually sufficient for most applications, But there are also some cases where more registers are needed. register 40001 to 49999 Corresponding data address 0000 to 270E. If we use the remaining data addresses 270F to FFFF, There will be as many as 6 Multiple registers available, Total 65536 One.This will correspond to the register number from 40001 to 105536. many Modbus Software driver program (Used for clients PC) according to 40001 to 49999 The limitations of writing, Unable to access the extended registers in the server device. and, Many server devices do not support maps using extended registers. On the other hand, Some server devices support these registers, Some client software can access it, Especially if custom software is written.

How to use 2 Byte server address?

Due to the usual use of one byte to define server addresses, And each server on the network requires a unique address, So the number of servers on the network is limited, At most 256. Modbus The restrictions defined in the specifications are even lower, for 247. To surpass this limitation, The protocol can be modified, Using two bytes as the address. Both the client and server need to support this modification. Using two byte addresses can extend the limit on the number of servers in a network to 65535. By default, Simply Modbus Software Usage 1 Byte address. The input address is greater than 255 When,The software will automatically switch to 2 Byte address, And keep it in this mode, Until manually closed 2 Byte Addressable .

How to send events and historical data?

Enron Modbus Including commands for moving events and historical data.

What is Enron Modbus?

Enron Modbus is caused by Enron The standards developed by the company Modicon Modbus Modification of Communication Protocol. Please refer to Enron Modbus To obtain detailed information.

Put this resource to use in a real project?

Go to the Tool Center for message parsing, CRC verification and device debugging, or submit your requirements for selection and integration advice.

Engineer Membership

Turn this article into actionable debugging resources

After activation, you can use advanced message parsing, resource pack downloads, code examples, engineering cases and priority technical support, suitable for real project delivery.

Unlimited Advanced Tools
Resource & Code Packs
Complete Engineering Case Library
Priority Technical Support

Leave a Reply

Your email address will not be published. Required fields are marked *.