1. Problem Overview: MB_CLIENT Permanently Stuck on Status 7002
The MB_CLIENT instruction on a SIMATIC S7-1500 (CPU 1512 SP FW ≤ V2.x with TIA Portal V13 SP1) reads a constant status word of 16#7002 (decimal 28674) while attempting to reach a Modbus TCP server hosted on a PC. The instruction never transitions to 16#818C (timeout, server unreachable) and never reports a TCP-level error such as 16#80A1 or 16#80A4. The same S7-1500 configured as a Modbus server using MB_SERVER against the same PC (running Modscan) responds normally. This asymmetric fault is the classic signature of an outbound connection that the kernel TCP stack cannot complete because the remote endpoint never completes the three-way handshake, while no ICMP unreachable / RST is generated back to the CPU.
Status 7002 corresponds to the on-the-wire state "Connection being established." Because TIA Portal V13 SP1's MB_CLIENT internal implementation waits on a passive SYN-ACK from the target and the connection-establishment retry window is bounded only by the OS-level connect timeout, the instruction can remain in 7002 for the full TCP retransmit lifetime (typically 60-120 s on the S7-1500 PROFINET stack) and then return to a steady 7002 instead of surfacing 818C if the underlying socket was re-armed by the background OUC (Open User Communication) task. This makes 7002 look stuck even though the connection attempt is still alive in the background.
2. System Configuration and Topology
The reference configuration that reproduces the issue is documented below.
| Item | Value |
|---|---|
| CPU | SIMATIC S7-1500 CPU 1512 SP-1 PN (6ES7512-1SK00-0AB0) |
| Firmware | V2.0 (compatible with TIA Portal V13 SP1) |
| Engineering | TIA Portal V13 SP1 Update 9 (build 13.1.1.0) |
| PROFINET interface ID | 64 (the on-board PN interface of the CPU) |
| CPU IP | 192.168.0.10/24 |
| PC IP (Modbus server) | 192.168.0.1/24 |
| Modbus server SW | Modsim32 or ModSim (Win-Tech), listening on TCP/502 |
| Reverse test SW | Modscan32 (Win-Tech), PLC acting as server → works |
3. MB_CLIENT Connection Parameters Reference
The instance DB written by MB_CLIENT_DB contains the static connection parameters. The values entered for the failing case must be checked item by item.
| Static tag | Type | Value used | Required / Acceptable | Notes |
|---|---|---|---|---|
| InterfaceId | HW_ANY | 64 | 64 (CPU PN interface) - correct | For S7-1500 on-board PN this is always 64. Slot 2 / 3 of a CM/CP would be 65, 66, ... |
| ID | CONN_OUC | 2 | Unique per OUC connection | Must be unique among all TCON/TDIS/TLS instructions in the project, not just MB_CLIENT instances. |
| ConnectionType | BYTE | 11 | 11 = TCP (active partner / client) | 16 = TCP (passive partner / server). 13 = UDP. Wrong type silently produces 7002 because the underlying TCON is configured as a passive socket. |
| ActiveEstablished | BOOL | TRUE | TRUE for client | FALSE only when PLC is the server. If FALSE while ConnectionType=11 the stack waits for an incoming SYN and never sends one. |
| RemoteAddress | ARRAY[1..4] of BYTE | {192,168,0,1} | Must match PC exactly | Entered as four BYTEs, not as a STRING. Reversed order is a frequent cause. |
| RemotePort | UINT | 502 | 502 standard; can be 1-65535 | If the server is on a non-standard port, do not use 502 here. |
| LocalPort | UINT | 0 | 0 (system-assigned) or specific unused port | If two MB_CLIENT instances both use LocalPort=0 the OS still assigns unique ephemeral ports, but the application engineer can fix it for clarity. |
4. Modbus TCP Client Status Code Dictionary
Status is reported on the STATUS (WORD) output of MB_CLIENT. The TIA Portal V13 SP1 help and the Modbus/TCP function manual describe the codes as follows.
| Status (hex) | Status (dec) | Meaning | Operator action |
|---|---|---|---|
| 7000 | 28672 | Idle, no job in progress | Wait for REQ rising edge. |
| 7001 | 28673 | First job running, connection not yet established | Normal during initial bring-up. |
| 7002 | 28674 | Connection being established | SYN sent, no SYN-ACK yet. Check remote IP/port, firewall, server listening. |
| 7003 | 28675 | Connection established, no job running | Healthy idle state. |
| 7004 | 28676 | Connection established, job in progress | Normal Modbus transaction in flight. |
| 7005 | 28677 | Connection being terminated | Followed by 7000 after TDIS completes. |
| 7006 | 28678 | Connection terminated, internal cleanup | Wait, will return to 7000. |
| 80A1 | 32929 | Connection terminated by remote | Server closed socket; check Modsim stay-open setting. |
| 80A2 | 32930 | Local connection error (parameter / resource) | Duplicate connection ID or wrong parameter. |
| 80A3 | 32931 | Connection terminated by user (TDIS / DISCONNECT) | Expected when client intentionally closes. |
| 80A4 | 32932 | TCP connection error (RST / ICMP unreachable) | Port closed on remote. S7-1500 will report this within 2 s of receiving the RST. |
| 818C | 33164 | Timeout: server did not respond to MB request within configured timeout | Different from connect timeout. Occurs only after a Modbus PDU was sent and no reply. |
| 818F | 33167 | Negative Modbus exception (function code ≥ 0x80) | Server replied but rejected the request. |
5. Root Cause Analysis: Why Status 7002 Never Transitions
There are seven realistic root causes that produce exactly the observed symptom of permanent 7002 with no 818C. The diagnostic procedure below tests each.
5.1 Wrong Remote IP (Most Common)
Modsim may be listening on 127.0.0.1 only, or the PC's active interface may not be 192.168.0.1. Open a Windows command prompt on the PC:
ipconfig /all
netstat -ano | findstr :502
The netstat output must show a line with [192.168.0.1]:502 in LISTENING state. If it shows [0.0.0.0]:502 or [127.0.0.1]:502 the server is reachable but may not be the right interface. If only [127.0.0.1]:502 appears, Modsim is bound to the loopback and the S7-1500 will never reach it — the CPU's SYN will elicit no reply, hence no RST and therefore no 80A4. The status stays in 7002.
5.2 Windows Firewall Blocking Inbound TCP/502
Windows Firewall with Advanced Security silently drops unsolicited inbound TCP unless an allow rule exists. Because no RST is returned to the CPU, the S7-1500 stack keeps retransmitting SYN and reports 7002. Validate by temporarily disabling the firewall:
netsh advfirewall set allprofiles state off
If the connection establishes immediately, add a permanent inbound allow rule:
netsh advfirewall firewall add rule name="Modbus TCP 502" dir=in action=allow protocol=TCP localport=502
5.3 Modsim Not Actually Listening on TCP/502
Modsim defaults to Modbus RTU on a serial port. To switch it to Modbus TCP/IP server:
- Start Modsim.
- Menu Connection → Connect → TCP/IP Server.
- Confirm the listen port is 502 and the bind address is 0.0.0.0.
- Click OK. The status bar must read "Listening on TCP/IP port 502."
If the wrong COM port or RTU mode was active, no TCP listener exists; SYN packets get no reply and 7002 persists.
5.4 ActiveEstablished Set to FALSE
If the engineer confuses the roles (PLC is supposed to be the client but the DB was built from the MB_SERVER template), ActiveEstablished is FALSE and ConnectionType = 11. The kernel TCON is configured as passive: it never sends a SYN. Status cycles 7002 → 7001 → 7002 and never connects. Fix: set ActiveEstablished = TRUE for the client DB.
5.5 Duplicate ID Across Multiple MB_CLIENT Instances
When two clients are required against the same server, both must use the same RemoteAddress but different ID values (e.g. ID=2 and ID=3) and ideally different LocalPorts. Sharing ID is not an error on download, but the second TCON is rejected by the kernel and the second MB_CLIENT is starved of its socket. The visible symptom on the second instance is identical to the 7002 hang.
5.6 IP Routing Failure on the PC Side
If the PC has multiple NICs (e.g. one wired to the CPU at 192.168.0.1 and one wireless at 10.0.0.50), the SYN from the CPU may be answered by the wrong interface or simply routed nowhere. In route print confirm that 192.168.0.0/24 has the local NIC as the only route.
5.7 TIA Portal Project Not Fully Downloaded
Online → Download to device with "All" blocks selected. Partial downloads (only the FB but not the instance DB) leave the CPU running an older MB_CLIENT that references a stale connection DB. Right-click the PLC → Download and reset program identifier if necessary.
6. Step-by-Step Resolution Procedure
Execute the following checks in order. Each step takes less than one minute.
Step 1 — Verify the Server Is Listening
- On the PC, open Command Prompt (Admin).
- Run
netstat -ano -p TCP | findstr :502. - Confirm a row in state LISTENING exists with LocalAddress containing
0.0.0.0:502or192.168.0.1:502. - If absent: switch Modsim to TCP/IP Server (menu Connection → TCP/IP Server) and restart.
Step 2 — Validate End-to-End Reachability with a PC Ping
- From the PC, ping the CPU:
ping 192.168.0.10. - From the CPU's online → Diagnostics, use Online & diagnostics → PROFINET interface → Ping to ping 192.168.0.1.
- If either fails, fix the physical link first — no Modbus layer work helps.
Step 3 — Temporarily Disable the Firewall
- Run
netsh advfirewall set allprofiles state off. - Set REQ = TRUE on MB_CLIENT.
- Watch the STATUS tag. If it transitions to 7003 within 3 s, the firewall was the cause.
- Re-enable:
netsh advfirewall set allprofiles state onand add the inbound allow rule from §5.2.
Step 4 — Verify the MB_CLIENT Instance DB
- In TIA Portal, open the MB_CLIENT instance DB.
- Confirm ActiveEstablished = TRUE, ConnectionType = 16#0B (decimal 11).
- Confirm RemoteAddress[1..4] = 192,168,0,1.
- Confirm RemotePort = 502.
- Confirm InterfaceId = 64.
Step 5 — Force a Full Reload
- Online → Download to device → select All (not "Software" only).
- After download, place the CPU in STOP, then back to RUN to reinitialize all OUC resources.
- Trigger REQ and observe STATUS.
Step 6 — Capture the Handshake
- On the PC, install Wireshark (free, vendor-neutral).
- Apply a display filter:
tcp.port == 502 and ip.addr == 192.168.0.10. - Trigger REQ on the CPU.
- Expected frames in order: [SYN] CPU → PC, [SYN, ACK] PC → CPU, [ACK] CPU → PC.
- If only SYN appears with retransmissions and no SYN-ACK ever returns, the server is not listening on the interface the SYN reached.
- If RST returns from the PC, STATUS will go to 80A4, confirming a TCP-level refusal, not a Modbus-layer issue.
Step 7 — Add an Operator-Side Watchdog
While the TCP stack's connect timeout is fixed and not user-configurable, you can wrap MB_CLIENT with an application watchdog so the HMI does not show "Connecting..." forever.
// ST pseudocode
IF MB_CLIENT_INSTANCE.STATUS = 16#7002 THEN
TIMER_7002(IN := TRUE, PT := T#10s);
IF TIMER_7002.Q THEN
// Force disconnect and reconnect
MB_CLIENT_INSTANCE.DISCONNECT := TRUE;
TIMER_RECONNECT(IN := TRUE, PT := T#2s);
IF TIMER_RECONNECT.Q THEN
MB_CLIENT_INSTANCE.DISCONNECT := FALSE;
MB_CLIENT_INSTANCE.REQ := TRUE;
TIMER_RECONNECT(IN := FALSE);
TIMER_7002(IN := FALSE);
END_IF;
END_IF;
END_IF;
7. Verification and Field Diagnostics
After the corrective action, confirm a healthy loopback:
| Check | Expected value | How to read |
|---|---|---|
| STATUS | 16#7003 (idle connected) or 16#7004 (busy) | Watch table on MB_CLIENT instance DB |
| STATUS | 16#0000 (no error) after a successful read | Same watch table |
| Wireshark | Full three-way handshake + Modbus PDU + Modbus response | Wireshark capture on PC |
| Modsim slave data | Register 40001 increments if configured to simulate a counter | Modsim display |
| PLC tag update | MB_CLIENT instance buffer updates with Modsim values | Watch table on destination DB |
7.1 Quick Diagnostic Decision Matrix
| Observation | Likely root cause | Fix |
|---|---|---|
| Permanent 7002, netstat shows listener | Firewall blocking TCP/502 inbound | Add allow rule |
| Permanent 7002, netstat shows nothing | Modsim not in TCP/IP Server mode | Reconfigure Modsim |
| Permanent 7002, ping succeeds both ways | Modsim bound to loopback only | Rebind Modsim to 0.0.0.0 |
| Permanent 7002, then 80A4 after some seconds | Server actively refused (RST) | Wrong port or server was stopped after first SYN |
| 7003 immediately, then 80A1 after a minute | Server idle-timeout closing the socket | Increase Modsim keep-alive or shorten client poll period |
| 7003 then 818C | TCP up, Modbus PDU timed out | Check UnitID mismatch or wrong Modbus function code |
| 7003 then 818F + exception code | Modbus exception from server | Map exception code per Modbus spec |
8. Common Pitfalls and Cross-Platform Edge Cases
8.1 Port 502 Privileges on Windows
On Windows Vista and later, the IANA-assigned well-known port range (1-1023) can be bound by user-mode applications without administrator rights, but Modsim running as a non-elevated user may still fail to bind 502 silently. Always right-click → "Run as administrator" for Modsim if it is the only suspect.
8.2 Anti-Virus Software Replacing the Firewall
Corporate installations often run a third-party AV suite (Symantec Endpoint, McAfee, Kaspersky) that replaces Windows Firewall. The Windows Firewall check above will report off, yet the AV may still drop TCP/502. Consult the AV vendor's network shield allow-list documentation for the Modbus port.
8.3 Switching Port to Non-Standard
If port 502 is unreachable on the server side and cannot be opened, both sides can be moved to 5020 or similar. Update RemotePort in the PLC and Modsim's listen port accordingly. Do not run two Modbus services on the same port from the same PC.
8.4 Multiple Network Interface Cards (NICs)
If the PC has Wi-Fi and Ethernet, Windows sometimes sends replies from the wrong interface. Disable the unused NIC in Network Connections for the duration of the test to force traffic onto the wired link.
8.5 TIA Portal V13 SP1 Specific Bug
TIA Portal V13 SP1 Update 4 and earlier have a known issue where MB_CLIENT continues to show 7002 even after a successful connect, because the STATUS output is not refreshed until the next OB1 cycle of the OUC background task. Upgrading to Update 9 (or to TIA Portal V14 SP1 or later) is the long-term remediation. The S7-1500 Modbus/TCP function manual is documented in the Siemens support portal under the entry for the Modbus library for S7-1500 / ET 200.
8.6 Two Clients Sharing the Same Server
For each MB_CLIENT connection, a unique server IP address must be specified. If the design requires two PLCs to talk to the same Modbus server, each must use its own connection block and its own instance DB. Reusing the same ID across them is the most frequent cause of a 7002 on the second instance.
9. Frequently Asked Questions
Why does MB_CLIENT never return 818C when the server is unreachable?
818C is the Modbus PDU response timeout, not the TCP-connect timeout. The S7-1500's TCON layer keeps retrying the SYN indefinitely without surfacing a unique error. The visible status remains 7002. Watch the underlying socket with Wireshark to confirm the server is not acknowledging.
What is the correct value for ConnectionType and ActiveEstablished when the PLC is the Modbus client?
ConnectionType = 16#0B (decimal 11) and ActiveEstablished = TRUE. Setting ActiveEstablished = FALSE while keeping ConnectionType = 11 configures a passive socket that never originates a connection — a common cause of permanent 7002.
Does the CPU need port 502 open on its own firewall?
No. The S7-1500 PROFINET interface has no firewall; only outbound TCP/502 is generated. The remote PC must allow inbound TCP/502 for the SYN-ACK to be returned. If the PC runs Windows Firewall, add an inbound allow rule for TCP/502.
Can two MB_CLIENT instances on the same CPU talk to one PC server?
Yes, but each must use a unique ID (for example 2 and 3) and a unique LocalPort if deterministic port allocation is required. Sharing the ID across two MB_CLIENT instances causes the second TCON to be rejected silently, surfacing as 7002 on the second instance.
Which TIA Portal version fixes the sticky-7002 display issue?
TIA Portal V13 SP1 Update 9 refreshes the STATUS output more aggressively. Upgrading to TIA Portal V14 SP1 or later and re-importing the Modbus library from the latest Modbus/TCP function manual is recommended for new deployments.