Overview: MODBUS TCP on the SIMATIC S7-1200
The SIMATIC S7-1200 CPU family exposes MODBUS TCP as a first-class protocol alongside PROFINET. Two instruction blocks, MB_CLIENT and MB_SERVER, are provided with every TIA Portal installation and implement Modbus Application Protocol V1.1b over TCP/IP per the Modbus Organization specification. The S7-1200 can act simultaneously as a PROFINET IO Controller (or IO Device) and as a Modbus TCP client, a Modbus TCP server, or both, all on the same Ethernet port, because MODBUS TCP is a TCP/IP application-layer protocol that shares the transport stack with PROFINET.
This makes the S7-1200 a practical gateway controller when a third-party drive (such as a Nanotec PD4-E closed-loop stepper, an Oriental Motor AZ series, or a Schneider Lexium), a panel meter, or a remote I/O island uses MODBUS TCP and the rest of the line uses PROFINET. The same CPU can also bridge between Ethernet/IP and Modbus TCP when used with the appropriate instruction blocks, although Ethernet/IP is not natively a Siemens protocol and requires add-on libraries or a CP 1543-1 / CM 1542-1 plug-in module for full scanner support.
Firmware and Software Prerequisites
MB_CLIENT and MB_SERVER are not part of the original S7-1200 firmware V1.0 instruction set. The minimum firmware and software requirements to use the standard library Modbus TCP instructions are:
| Item | Minimum Version | Notes |
|---|---|---|
| S7-1200 CPU firmware | V2.0 or higher (V4.x recommended) | MB_CLIENT/MB_SERVER instructions are added with V2.0; V4.x adds improved diagnostics and 0-based addressing option |
| TIA Portal / STEP 7 | V12 SP1 or higher (V15-V17 recommended) | Library blocks shipped with the installation; no separate library download required |
| S7-1200 CPU part numbers (examples) | 6ES7211-1AE40-0XB0, 6ES7212-1AE40-0XB0, 6ES7214-1BG40-0XB0, 6ES7215-1AG40-0XB0 | All DC/DC/DC and AC/DC/RLY variants in the 1211C/1212C/1214C/1215C/1217C range from firmware V4.0 onward support Modbus TCP out of the box |
| Ethernet port | One PROFINET interface on the CPU; PROFINET/LAN socket X1 | 1215C and 1217C have a second PROFINET port (X2) that can also be used for MODBUS TCP |
The official Siemens application note covering Modbus TCP for the S7-1200 and S7-1500 is Modbus/TCP with the instructions "MB_CLIENT" and "MB_SERVER" (Siemens support entry 102020340). The PDF details block pin assignments, the structure of the instance DB, the difference between 0-based and 1-based Modbus addressing depending on firmware version, and the connection-resource bookkeeping.
If the customer CPU is on firmware V1.0, the standard MB_CLIENT/MB_SERVER blocks are not available. In that case you must either upgrade the firmware (firmware update files are available free of charge from Siemens support) or use the older Modbus TCP library that was distributed as an example project on the old Service & Support portal. For any new design, treat firmware V4.x as the baseline and the older paths as legacy.
MB_CLIENT and MB_SERVER Instruction Architecture
Both blocks are FB-type instructions (function blocks) shipped in the standard library. Each call must be associated with its own instance data block, which Siemens calls the IDB (Instance DB). The IDB stores the connection descriptor, the active request, the partial transaction state, and the diagnostics.
MB_CLIENT input pin map
| Pin | Data type | Meaning |
|---|---|---|
REQ |
BOOL | Rising edge triggers a new Modbus transaction. Pulse the input from the application logic; the block holds the request active internally until the response arrives or a timeout elapses. |
DISCONNECT |
BOOL | Set to TRUE to drop the TCP connection (closes the socket). The block clears the bit once the connection is closed. |
MB_MODE |
USINT | 0 = read, 1 = write (and, depending on the variant, 2..3 for diagnostics). On S7-1500 the additional modes for write-multiple exist; on S7-1200 the same numeric mapping is honored by current firmware. |
MB_DATA_ADDR |
UDINT | Starting Modbus data address. With firmware V4.x the address is 0-based (Modbus-native); with V2.x/V3.x the address is 1-based (matching legacy libraries). The offset must be in the legal range for the function code chosen by MB_MODE. |
MB_DATA_LEN |
UINT | Number of coils, discrete inputs, holding registers, or input registers to transfer. Maximum 125 holding registers or 2000 coils per single Modbus request per the protocol spec. |
MB_DATA_PTR |
VARIANT | Pointer to a DB or bit-memory region in the S7-1200 that holds the user data. The DB must be a standard DB with non-optimized access for older firmware; with firmware V4.4 and TIA Portal V16+ the data pointer can point into optimized-access DBs as well. |
CONNECT_ID |
UDINT | Local identifier for the connection. Must be unique per S7-1200 CPU; reused on the matching MB_SERVER call if both ends are in the same project. |
CONNECT |
VARIANT / TCON_IP_V4 (depending on version) | Pointer to the connection description DB (a DB of type TCON_IP_V4 or TCON_IP_RFC1006 in current TIA Portal). Contains the partner IP address, remote port (default 502), and local port. |
MB_CLIENT output pin map
| Pin | Data type | Meaning |
|---|---|---|
DONE |
BOOL | One-cycle TRUE pulse on successful completion of the last request. |
BUSY |
BOOL | TRUE while a request is in flight. |
ERROR |
BOOL | TRUE if the last request failed. |
STATUS |
WORD | Hex error/status code. W#16#0000 = OK, W#16#7000 = no request active, W#16#7001 = first call, W#16#7002 = subsequent call, W#16#8380 to W#16#87FF = Modbus exception codes and TCP-layer errors (see Diagnostics section). |
MB_SERVER pin map (truncated to essentials)
| Pin | Type | Meaning |
|---|---|---|
DISCONNECT |
BOOL in | Drop all active client connections. |
MB_HOLD_REG |
VARIANT in | Pointer to the holding-register area exposed by the server (read/write holding register FC03/FC06/FC16). |
CONNECT_ID |
UDINT in | Local connection ID; matches the corresponding MB_CLIENT ID if mirrored in the same project. |
CONNECT |
VARIANT in | Pointer to TCON_IP_V4 connection DB; specifies the listen port (502 by default). |
NDR, DR, ERROR, STATUS
|
out | New-data, data-read, error, and status flags analogous to MB_CLIENT but driven by incoming requests rather than outgoing ones. |
Port Sharing: PROFINET and MODBUS TCP on One Socket
The S7-1200 CPU exposes a single physical PROFINET port (X1 on most models). PROFINET RT and MODBUS TCP both ride on top of TCP/IP, with PROFINET using UDP/IP for real-time class 1 frames and TCP/IP only for non-RT traffic such as engineering and diagnostics. The S7-1200 TCP/IP stack allows multiple TCP server ports to listen on the same IP address and multiple TCP clients to originate connections from the same IP address. This means:
- The S7-1200 can be a PROFINET IO Controller and a MODBUS TCP server on the same X1 port, both bound to the same IP.
- The S7-1200 can be a PROFINET IO Controller and a MODBUS TCP client to one or more third-party servers on the same X1 port.
- CPU 1215C and CPU 1217C have a second port (X2) that can be assigned a different IP subnet; both ports run the same protocols independently.
The connection-resource bookkeeping is split: PROFINET uses one connection slot per IO Device plus reserved slots for the IO Controller itself; MODBUS TCP uses the OPC UA / open TCP / ISO-on-TCP connection pool. On a CPU 1214C, for example, you have up to 8 open Modbus TCP connections available for MB_CLIENT plus the MB_SERVER listen socket. The exact numbers are documented per CPU in the S7-1200 System Manual, entry SIMATIC S7-1200 Programmable Controller System Manual (109741593).
Connection Limits and Resource Planning
Connection limits are a frequent source of commissioning surprises. The S7-1200 splits its connections between PROFINET and open-communication services:
| CPU | Open-communication (TCP/ISO-on-TCP/UDP) connections total | Reserved PROFINET connections | Effective max MB_CLIENT sockets |
|---|---|---|---|
| CPU 1211C / 1212C | 8 | 3 | Up to ~5 client sockets in practice, but check the System Manual for the exact reservation scheme on your firmware |
| CPU 1214C | 8 | 3 | Same as above; verify against the System Manual for your firmware |
| CPU 1215C / 1217C | 8 + 8 (port X2 has its own pool) | 3 per port | Effectively up to 8 clients per port, 16 clients total if both ports are used for Modbus |
These figures are conservative and depend on firmware revision; the canonical table lives in the System Manual chapter on "Communication services and connection resources". When you approach the limit, the MB_CLIENT STATUS word reports W#16#8085 (no resources available) or W#16#8086 (partner reports resources exhausted). Plan your architecture accordingly: if you have eight third-party Modbus devices, consider a CP 1542-1 to take the load off the CPU, or switch to PROFINET for the higher-density part of the network.
Step-by-Step Configuration in TIA Portal
- Add the S7-1200 CPU to the project and configure its PROFINET interface (X1) with the IP address, subnet mask, and router (if any). Confirm firmware revision is at least V2.0; V4.x recommended.
- In the project tree, open Devices & Networks > Network view, drag the S7-1200 into the Ethernet subnet. If you are also wiring PROFINET devices, add them in the same view.
- Open the S7-1200 program blocks and create a new FB or use the program OB1 (main) for the Modbus call. Drag Communication > Modbus TCP > MB_CLIENT from the Instructions task card into the network. Confirm the dialog asking for the instance DB name and number.
- Create the connection description DB. Right-click Program blocks > Add new block > Data block, set it to type "Global DB", and declare a variable of system data type
TCON_IP_V4. Populate the fields:\li>
InterfaceId := 64#0000_0001 // PROFINET interface 1
Id := 1 // connection ID (must match CONNECT_ID)
ConnectionType := 16#0B // TCP/IP
ActiveEstablished := TRUE // client opens the connection
RemoteAddress := '192.168.0.50' // partner IP (third-party Modbus device)
RemotePort := 502 // standard Modbus TCP port
LocalPort := 0 // 0 = any free local port
- Create a standard data block
DB_ModbusDatafor the data buffer. Declare the Modbus registers asARRAY[0..49] OF WORDfor 50 holding registers, plus anARRAY[0..7] OF BOOLorARRAY[0..7] OF WORDfor coil-style access. The data type must match the FC you are issuing:WORDfor holding- and input-register FCs,BOOLfor coil- and discrete-input FCs. - Wire the MB_CLIENT inputs. Example for a read-holding-register request to address 0, length 10:
REQ := tagCycle_500ms; // 500 ms pulse MB_MODE := 0; // read MB_DATA_ADDR := 0; // start at Modbus address 0 (0-based on V4.x) MB_DATA_LEN := 10; // 10 holding registers MB_DATA_PTR := "DB_ModbusData".HR[0]; // data buffer CONNECT_ID := 1; // match the TCON_IP_V4 DB CONNECT := "DB_Conn_1".Connection; // pointer to the TCON_IP_V4 struct - Add error handling. On every rising edge of
ERROR, copySTATUSinto a non-volatile diagnostic word and trigger an HMI message. Common status codes are mapped in the next section. - Compile, download, and go online. Open the instance DB in watch mode; verify that
REQproduces aBUSYcycle, thatDONEpulses, and that the data buffer updates. - For MB_SERVER, drop the server block into a separate network (or a cyclic OB), wire
MB_HOLD_REGto your holding-register DB, and confirm the same IP/port pair that MB_CLIENTs use as the destination. NoREQis needed; the server is event-driven.
Performance Tradeoffs vs PROFINET
PROFINET IRT class 1 on the S7-1200 supports a send clock of 1 ms with cycle times of 2 to 4 ms for typical IO Device configurations. PROFINET RT without IRT typically runs at 4 to 32 ms cycle time, depending on the number of devices and the slot configuration. The PROFINET cycle is hardware-driven and synchronized across the network.
MODBUS TCP is a polled, request/response protocol. The achievable cycle time on the application side is a function of:
- Number of registers requested per transaction (1 to 125 holding registers per FC03 call).
- Number of transactions the application issues per cycle (sequential, no parallelism within a single MB_CLIENT instance; you can run multiple MB_CLIENT FBs in parallel against different partners).
- Network round-trip time: a typical gigabit Ethernet switch adds 10 to 100 microseconds; the partner device's request-processing time dominates and is often 1 to 10 ms.
- TIA Portal scan time of the OB that drives
REQ; if you pulseREQevery 50 ms in OB1 and each transaction takes 5 ms, you have a 55 to 60 ms effective loop time.
For motion applications, MODBUS TCP generally updates setpoint and actual-value registers in the 10 to 100 ms range. PROFINET IRT can deliver 2 to 4 ms deterministic updates to a PROFINET drive profile. If the closed-loop stepper (such as the Nanotec PD4-E601L42-E-65-4) is being commanded by position setpoints every 20 to 50 ms and reads back actual position at the same rate, MODBUS TCP is often sufficient. If you need sub-10 ms deterministic updates, PROFINET is the better choice and many drive vendors (including Nanotec, in the PD4-E PROFINET variant) support the PROFIdrive profile over PROFINET.
| Aspect | MODBUS TCP on S7-1200 | PROFINET on S7-1200 |
|---|---|---|
| Cycle determinism | Best-effort, polled | Hardware-synchronized (IRT) or scheduled (RT) |
| Typical cycle time | 10 to 100 ms application-dependent | 1 to 32 ms (RT) / 1 to 4 ms (IRT class 1) |
| Cabling | Standard Cat 5e or better Ethernet | Same; PROFINET cable recommended for industrial use |
| Configuration effort | Low: a few block calls in TIA Portal | Medium: GSDML import, device configuration, slot mapping |
| Diagnostics | STATUS word + instance DB; no automatic IO diagnostics | Channel-level diagnostics, port statistics, device-replacement-without-removable-medium (for IO Devices) |
| Vendor adoption | Very broad (any drive, meter, instrument with Ethernet) | Broad in Europe; less universal in North American discrete and process markets |
Diagnostics: STATUS Word Decoding
The STATUS output of MB_CLIENT and MB_SERVER carries a hex code that classifies the failure. Keep these in a fault-matrix tag and expose it to the HMI for the operator. The most useful codes are:
| STATUS (hex) | Source | Meaning | Field action |
|---|---|---|---|
| W#16#0000 | Both | OK | None |
| W#16#7000 | Both | No request active | None |
| W#16#7001 | MB_CLIENT | First call; establishing connection | Wait; allow up to TCP connect timeout |
| W#16#7002 | MB_CLIENT | Subsequent call; request sent, awaiting response | Wait |
| W#16#8380 | MB_CLIENT | Modbus exception 0x01 — Illegal Function | Partner does not support the requested FC; check MB_MODE mapping |
| W#16#8381 | MB_CLIENT | Modbus exception 0x02 — Illegal Data Address | MB_DATA_ADDR is outside the partner's valid range; check partner register map |
| W#16#8382 | MB_CLIENT | Modbus exception 0x03 — Illegal Data Value | MB_DATA_LEN is invalid for the FC; or write value out of range |
| W#16#8383 | MB_CLIENT | Modbus exception 0x04 — Slave Device Failure | Partner reports internal error; check partner diagnostics |
| W#16#8085 | Both | No local connection resources | Reduce concurrent Modbus connections or add a CP module |
| W#16#8086 | Both | Partner connection resources exhausted | Partner has too many open TCP connections; close unused ones |
| W#16#80C8 | MB_CLIENT | Connection ID already in use | Pick a unique CONNECT_ID per CPU; the TIA Portal cross-reference catches this at compile time |
| W#16#80D2 | MB_CLIENT | Partner did not respond within the configured timeout | Increase timeout, check cabling and switch |
Decoding the STATUS word with a simple case statement gives the operator a clear text on the HMI and turns Modbus into a diagnosable service instead of a black box.
Frequently Asked Questions
Does every S7-1200 CPU with PROFINET support MODBUS TCP?
Every S7-1200 CPU from firmware V2.0 onward supports MODBUS TCP as both client (MB_CLIENT) and server (MB_SERVER). Firmware V1.0 does not include the standard library instructions; upgrade the firmware or use the older legacy library. The functionality is independent of whether the CPU is acting as a PROFINET IO Controller or IO Device — the two share the same Ethernet port without conflict.
What is the main performance tradeoff of MODBUS TCP versus PROFINET on the S7-1200?
PROFINET IRT delivers 2-4 ms hardware-synchronized cycle times; PROFINET RT typically runs 4-32 ms. MODBUS TCP is polled and request-response, so the application-side update rate is set by your REQ period and the partner's response time, typically 10-100 ms. For closed-loop stepper applications with 20-50 ms setpoint intervals MODBUS TCP is usually adequate; for sub-10 ms deterministic motion choose PROFINET.
Can the S7-1200 act as a MODBUS TCP client and a MODBUS TCP server on the same Ethernet port?
Yes. MB_CLIENT opens outgoing TCP connections to one or more remote servers, and MB_SERVER opens a listening socket (default port 502) for incoming client connections. Both blocks use the same S7-1200 IP address on X1 (or X2 on 1215C/1217C). Each MB_CLIENT instance consumes one of the S7-1200's open-communication connection resources; the CPU 1214C, for example, has up to 8 such resources available after PROFINET reservations.
How do I choose between 0-based and 1-based Modbus addresses in MB_DATA_ADDR?
On S7-1200 firmware V4.x the MB_DATA_ADDR input is 0-based, matching the Modbus protocol specification natively (address 0 corresponds to Modbus register 40001). On older firmware V2.x/V3.x the input was 1-based and you had to subtract 1 from the partner's documented Modbus address before passing it to the block. Check the block help for the firmware you are running before commissioning; getting this wrong produces STATUS W#16#8381 (Illegal Data Address).
Does MODBUS TCP on S7-1200 work with Ethernet/IP devices on the same network?
MODBUS TCP and EtherNet/IP share the same physical Ethernet and can coexist on a managed switch without interference because they use different TCP/UDP ports. The S7-1200 itself does not include a native EtherNet/IP scanner; to talk to EtherNet/IP devices you would add a CP 1543-1 or use a third-party add-on library. The S7-1200's MB_CLIENT/MB_SERVER blocks talk only to MODBUS TCP endpoints, not to EtherNet/IP endpoints, even though both are TCP-based.