Modbus TCP on an S7-1200 comes down to letting the CPU act as a client or a server, exchanging frames through instruction blocks and mapping internal data areas onto Modbus register addresses. Configuration has four steps: decide the role, set the connection parameters, call the instruction blocks, and check the address mapping.
Modbus RTU runs over a serial port, addressing devices by station number and carrying a CRC. Modbus TCP runs over Ethernet, distinguishing devices by IP address and port; the unit identifier survives in the frame but the CRC does not, because Ethernet checks the frame itself. So configuration shifts from baud rate and parity to IP address, port and connection resources. The function codes and the data model are the same, so the way you think about register mapping carries over.
The side that initiates requests and reads or writes the other's data is the client; the side that waits to be asked and supplies data is the server. Having the PLC act as client to read meters and instruments is common practice; when the PLC acts as server for a host computer, you only configure it and let it listen on the port, with no client instruction to call. Get the role wrong and both the instruction block and the direction of data are wrong.
Start by giving the CPU's Ethernet port an IP address and subnet mask in the device configuration, making sure it is on the same subnet as the partner. Then, in the background data block of the instruction, specify the connection type, the connection ID, the partner IP address and the port (Modbus TCP uses port 502 by default). The connection ID must be unique within one CPU; several connections must not share a single ID.
Use MB_CLIENT for the client and MB_SERVER for the server. MB_CLIENT takes the connection ID, request type, remote address, data length and a pointer to the local data area; it works on a polling basis, so it must be driven by the REQ trigger together with the DONE, BUSY and ERROR status bits, and must not fire a fresh request every scan. For several slave devices, give each its own connection or poll them in turn, so that concurrent requests on one port do not collide.
Modbus register addresses are normally numbered from 1, whereas a PLC data-area pointer starts at 0, so an offset of one often has to be applied. A register holds 16 bits, so a 32-bit float or integer occupies two registers and the word order matters; on some devices it is the reverse of the PLC, and the value read back looks absurd until the words are swapped. Once the mapping is built, verifying with a small number is the safest check.
| Parameter | Meaning | Common setting | Consequence of a mistake |
|---|---|---|---|
| Role | Client or server | Decided by the data direction | Instruction and data direction reversed |
| IP address | Network address of the device | Same subnet as the partner | Connection cannot be established at all |
| Port | Communication port number | Standard is 502 | Connection refused or timed out |
| Connection ID | Connection number inside the CPU | Unique per connection | Connection conflict or reuse error |
| Unit identifier | Points to a device behind a gateway | Used only in gateway setups | Wrong device addressed |
| Function code | Read or write method | Chosen by register type | Wrong area read |
| Start address | First register number | Watch the 1-based or 0-based convention | Everything offset by one |
| Data length | Number of registers | Within the device limit | Frame rejected |
| Word order | High/low word arrangement | Per the device manual | 32-bit values scrambled |
Modbus TCP is a master/slave protocol, and one connection handles only one request at a time, so the refresh rate depends on the polling cycle; do not expect the synchronous behaviour of a real-time bus. For several devices exchanging data at speed, consider PROFINET instead, or poll in groups. During commissioning, verify the register addresses with dedicated Modbus test software before entering them in the instruction block.
The Modbus application-layer protocol and data model follow the GB/T 19582 series (equivalent to the Modbus specification), and its implementation over Ethernet follows the corresponding national standard in that series and the relevant part of IEC 61158. Programming and instruction use follow GB/T 15969.3 (identical to IEC 61131-3). Ports and register addresses of a specific device are as stated in the manufacturer's communication manual, and the electrical connection, protection and earthing of the communicating equipment follow GB 5226.1 and the equivalent international standard IEC 60204-1.
Stop the machine, isolate, prove dead and apply lock-out/tag-out before changing configuration or wiring. When altering network parameters, avoid clashing with an existing production network, and after commissioning update the network address register and restrict external write access.