IMDHMIControls LibraryShop main store

Troubleshooting

How one S7-1200 polls five Modbus TCP slaves with MB_CLIENT

Industrial networks Published 7 min read By IMDHMI controls team

Short answer

One S7-1200 reads five Modbus TCP slaves reliably when each server gets its own MB_CLIENT call: own instance data block, own connection identifier, own connection data, sequenced so every transaction finishes before the next begins. Count all connections on the CPU — clients, servers, HMI, engineering — against the CPU's documented maximum, and branch every fault per server.

On this page
  1. Why one instance cannot carry five servers
  2. The arrangement that works: one MB_CLIENT call per server
  3. Sequence the requests and time the rotation
  4. Count the CPU's connections before you commit
  5. Branch every fault per server
  6. The decision for each layout
  7. Questions asked

Five Modbus TCP slaves on one S7-1200 is a solved problem, and the fix is structural rather than a timing trick: one MB_CLIENT call per server, each with its own instance data block, its own connection identifier and its own connection data, sequenced so that every transaction finishes before the next one begins. The failure that usually sends engineers looking — the first server answers and the rest time out, or servers stop answering after the client switches target — comes from one instance carrying five servers' connection state at once. Work the checks in that order: pairing, sequencing, connection budget, per-server diagnostics.

Why one instance cannot carry five servers #

MB_CLIENT is asynchronous. The call holds state across scans while it opens the TCP connection, sends the request and waits for the answer, and that state lives in the instance data block. Rewrite the connection data of a live instance so it points at the next server, and the stored connection state belongs to the previous server while the request belongs to the new one. Slaves react by holding a half-open connection and timing out on everything that follows: the first server answers, the rest go quiet, and nothing in the network hardware is wrong.

The reuse pattern that is documented draws the line exactly. Several requests over one connection work with the same instance data block, the same connection identifier and the same port number — which makes it several requests to one server, never five servers through one instance. The mirror-image fault, two instances pointed at a single server, stops reads the same way; that case is covered in why two MB_CLIENT instances stop Modbus TCP reads from one server. Both are pairing errors, and both fix the same way: the set of instance, connection identifier, port and remote address is fixed, and it is one set per connection.

The arrangement that works: one MB_CLIENT call per server #

Give every server its own call and its own fixed set of connection data:

  • One MB_CLIENT call per server, each invoked from its own step in the polling sequence rather than unconditionally every scan.
  • One instance data block per call. A multi-instance block inside the polling function block works and wires the same way as the single-server case; see multi-instance Modbus blocks and MB_DB links in an S7-1200.
  • One connection identifier per instance, different from every other connection on the CPU.
  • One connection data structure per instance: for the V4 library generation of MB_CLIENT that is TCON_IP_v4, which carries the server's IPv4 address, the remote port and the connection identifier, and marks the S7-1200 as the side that actively establishes the connection.
  • One status set per server: last successful update and current error recorded separately, so a fault on the fifth server never masquerades as a fault on the first.

Modbus TCP servers listen on TCP port 502 unless configured otherwise, so an endpoint is an IP address plus a port. Five simulated slaves on one computer are still five endpoints if each listens on its own port, for example 502 through 506; five devices usually hold one address each.

Sequence the requests and time the rotation #

Each instance carries one transaction at a time, and the scan keeps running while the request is on the wire, so the program owns the order — the instruction's documented example for coordinating multiple requests says plainly that each individual request must finish execution and that your program logic controls the sequence. The pattern:

  • Step n drives the request input of instance n and holds until that instance's done or error output sets, whatever your installed library names them.
  • On done or error, record the result, advance the counter and pulse the next instance.
  • Leave every connection established across the whole rotation: connect once, poll forever, no disconnect between requests.
  • Use the documented DISCONNECT input only when you deliberately take a server out of the rotation, and let that call finish before anything else touches the instance.

That queue-one-transaction discipline is the same one that lets a queued function block poll many Modbus RTU slaves over one serial port; the transport differs, the interlock does not — polling many Modbus RTU slaves with one queued function block.

Worked example: servers at 192.168.1.11 through 192.168.1.15, one transaction at a time, each read pulling ten holding registers with a round trip of 60 ms (an illustrative figure for a healthy LAN; take yours from the done timestamps):

  • Healthy rotation: 5 × 60 ms = 300 ms, so every server's data is at most 300 ms old.
  • Fifth server dead with an example response timeout of 3 s and no retry scheduling: 4 × 60 ms + 3000 ms = 3240 ms per rotation, and the four live servers drop to an update roughly every 3.2 s.
  • With retry scheduling: skip the dead address, the rotation returns to 4 × 60 ms = 240 ms, and the dead server gets one probe request every 10 s; an answer puts it back in the rotation.

The stuck-done fault — the request input pulsing while the done output never sets — shows up on plain TCON, TSEND and TRECV calls too, and its fix pattern is the subject of guide to a TCON, TSEND or TRECV done output that never sets.

Count the CPU's connections before you commit #

Every connection on the CPU draws from one budget: the instruction documentation states that the total number of connections of one CPU, Modbus TCP clients and servers included, must not exceed the maximum the CPU supports. That maximum is published per CPU and firmware in the CPU manual; the counting rule is universal.

