Перейти к содержанию

Навигация

Modbus/en: различия между версиями

Часть переводимой страницы Протокол Modbus.
(Часть переводимой страницы Протокол Modbus.)
 
(не показана 1 промежуточная версия этого же участника)
Строка 13: Строка 13:
The master device periodically polls the slave or server. The master has no address, the transmission of messages from the device server to the host without asking the host in the protocol is not provided.
The master device periodically polls the slave or server. The master has no address, the transmission of messages from the device server to the host without asking the host in the protocol is not provided.


<div class="mw-translate-fuzzy">
[[File:Modbus_Datagram.png|900px|thumb|left|Modbus datagram in general]]
[[File:Modbus_Datagram.png|900px|thumb|left|Modbus datagram in general]]
</div>


The Modbus data package looks as shown in the figure. A PDU (Protocol Data Unit) is a common part of a MODBUS package that includes the function code and data of the package. '''ADU''' (Application Data Unit) is a complete Modbus package. Includes a physical layer-specific part of the package and PDU. For serial lines, the device address is passed in the ADU header, and the CRC16 checksum is passed at the end. The maximum ADU size in serial communication lines is 253 bytes (1 byte of the address and two bytes of the checksum are subtracted from the maximum 256 bytes allowed by the specification). For reference — in Modbus TCP, the maximum packet length is 260 bytes.
The Modbus data package looks as shown in the figure. A PDU (Protocol Data Unit) is a common part of a MODBUS package that includes the function code and data of the package. '''ADU''' (Application Data Unit) is a complete Modbus package. Includes a physical layer-specific part of the package and PDU. For serial lines, the device address is passed in the ADU header, and the CRC16 checksum is passed at the end. The maximum ADU size in serial communication lines is 253 bytes (1 byte of the address and two bytes of the checksum are subtracted from the maximum 256 bytes allowed by the specification). For reference — in Modbus TCP, the maximum packet length is 260 bytes.
Строка 22: Строка 20:
The function is encoded in one byte and determines what action the server device should perform. Function codes range from 1 to 255, with codes 128 to 255 reserved for error messages from the server device. Code 0 is not used. The size of the data block can vary from zero to the maximum allowed. If the request is processed correctly, the server device returns an ADU containing the requested data.
The function is encoded in one byte and determines what action the server device should perform. Function codes range from 1 to 255, with codes 128 to 255 reserved for error messages from the server device. Code 0 is not used. The size of the data block can vary from zero to the maximum allowed. If the request is processed correctly, the server device returns an ADU containing the requested data.


<div class="mw-translate-fuzzy">
[[File:Modbus_transaction_OK.png|700px|thumb|center|Modbus-transaction without errors]]
[[File:Modbus_transaction_OK.png|700px|thumb|center|Modbus-transaction without errors]]
</div>


----
----
Строка 30: Строка 26:
If an error occurs, the device returns an error code. In the case of a normal transaction, the function code in the response is returned unchanged; in the case of an error, the highest bit of the function code is set to one (that is, the function code + 0x80)
If an error occurs, the device returns an error code. In the case of a normal transaction, the function code in the response is returned unchanged; in the case of an error, the highest bit of the function code is set to one (that is, the function code + 0x80)


<div class="mw-translate-fuzzy">
[[File:Modbus_transaction_ERR.png|700px|thumb|center|Modbus-transaction with errors]]
[[File:Modbus_transaction_ERR.png|700px|thumb|center|Modbus-transaction with errors]]
</div>


----
----
Строка 66: Строка 60:
Discrete inputs are also single-bit registers that describe the state of the device input (for example, voltage — 1). These registers are read-only.
Discrete inputs are also single-bit registers that describe the state of the device input (for example, voltage — 1). These registers are read-only.


