meta data for this page
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| automation:s7_modbus [2026/03/24 19:50] – [Modbus/TCP] vamsan | automation:s7_modbus [2026/03/25 08:46] (current) – [Modbus/TCP] vamsan | ||
|---|---|---|---|
| Line 67: | Line 67: | ||
| Although quite different, they can sometimes be integrated, such as in multimaster (hybrid) RTU scenarios. In this scenario, a signal converter needs to be integrated into the TCP network. The converter has its own IP address to receive Modbus/TCP telegrams. It's crucial that the client is aware of the Modbus/RTU network behind the converter, which uses traditional RTU addressing. Often, clients cannot manage both RTU addressing and TCP simultaneously, | Although quite different, they can sometimes be integrated, such as in multimaster (hybrid) RTU scenarios. In this scenario, a signal converter needs to be integrated into the TCP network. The converter has its own IP address to receive Modbus/TCP telegrams. It's crucial that the client is aware of the Modbus/RTU network behind the converter, which uses traditional RTU addressing. Often, clients cannot manage both RTU addressing and TCP simultaneously, | ||
| + | |||
| + | |< 100% >| | ||
| + | |{{ : | ||
| |< 100% >| | |< 100% >| | ||
| Line 79: | Line 82: | ||
| ^Addressing|Master ID: 0, slave ID: 1 to 247|IP Address (like: // | ^Addressing|Master ID: 0, slave ID: 1 to 247|IP Address (like: // | ||
| ^Wiring|3-core cable with shielding or 4-core cable|Ethernet cables (RJ45) and network switches| | ^Wiring|3-core cable with shielding or 4-core cable|Ethernet cables (RJ45) and network switches| | ||
| - | |||
| - | |||
| - | |< 100% >| | ||
| - | |{{ : | ||
| ==== Modbus/RTU ==== | ==== Modbus/RTU ==== | ||
| + | {{ : | ||
| + | Modbus/RTU was the first Modbus communication method and remained the main standard until Ethernet became popular. It remains widely used today, partly because its hardware integration is simpler and more affordable than Modbus/TCP. As a result, it is likely to stay available for quite some time. | ||
| === Comparison of RS-232 and RS-485 === | === Comparison of RS-232 and RS-485 === | ||
| Line 174: | Line 175: | ||
| === Modbus/RTU Error Checking (CRC) === | === Modbus/RTU Error Checking (CRC) === | ||
| - | Even though "No Parity" | + | Even though |
| The **CRC** (//Cyclic Redundancy Check//) is an error-detection method that ensures data integrity in Modbus RTU. It is a 16-bit (2-byte) value appended to each message. | The **CRC** (//Cyclic Redundancy Check//) is an error-detection method that ensures data integrity in Modbus RTU. It is a 16-bit (2-byte) value appended to each message. | ||
| Line 185: | Line 186: | ||
| ==== Modbus/TCP ==== | ==== Modbus/TCP ==== | ||
| + | {{ : | ||
| Modbus/TCP (also known as Modbus TCP/IP) is a version of the Modbus protocol designed for Ethernet network communication. It wraps standard Modbus messages into TCP/IP packets, enabling reliable, high-speed data exchange. | Modbus/TCP (also known as Modbus TCP/IP) is a version of the Modbus protocol designed for Ethernet network communication. It wraps standard Modbus messages into TCP/IP packets, enabling reliable, high-speed data exchange. | ||
| Line 193: | Line 195: | ||
| * **Addressing: | * **Addressing: | ||
| - | === Modbus TCP Frame Structure === | ||
| - | The Modbus TCP frame (// | + | ==== Modbus/TCP and Modbus/RTU Hybrid ==== |
| - | + | {{ : | |
| - | |< 100% >| | + | |
| - | ^Field^Length^Description| | + | |
| - | ^Transaction ID|2 Bytes|A request number used to match responses with requests.| | + | |
| - | ^Protocol ID|2 Bytes|Always 0 for Modbus services.| | + | |
| - | ^Length|2 Bytes|Count of remaining bytes (Unit ID + PDU).| | + | |
| - | ^Unit ID|1 Byte|Used for routing through gateways to serial Modbus devices; otherwise often set to 255 or 0.| | + | |
| - | ^Function Code|1 Byte|Defines the operation (e.g., Read Holding Registers).| | + | |
| - | ^Data Field|Variable|Contains the actual payload (register addresses, values, etc.).| | + | |
| ==== Modbus Registers and Coins ==== | ==== Modbus Registers and Coins ==== | ||
| Modbus data is structured into four main //" | Modbus data is structured into four main //" | ||
| Line 228: | Line 221: | ||
| {{ : | {{ : | ||
| - | ==== Modbus Telegram structure ==== | + | |
| + | ==== Modbus Telegram | ||
| + | In Modbus, the Application Data Unit (ADU) represents the complete message frame sent over a physical network. It functions as an //" | ||
| + | |||
| + | The ADU' | ||
| + | |||
| + | {{ : | ||
| + | |||
| + | |< 100% 50% 50% >| | ||
| + | |**Modbus/ | ||
| + | |**MBAP** Header (7 Bytes): \\ - Transaction ID (2 Bytes): Matches requests with responses. \\ - Protocol ID (2 Bytes): Always 0 for Modbus. \\ - Length (2 Bytes): Number of remaining bytes. \\ - Unit ID (1 Byte): Used for routing to serial devices through a gateway. \\ **PDU** (Function Code + Data): The core command. \\ \\ Max Size: 260 bytes.|Slave **Address** (1 Byte): Identifies the target device (1–247). \\ **PDU** (Function Code + Data): The core command. \\ **CRC** (2 Bytes): A Cyclic Redundancy Check used to detect transmission errors. \\ \\ Max Size: 256 bytes.| | ||
| + | |||
| + | Error checking by Modbus/TCP is managed by the TCP layer and is not included in the ADU. | ||
| + | |||
| + | === Modbus Protocol Data Unit (PDU) === | ||
| + | The //Modbus Protocol Data Unit// (**PDU**) is the core message structure common to all Modbus variants (RTU, ASCII, and TCP). It defines the actual command and data being exchanged between a client and a server, independent of the network medium. The PDU consists of two primary fields with a maximum combined size of 253 bytes. | ||
| + | |||
| + | ^Field^Size^Description| | ||
| + | ^Function Code|1 Byte|Tells the server which action to perform, such as Read, Write, Diagnostic.| | ||
| + | ^Data Field|0–252 Bytes|Contains request details such as register addresses, quantities, or the actual data values being transmitted or returned.| | ||
| + | |||
| + | **Function Code Types** | ||
| + | |||
| + | The function code ranges from 1 to 255 and is categorized by its purpose: | ||
| + | * **Public Codes (1–64, 73–99, 111–127): | ||
| + | * **User-Defined Codes (65–72, 100–110): | ||
| + | * **Exception Responses (128–255): | ||
| + | |||
| + | **Data Field Structure** | ||
| + | |||
| + | The structure of the data field changes depending on whether the PDU is part of a Request or a Response: | ||
| + | |||
| + | * In a **Request**, | ||
| + | * In a **Response**, | ||
| + | * **Addressing: | ||
| + | |||
| + | **Data Encoding (Endianness)** | ||
| + | |||
| + | Modbus uses Big-Endian representation for all 16-bit values within the PDU. This means the //Most Significant Byte// (**MSB**) is transmitted before the //Least Significant Byte// (**LSB**). // | ||
| + | |||
| + | === Modbus Function Codes === | ||
| + | The table below details the standard Modbus function codes, which cover data access, diagnostics, | ||
| + | |||
| + | |< 100% >| | ||
| + | ^Code (Hex)^Code (Dec)^Function Name^Data Type^Access| | ||
| + | ^0x01|01|Read Coils|Bit (0x)|Read| | ||
| + | ^0x02|02|Read Discrete Inputs|Bit (1x)|Read| | ||
| + | ^0x03|03|Read Holding Registers|16-bit (4x)|Read| | ||
| + | ^0x04|04|Read Input Registers|16-bit (3x)|Read| | ||
| + | ^0x05|05|Write Single Coil|Bit (0x)|Write| | ||
| + | ^0x06|06|Write Single Register|16-bit (4x)|Write| | ||
| + | ^0x07|07|Read Exception Status|Serial Only|Read| | ||
| + | ^0x08|08|Diagnostics|Internal|Read| | ||
| + | ^0x0B|11|Get Comm Event Counter|Serial Only|Read| | ||
| + | ^0x0C|12|Get Comm Event Log|Serial Only|Read| | ||
| + | ^0x0F|15|Write Multiple Coils|Bit (0x)|Write| | ||
| + | ^0x10|16|Write Multiple Registers|16-bit (4x)|Write| | ||
| + | ^0x11|17|Report Server ID|Serial Only|Read| | ||
| + | ^0x14|20|Read File Record|File|Read| | ||
| + | ^0x15|21|Write File Record|File|Write| | ||
| + | ^0x16|22|Mask Write Register|16-bit (4x)|Write| | ||
| + | ^0x17|23|Read/ | ||
| + | ^0x18|24|Read FIFO Queue|16-bit|Read| | ||
| + | ^0x2B|43|Read Device Identification|Internal|Read| | ||
| + | |||
| + | **Function Code Categories** | ||
| + | |||
| + | * **Public Function Codes (1–64, 73–99, 111–127): | ||
| + | * **User-Defined Codes (65–72, 100–110): | ||
| + | * **Exception Codes (128–255): | ||
| ==== Modbus test programs, test methods ==== | ==== Modbus test programs, test methods ==== | ||