Worked count for this layout: five MB_CLIENT client connections, plus one HMI panel and one engineering laptop, total 7, and 7 is the number that must sit at or below the documented maximum for that CPU and firmware. The Modbus client connections are rarely what breaks a budget — panels, engineering stations, PUT/GET partners and any server connections share it.

Decision: if the count fits, keep five instances and five connections; five servers never require five simultaneous transactions, only five accounted connections. If it does not fit, do not shrink the instance count and re-target one instance — that reinstates the original fault. Move the units behind a Modbus TCP gateway instead: one connection, one instance, a distinct unit identifier per device, still one transaction at a time.

Branch every fault per server #

Record per server, not per CPU: keep the last successful update and the current error for each address. A receive buffer can still hold an old, valid value after communication stops, so if polled values drive outputs, treat a missed update as a control fault and fail that function safe — stale data is a process hazard, not a network symptom.

Branch on what the transaction returns:

What you see Where the fault lives Next check
No TCP connection Endpoint, path or connection budget Server address and port, host firewall, port already occupied, the CPU connection count
Connection up, then timeout No timely answer Server load, gateway routing — why an S7-1200 Modbus TCP client shows no data through a gateway — and the response watch time
Exception returned The server received and rejected the request Function code, register address, quantity; a ten-register read against a shorter map is the multi-register read fault reported as error 8383, covered in why MB_CLIENT returns Modbus TCP error 8383 on multi-register reads
Values arrive but are wrong Mapping or interpretation 40001-based versus zero-based addressing, word order across registers, signed interpretation

An exception code is the server naming the request field it rejected; the meanings of codes 01, 02, 03, 04 and 06 are in the first FAQ answer below. An exception and a timeout follow different branches: a rejected request is fixed in the client's request, a timeout is fixed on the network or the server.

The decision for each layout #

  • Five servers on five addresses: five MB_CLIENT calls, five instance data blocks, five connection identifiers, one TCON_IP_v4 per server, one transaction at a time across the rotation, connections left established between polls, total counted against the CPU's documented connection maximum.
  • Several units behind one gateway address: one MB_CLIENT call, one connection, one instance, a different unit identifier per unit, checked against the gateway's documented unit routing.
  • Connection count over budget: move endpoints behind a gateway; never re-target a live instance between servers.
  • One server goes quiet after commissioning: read that server's own last-good timestamp first. If it froze at the moment the target switched, the pairing was the fault, not the network.

Questions asked

What do Modbus exception codes 01, 02, 03, 04 and 06 mean?

An exception is the server rejecting the request and naming the field. Code 01 is an illegal function, so the function code is not implemented on that server. 02 is an illegal data address, so the address or quantity falls outside the server's register map. 03 is an illegal data value. 04 is a server device failure. 06 is server device busy: the request was accepted but the answer is not ready, so wait and retry once rather than hammering the server.

Can the five reads overlap instead of running one at a time?

They can. Each instance holds its own connection, so requests to different servers can be in flight simultaneously as long as every connection fits inside the CPU's documented connection maximum. Each instance still carries only one transaction at a time, and each request must still be verified complete before that instance is reused. Sequential polling remains the simpler arrangement to commission and diagnose, which is why it is the default here.

What unit identifier does a request to these servers carry?

The unit identifier is a field in every Modbus TCP request, and the IP address alone does not settle it. A device reached directly over TCP conventionally answers to identifier 255. A device behind a gateway answers to the unit number that routes to it, so five units behind one gateway address need five different identifiers on the one shared connection. Take each value from that device's or gateway's own documentation.

Does the simulator's .MBS file load into TIA Portal?

No. A .MBS file is the configuration of the simulator application that created it, so open it inside that application and confirm its endpoints and register maps match what the PLC requests. The PLC project needs nothing from the file itself: only the server addresses, ports and register addresses that the simulator is actually serving. A file extension alone does not identify a supported import path.

Keep reading

  • Troubleshooting

    Why an HMI Modbus TCP write leaves the S7-1200 DB unchanged

    The write most likely never reached the register you think it did: the HMI's 400001 is a one-based display number, while the Modbus request carries a zero-based offset that the server block maps onto DB102.DBW0. Confirm the server block status and data area, confirm station 3 points at the S7-1200 rather than the motion controller, match the driver's register convention, and prove the path with one known value written to a single word.

    Industrial networks

  • Troubleshooting

    Why an S7-1500 X2 Modbus server accepts TCP but no DONE arrives

    The client's 0001-to-7005 loop means it builds a connection, sends a request and never receives an accepted response; the completed 7006 state and DONE never arrive. A blank Telnet session proves only that X2 accepts TCP on port 502. Match TCON_IP_v4.InterfaceID to X2's hardware identifier from device configuration, then read the one-scan ERROR and STATUS with a trace.

    Industrial networks

  • Troubleshooting

    Making an FX5U a Modbus TCP server for a KTP700 panel

    A SIMATIC KTP700 BASIC can only open Modbus TCP requests, so the FX5U must answer them as the server; enabling Modbus TCP in GX Works3 and TIA Portal together opens nothing. Prove the Ethernet path, enable the FX5U's Modbus TCP slave service in its Ethernet module parameters, point the panel connection at the FX5U address on port 502, and bind one test tag to a known register before scaling up.

    Industrial networks