<div class="mw-translate-fuzzy">
Holding Registers and Input Registers are represented by a two-byte word and can store values from 0 to 65535 (0x0000 — 0xFFFFF).
Holding Registers and Input Registers are represented by a two-byte word and can store values from 0 to 65535 (0x0000 — 0xFFFFF).
Input registers are read-only (e.g. current temperature). Storage registers support both read and write (to store settings). Currently, in many devices, particularly Wiren Board devices, these registers are not separated. Commands to read the storage register N and the input register N will access the same value in the address space of the device.
Input registers are read-only (e.g. current temperature). Storage registers support both read and write (to store settings). Currently, in many devices, particularly Wiren Board devices, these registers are not separated. Commands to read the storage register N and the input register N will access the same value in the address space of the device.
</div>


===Registers addresses and numbers===
===Registers addresses and numbers===
Строка 91: Строка 83:
|}
|}


<div class="mw-translate-fuzzy">
This misleads how to access the register with the desired number. Moreover, the terms "address" and "register" can be used by the manufacturer arbitrarily. Most often register numbers are specified, such as for Wiren Board devices.In some devices a shorter logical address is applied (.0001 — .9999), and the address uses 5, not 6 digits.
This misleads how to access the register with the desired number. Moreover, the terms "address" and "register" can be used by the manufacturer arbitrarily. Most often register numbers are specified, such as for Wiren Board devices.In some devices a shorter logical address is applied (.0001 — .9999), and the address uses 5, not 6 digits.
</div>


Sometimes the description of a device shall contain only logical addresses. For example, coil register 0 has the address 000001, input register 4 — 400005, etc.
Sometimes the description of a device shall contain only logical addresses. For example, coil register 0 has the address 000001, input register 4 — 400005, etc.
Строка 122: Строка 112:
The manufacturer provides both logical and physical addresses of the registers in the table, which allows us to easily create a device template and illustrate the connection between the logical and physical addresses of the Modbus registers.  
The manufacturer provides both logical and physical addresses of the registers in the table, which allows us to easily create a device template and illustrate the connection between the logical and physical addresses of the Modbus registers.  


<div class="mw-translate-fuzzy">
[[File:SDM220_Template.png|700px|thumb|center|Template Fragment for SDM220 meter]]
[[File:SDM220_Template.png|700px|thumb|center|Template Fragment for SDM220 meter]]
</div>


=== Register reading and writing function codes ===
=== Register reading and writing function codes ===
Строка 164: Строка 152:
=== Modbus request and response data format ===
=== Modbus request and response data format ===


<div class="mw-translate-fuzzy">
Let's take a closer look at how data is exchanged between the client device sending the request and the server device responding to it. The following figure shows how the controller communicates with a device with address 0x01. We want to read 8 coil registers starting from the first one.
Let's take a closer look at how data is exchanged between the client device sending the request and the server device responding to it. The following figure shows how the controller communicates with a device with address 0x01. We want to read 8 coil registers starting from the first one.


[[File:Read_8_Coils_2.png|600px|thumb|center|Data exchange in Modbus]]
[[File:Read_8_Coils_2.png|600px|thumb|center|Data exchange in Modbus]]
</div>


We have received a hexadecimal number 0x2D as data, so the state of eight coil registers in binary form is: 0b10110100.
We have received a hexadecimal number 0x2D as data, so the state of eight coil registers in binary form is: 0b10110100.
Строка 204: Строка 190:
If the request cannot be processed by the server device for one reason or another, it sends an error message in response. The error message contains the address of the Modbus device, the code of the function in which the error occurred, increased by 0x80, the error code and the checksum:
If the request cannot be processed by the server device for one reason or another, it sends an error message in response. The error message contains the address of the Modbus device, the code of the function in which the error occurred, increased by 0x80, the error code and the checksum:


<div class="mw-translate-fuzzy">
[[File:Read_8_Coils_ERR.png|600px|thumb|center|Transaction failed]]
[[File:Read_8_Coils_ERR.png|600px|thumb|center|Transaction failed]]
In this case, we tried to access the nonexistent register address 0xFFFF and tried to read 8 flag registers. As a result, we received error code 0x03 — "an invalid value was passed in The data field".
In this case, we tried to access the nonexistent register address 0xFFFF and tried to read 8 flag registers. As a result, we received error code 0x03 — "an invalid value was passed in The data field".
</div>


The most common Modbus error codes are listed in the following table:
The most common Modbus error codes are listed in the following table:
wb_editors
14 355

правок