A Brief Introduction to Modbus Protocol

freeFree Technical Resource

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

A Brief Introduction to Modbus Protocol

Modbus is an open protocol, which means manufacturers can use it for free without paying royalties. It has become a standard communication protocol in industry and is now the most commonly used method for connecting industrial electronic devices. It is widely used by many manufacturers in various industries Modbus is commonly used to transmit signals from instruments and control devices back to the main controller or data acquisition system, such as measuring temperature and humidity and transmitting the results to a computer system. Modbus is commonly used to connect monitoring computers with Remote Terminal Units (RTUs) in Supervisory Control and Data Acquisition (SCADA) systems.

Due to the analog output holding register range being 40001 to 49999, it means that the number of registers cannot exceed 9999. Although this is usually sufficient for most applications, there may be more registers in some cases. Register 40001 to 49999 corresponds to data addresses 0000 to 270E. If we utilize the remaining data addresses 270F to FFFF, we can use more than six times as many registers, totaling 65536. This corresponds to register numbers 40001 to 105536. Many Modbus software drivers (for the main PC) are written with restrictions from 40001 to 49999 and cannot access the extension registers in the slave device. Many devices do not support mapping using extended registers. On the other hand, some slave devices do support these registers, and some Master software can access them, especially when writing custom software.

A Brief Introduction to Modbus ProtocolFigure

  Data is sent in the form of a series of 1s and 0s, Known as a position. Each bit is sent as a voltage. Send zero as positive voltage, And one is sent as a negative voltage. These bits will be sent soon. The typical transmission speed is9600Porter (bits per second)).

  What is hexadecimal?

  When solving problems, Viewing the actual raw data transmitted would be very helpful. Long strings of 1 and 0 are difficult to read, Therefore, these bits are combined together and displayed in hexadecimal format. Each 4-bit block is composed of0 toF of16One of the characters represents.

  Each 8-bit block (referred to as a byte) is composed of00 toFF of256One representation of a character pair.

  How data is stored in standardsModbusMiddle?

  The information is stored in four different tables on the slave devices. Two tables for storing/disabling discrete values (coils) and two tables for storing numerical values (registers)). Each coil and register has a read-only table and a read-write table. Each table has9999Individual Value. Each coil or contact is 1 position, And allocate one between0000 and270E The data address between them. Each register is 1 word= 16bit= 2byte, And the data address is0000 and270E between.

  The coil/register number can be considered as a position name, Because they will not appear in actual messages. The data address is used in the message. for example, The first hold register, Number40001, Having a data address0000 . The difference between these two values is the offset. Each table has a different offset. 1,10001,30001and40001.

  What is a slave ID card?

  Each slave station in the network is assigned 1 to247The unique unit address. When the main station requests data, The first byte it sends is the slave address. like this, Each slave device knows whether to ignore the message after the first byte.

  What is functional code?

  The second byte sent by the host is the function code. This number tells the slave which table to access and whether to read from or write to the table.

  What isCRC?

  CRCRepresenting cyclic redundancy check. It is in everymodbusAdd two bytes at the end of the message for error detection. Each byte in the message is used for computationCRC. The receiving device also calculatesCRCAnd connect it with the data from the sending deviceCRCCompare and contrast. If one of the messages is received incorrectly, thenCRCWill be different and will lead to errors. .

  What is a data type?

  For exampleFC03 indicate, register40108ContainAE41 , It is converted into16bit1010 1110 0100 0001 Big! But what does this mean? Hmm, This may mean some things. register40108Can be defined as these16Any type of bit data:

A16Unsigned integer(0to65535Integer between registers40108ContainAE41 = 44609(Conversion from hexadecimal to decimal)

A16Signed integer(-32768to32767Integer between)AE41 = -20,927 (Hexadecimal to a package, If it exceeds32767Then subtract65536Decimal conversion)

  Two types of charactersASCIIstring(2Typed letters)AE41 =®A

  Discrepancy of A's on/off values (working in the same way here)16The hexadecimal data of the value of the integer 0 or 1 will be0000 or0001 )Registration40108It can also be combined with

  40109Forming any of these32Types of bit data:

A32Unsigned integer(0and4294967295Numbers between them)40108,40109 = AE41 5652 = 2923517522

  one32Signed integer(-2,147,483,648and2,147,483,647Numbers between them)AE41 5652 = -1,371,449,774

A32Double precisionIEEEfloating-point number. This is a mathematical formula, Allow any real number (with a decimal point) to be used32Position representation, The accuracy is about 7 digits. AE41 5652 = -4.395978 E-11 This is a spreadsheetIEEEFloating point calculator, Used for inputting 4 bytes or 2 words. To download a copy, Please right-click and select 'Save Target As'...

  Four character AASCIIstring(4Typed letters)AE41 5652 =®AVR More registers can be combined to form longer onesASCIIstring. Each register is used to store twoASCIICharacter (two bytes)).

  What is byte and word sorting?

  ModbusThe specification does not accurately define how data is stored in registers. Therefore, Some manufacturers have implemented it in their equipmentmodbus, Firstly, store and transmit high byte data, Then there are the low bytes. (41 previousAE ). or, Others first store and send low order bytes(AE previous41 ). Similarly, When registers are combined to represent32When dealing with data types, Some devices will be high16Bit (high word) is stored in the first register, The remaining low words are stored in the second register(AE41 in5652 previously), And other devices are the opposite(5652 previously)AE41 )As long as the receiving device knows how to expect it, The order in which bytes or words are sent is irrelevant. for example, If you want to convert numbers29,235,175,522as32Send unsigned integers, Then it can be arranged in any of these four ways.

  AE41 5652 High byte first, high word first

  5652 AE41 High byte first, low word first

  First of all41AE 5256 Low byte, first high word

  5256 41AE The first low byte is the first low word

  What isModbusmap?

  modbusMapping is just a separate device list, It defines- What is the data (such as pressure or temperature readings))

  • Where to store data (which tables and data addresses))
  • Storage method of data (data type), Byte and word sorting)

  Some devices are constructed using fixed mappings defined by manufacturers. And other devices allow operators to configure or program custom maps to meet their needs.

  Modbus ASCIIandModbus RTUWhat's the difference??

  Modbus RTUandModbus ASCIIUsing the same protocol. The only difference is that the bytes transmitted through the line are usedRTURepresented as binary, usingModbus RTURepresented as readableASCII. AboutRTUThe important precautions areRTUNo newsStart_of_textInstructions. The recipient's use in communication“Silence”Time to determine the start of new messages. ASCIIThere is indeed a text beginning marker. Binary message ratioASCIIShort,Therefore, theoretically, the transmission/reception speed is faster. You may be happy to be hereHMI / SCADAI saw approximately100 msThe update rate, And you can choose any communication option.

  Summary:

  • UseRTUit is possible that
  • IfRTUinWinNTThere is a timeout issue or usage issue on the platform300 bpsUsed for slow communication media such as dial-up modemsASCII, Most of them are used forModbusofOPCAll servers support itASCIIandRTUCommunication.

  What is an extended register address?

  Due to the fact that the range of the analog output holding register is40001to49999, Therefore, it means that the register cannot exceed9999One.Although this is usually sufficient for most applications, But in some cases, there may be more registers. register40001to49999Corresponding to the data address0000 to270E . If we utilize the remaining data addresses270F toFFFF , More than six times the number of registers can be used, in total65536One.This corresponds to40001to105536Register number. manymodbusSoftware driver program (for main use)PC)All of them are used40001to49999Limitations on Writing, Cannot access the extension register from the device. Many devices do not support mapping using extended registers. On the other hand, Some devices do support these registers, someMasterThe software can access it, Especially when writing custom software.

  How ByteDance Slave Addressing Works?

  Due to the fact that a single byte is typically used to define a slave address, And each slave station on the network requires a unique address, Therefore, the limit on the number of slave stations on the network is256. modbusThe restrictions defined in the specifications are even lower, for247 . Exceeding this limit, The protocol can be modified to use two bytes as the address. Both the master and the slave need to support this modification. Double byte addressing extends the limit on the number of slave stations in a network to65535. By default, Simply ModbusSoftware uses 1-byte addressing. Input greater than255 When it comes to the address, The software will automatically switch to this mode of 2-byte addressing and keep all addresses unchanged, Until manually disabling 2-byte addressing.

Related Tags
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 *.