Siemens S7-mEC Modbus TCP Configuration: Complete Setup Guide

David Krause17 min read
S7-300SiemensTutorial / How-to
Licensed PE Working through this on a live machine? A Maine-licensed engineer can take it from here — included with IMD hardware, by the hour for everything else. Book an engineer

S7-mEC Hardware and Firmware Variants

The S7-mEC product family is documented on the S7-modular Embedded Controller (S7-mEC) EC31-RTX product page and the SIMATIC S7-mEC Operating Manual (PDF). The platform pairs an x86-compatible embedded CPU with the S7-300 backplane, so any S7-300 SM (signal module), FM (function module), or CP (communications processor) that fits the rail can be used alongside it. The S7-mEC ships with a pre-installed Windows Embedded Standard 7 (WES7) image and, in the RTX variants, the IntervalZero RTX real-time extension that allows the S7 logic to run deterministically without Windows interference.

Table 1 - S7-mEC Variants Relevant to Modbus TCP Deployment
Variant Operating System IE Interfaces Modbus TCP Capable Notes
EC31-RTX WES7 + RTX 2 x IE (PN/IE) Yes Real-time capable S7 tasks; preferred for closed-loop control
EC31 WES7 2 x IE (PN/IE) Yes Non-RTX variant, lower cost
EC31-HMI/RTX WES7 + RTX + WinCC flexible 2 x IE (PN/IE) Yes Bundled with WinCC flexible RT for HMI applications

For Modbus TCP purposes the choice between EC31 and EC31-RTX does not affect the communication stack itself, which lives in the Windows side. RTX is only relevant if you intend to run a deterministic S7 task that pre-empts the Windows scheduler. The two integrated Industrial Ethernet (IE) ports on the front of the CPU are the physical connections for Modbus TCP traffic. The PCI-104 expansion module (EM PCI-104) and the EM PC expansion add serial interfaces, additional fieldbuses, and digital I/O, but Modbus TCP always rides on the integrated IE ports.

Important: The S7-mEC's IE ports are dual-stack. They carry PROFINET IO and standard TCP/IP traffic simultaneously. A Modbus TCP session will not disrupt PROFINET real-time, but you should keep the two logical networks on separate VLANs if you run a converged plant network.

Modbus TCP Protocol Recap

Modbus TCP is the IANA-registered TCP/IP encapsulation of the Modbus application layer, defined by Schneider Electric and maintained by the Modbus Organization. Every server (slave) listens on TCP port 502. The S7-mEC, when configured as a master (client), opens an outgoing socket to the slave's IP and port 502; when configured as a slave (server), the Open Modbus library opens a listening socket and accepts the master connection. The Modbus Application Protocol Header (MBAP) is 7 bytes: transaction ID, protocol ID (always 0x0000), length, and unit ID. The Open Modbus library for STEP 7 supports function codes 1, 2, 3, 4, 5, 6, 15, and 16 out of the box. Function code 23 (read/write multiple registers) is not supported in the standard blocks and must be implemented manually if needed.

Table 2 - Modbus TCP Function Codes Supported by the Open Modbus Library
FC Name Direction Typical Use
01 Read Coils Master to slave Digital outputs from slave
02 Read Discrete Inputs Master to slave Digital inputs to slave
03 Read Holding Registers Master to slave Analog setpoints, configuration words
04 Read Input Registers Master to slave Process variables from slave
05 Write Single Coil Master to slave Digital command to slave
06 Write Single Register Master to slave Setpoint to slave
15 Write Multiple Coils Master to slave Batched digital commands
16 Write Multiple Registers Master to slave Batched setpoint download

System Architecture

S7-mEC EC31-RTX IE Port 1 192.168.0.10 Managed Switch Modbus TCP Slave 1 192.168.0.20 : 502 FC 3,4,6,16 Modbus TCP Slave 2 192.168.0.21 : 502 FC 1,2,5,15 Modbus TCP Slave 3 192.168.0.22 : 502 FC 3,4,6,16 TCP/502 Master Poll Master Poll Master Poll

The S7-mEC acts as the Modbus TCP master in this topology. Each slave can use a different subset of function codes, and the Open Modbus library creates a per-connection configuration block in the project.

Prerequisites and Required Software

  1. Hardware: S7-mEC EC31 or EC31-RTX with at least one free Industrial Ethernet port, a managed switch, and the Modbus TCP target device. Verify the controller is reachable using SIMATIC Manager -> Target system -> Accessible nodes, or TIA Portal -> Online -> Accessible devices.
  2. STEP 7 V5.5 SP4 or later: The Open Modbus library has both classic STEP 7 and TIA Portal variants. If you are on TIA Portal V13 SP1+ with an S7-mEC project that was migrated from STEP 7, the classic blocks can be re-imported; otherwise, use the wizard variant that matches your engineering tool.
  3. Open Modbus/TCP library: Download the latest version from Siemens support (entry ID 22660304 at the time of the original case). The ZIP contains the wizard executable (ModbusTCPWizard.exe), the function blocks (FB100 series), the UDTs, and the example projects.
  4. Windows admin rights: The wizard writes registry entries and configuration files. Right-click STEP 7 and run as administrator on Windows 7 and later.
  5. Static IP addressing: Assign a fixed IP to the S7-mEC's IE port. DHCP works once the link is up, but at commissioning you need a static address so the wizard and the slave can both resolve the controller.
  6. Network reachability: From the engineering station, ping the S7-mEC and ping the slave. Modbus TCP issues that look like a wizard problem are often a firewall, VLAN, or routing fault.
Firewall gotcha: Windows Firewall on the S7-mEC is on by default in WES7 and silently drops inbound Modbus TCP frames. If the S7-mEC is the slave, open inbound TCP 502 in the Windows Firewall with Advanced Security snap-in. If the S7-mEC is the master, you usually do not need an inbound rule, but outbound filtering is increasingly common on hardened images. Also, the RTX real-time scheduler and the standard Windows TCP/IP stack can interfere with each other on EC31-RTX; disable TCP offload on the IE NIC in the advanced adapter properties if you see sporadic timeouts.

Open Modbus Library and Wizard Architecture

The Open Modbus/TCP library follows the classic Siemens library pattern: a wizard creates a configuration DB that captures the master or slave definitions, and one or two function blocks execute the runtime. The blocks rely on the standard TCON, TDIS, TSEND, and TRCV system blocks from the S7-300 communication resources, so the controller must have at least one open TCP connection resource on the chosen IE port. The library contains these primary components:

  • FB100 "TCP_MB_MASTER": Master function block. Polls configured slaves, writes data to a per-connection data area in the configuration DB, and surfaces status codes.
  • FB101 "TCP_MB_SLAVE": Slave function block. Listens for incoming connections, services requests, and exposes a process image in the configuration DB.
  • FB102 / FB103: Helper blocks for connection management, fragmentation, and assembly of multi-register responses.
  • FB105 / FB106: Used in some variants for connection ID management when multiple slaves are active.
  • UDT "MB_DATA": Process image type. Defines the layout of the per-connection data buffer.
  • ModbusTCPWizard.exe: Generates the configuration DB and the call interface. Reads from a registry key to find the project and writes the DB into the project's block container.

Step-by-Step Implementation

Step 1 - Configure the IE Interface in HW Config

Open the S7-mEC station in HW Config (or the device view in TIA Portal). On the IE port that will carry Modbus TCP, assign a fixed IP address, subnet mask, and (if used) router. Set the IE port type to "PN/IE" if it is also carrying PROFINET. Confirm that at least one TCP connection resource is free in the interface's connection list. The S7-mEC supports 16 ISO-on-TCP connections and 16 TCP connections per IE port by default, but the exact number depends on the firmware and any CP modules installed.

Step 2 - Install the Open Modbus Library

Extract the Open Modbus ZIP to a local folder. In SIMATIC Manager, open the S7 program. Right-click the Blocks container and choose "Insert -> S7 Library -> Open Modbus/TCP". The library FBs, UDTs, and the wizard executable are added to the project. If prompted, allow the wizard to register the library path in the Windows registry; this is required for the next step to work.

Step 3 - Run the Modbus TCP Wizard

Launch ModbusTCPWizard.exe as administrator. The wizard opens with a project picker. Point it at the STEP 7 project file (.s7p) or the TIA Portal project folder. The wizard reads the station configuration and presents the available IE ports. The first user trap appears here.

The MEC port selection quirk: The wizard's port dropdown is a Windows combo box. On the S7-mEC, the displayed string for the first IE port is long enough that the second part of the string (the interface identifier or firmware marker, often something like "2.0.5" or a similar version string) is hidden by the combo box frame. Engineers who skim the dropdown see only the IP address and pick the first entry, which can be the wrong one. The original-thread guidance is precise: read the entire line, and verify that the IP you select corresponds to the IE port you wired to the Modbus slave network. If you wired Port 1 to the field network, you must select Port 1 in the wizard, even if Port 2 is alphabetically or numerically first in the list. The original solution notes the port identifier "begins with 2xx5" - this is the firmware version or interface tag appended at the end of a wrapped line, not a separate port designation.

After selecting the correct IE port, choose master or slave role. The wizard then asks for the slave IP, port (502 default), polling interval, response timeout, and retry count. The library examples include 1xx, 2xx, 3xx, and 4xx slave variants. The 3xx variant is the most common for a holding-register slave (function codes 3, 4, 6, 16), which matches most process instruments and drives. The 4xx variant supports bit-packed register mapping for devices that report status as register bits.

Table 3 - Wizard Configuration Parameters
Parameter Master Example Slave Example Notes
Role Master (client) Slave (server) Determines FB selection (FB100 vs FB101)
Local IE port S7-mEC IE1 S7-mEC IE1 Verify the port in HW Config matches the wizard
Local port 0 (auto) 502 Slave should always bind 502
Remote IP 192.168.0.20 N/A (accepts any) Master must know the slave IP
Remote port 502 N/A Modbus TCP standard
Poll interval 100 ms N/A Lower = faster data, higher CPU load
Response timeout 1000 ms N/A Increase for slow slaves or wireless links
Retries 3 N/A After retries, FB reports error
Unit ID 1 1 Use 255 for serial-bridged slaves
Function code set 3xx (FC 3,4,6,16) 3xx Match the slave device's capability

Step 4 - Generate the Configuration DB

Click "Generate DB" in the wizard. The wizard creates a DB (typically DB1000 or higher) that holds the connection parameters, the polling list, and the process image. It also creates a UDT instance per connection. The wizard writes the DB into the project's offline blocks container. Do not modify the generated DB manually; the wizard will overwrite it on the next run.

Step 5 - Call the Function Block

Open OB1 (or a cyclic OB) and insert a call to FB100 (master) or FB101 (slave). The instance DB is created automatically on first download. A minimal master call in STL looks like:


CALL FB100, DB1000
   ID         := 1                // Connection ID from wizard
   TIMEOUT    := T#1S             // Response timeout
   DONE       := M10.0            // 1 = last request completed OK
   ERROR      := MW12             // Error word
   STATUS     := MW14             // Detailed status
   DATA       := P#DB200.DBX0.0   // Process image pointer

For the slave role, the equivalent call uses FB101 with the connection ID, the buffer DB, and the buffer length. The buffer must be at least 2x the largest expected response, because the library uses an assembly buffer for multi-register reads.

Step 6 - Download and Test

Download the hardware configuration and the S7 program to the S7-mEC. Open a Modbus TCP client tool on the engineering station (e.g., Modbus Poll, QModMaster, or a simple Python script using pymodbus) and connect to the S7-mEC's IP on port 502 if it is configured as a slave, or to the slave's IP on port 502 if the S7-mEC is the master. Verify that the wizard-generated process image updates at the configured poll interval.

Master vs Slave Selection (3xx vs 4xx)

The Open Modbus library ships with example projects named for the dominant function codes they exercise. The 1xx series is for coil-heavy slaves (FC 1, 2, 5, 15). The 2xx series is for input-register-heavy slaves (FC 4). The 3xx series is the most common and covers holding-register slaves (FC 3, 4, 6, 16), which describes the majority of process instruments, variable-frequency drives, and energy meters. The 4xx series is for slaves that report data packed into register bits, often older power meters and protection relays. Choose the example that most closely matches the actual slave device, then customize the polling list in the wizard.

Table 4 - Example Project Variants and Their Function Code Coverage
Variant Read FCs Write FCs Typical Slaves
1xx 1, 2 5, 15 I/O blocks, relay banks
2xx 4 None Sensor front-ends, RTUs
3xx 3, 4 6, 16 Drives, meters, instruments
4xx 3, 4 (bit-packed) 6, 16 (bit-packed) Legacy meters, protection relays

Verification and Acceptance Tests

  1. Link layer: From the engineering station, ping the S7-mEC. From the S7-mEC's Windows command prompt, ping the slave.
  2. Connection establishment: In STEP 7, open the connection table and confirm the Modbus TCP connection is in "Established" state.
  3. Polling: Force a known value in the slave and verify the wizard-generated DB updates at the configured poll interval.
  4. Write path: Write a value from the S7-mEC to the slave and confirm the slave accepts it. Check the slave's diagnostic counters for receive errors.
  5. Error path: Disconnect the slave and confirm the FB reports an error code and the DONE bit remains 0. Reconnect and confirm recovery within the retry count.
  6. Sustained load: Run for at least 30 minutes under normal traffic to surface any memory leak, socket exhaustion, or Windows scheduling issue.

Troubleshooting Matrix

Table 5 - Common Faults, Causes, and Remedies
Symptom Likely Cause Diagnostic Step Remedy
No connection, FB ERROR = 0x80A1 Local port busy or wrong IP Check HW Config IE port and wizard-selected port match Re-run wizard and select the correct IE port
No connection, FB ERROR = 0x80A7 Remote slave not reachable Ping slave from S7-mEC Fix network, VLAN, or firewall
Connection establishes, no data Wrong unit ID or wrong function code Capture frames with Wireshark on TCP 502 Match unit ID and FC to slave documentation
Sporadic timeouts TCP offload engine enabled Check NIC advanced properties Disable TCP offload on the IE NIC
First poll works, subsequent polls fail Socket not released after error Check STATUS for 0x80B0 Increase timeout, reduce poll rate, check for keep-alive
Wizard crashes on launch Registry path missing Re-install library with admin rights Right-click -> Run as administrator
DB overwritten after re-run Wizard regenerated Expected behavior Make customizations in a separate DB; do not edit wizard DB
WinCC flexible RT blocks port 502 WinCC RT binds port 502 if it includes Modbus driver netstat -an on the S7-mEC Change WinCC Modbus port or slave port to a non-standard value
Communication works for hours, then stops Windows firewall triggers after update Check Windows event log Add firewall rule exemption for ModbusTCPWizard service
RTX-induced timeouts RTX scheduler pre-empting TCP/IP stack Correlate timeouts with S7 task load Run S7 on RTX side, Modbus on Windows side with shared data area

Platform Comparison: S7-mEC vs S7-1200/1500 vs ET 200SP

Engineers sometimes ask whether the S7-mEC is the right platform for Modbus TCP or whether a newer S7-1200 or S7-1500 would be simpler. The trade-off is as follows:

Table 6 - Modbus TCP Capability Across SIMATIC Platforms
Platform Native Modbus TCP Support Library Required Typical Engineering Tool Recommended For
S7-mEC (EC31/RC31-RTX) No Yes - Open Modbus/TCP STEP 7 V5.5 or TIA Portal Mixed PLC + Windows applications, legacy migrations
S7-1200 Yes (MB_CLIENT / MB_SERVER from FW V2.0) No TIA Portal V11+ New small systems, cost-sensitive applications
S7-1500 Yes (MB_CLIENT / MB_SERVER from FW V1.5) No TIA Portal V12+ New large systems, high-performance applications
ET 200SP CPU Yes (same as S7-1500) No TIA Portal V13+ Distributed I/O with controller function

If your application is a greenfield Modbus TCP integration with no Windows side, an S7-1200 or S7-1500 with the native MB_CLIENT/MB_SERVER blocks is faster to commission and easier to maintain. The S7-mEC with the Open Modbus library is the right choice only when you need the S7-300 I/O family, the Windows runtime, or are migrating an existing STEP 7 V5.5 project.

Edge Cases and Field-Proven Caveats

Multiple masters on the same slave: Some process instruments and drives will only accept one TCP connection at a time. If the S7-mEC is a master, no other master should hold a connection to the same slave. The Open Modbus library does not enforce this; it is up to the engineer to design the network.

TCP keep-alive: Long-idle Modbus TCP sessions can be silently dropped by intermediate firewalls or switches. Enable TCP keep-alive on the IE port's advanced properties, or configure a periodic no-op read in the wizard polling list.

Endianness: Modbus is big-endian on the wire, S7 is little-endian. The Open Modbus library handles byte-swapping for 16-bit registers, but 32-bit values across two registers (long integer, float) require the user to swap word order. Plan for this in the S7 side; do not assume a float from the slave is ready-to-use.

RTX real-time interference: On EC31-RTX, the RTX scheduler can preempt the Windows TCP/IP stack. Symptom is bursts of timeouts that correlate with RTX task load. Mitigation is to run the S7 program on the RTX side and the Modbus TCP on the Windows side, with a hand-shared data area.

Library version drift: The Open Modbus library has had several revisions. A project built against v4.x may not import cleanly into v6.x. Always archive the library ZIP with the project, and document the library version in the project header.

Field Commissioning Checklist

  • [ ] S7-mEC firmware, STEP 7, and Open Modbus library versions recorded in the project header
  • [ ] IE port IP, subnet, and VLAN documented
  • [ ] Windows Firewall rules set for TCP 502 (slave mode) or outbound allow (master mode)
  • [ ] TCP offload disabled on the IE NIC
  • [ ] Wizard-selected port verified against the wired port in HW Config
  • [ ] Example project variant (1xx, 2xx, 3xx, 4xx) matches the slave device
  • [ ] Unit ID matches the slave configuration
  • [ ] Function codes match the slave device capability
  • [ ] Byte-swap rules documented for any 32-bit data
  • [ ] 30-minute sustained load test completed
  • [ ] Error path tested (slave disconnect and reconnect)

Related Siemens Resources

For additional reference, see the S7-modular Embedded Controller (S7-mEC) EC31-RTX product page for the full EC31-RTX datasheet and ordering information, and the SIMATIC S7-mEC Operating Manual (PDF) for the hardware configuration, addressing, and diagnostic procedures that apply to Modbus TCP commissioning.

Does the S7-mEC support Modbus TCP natively without any library?

No. The S7-mEC does not ship with native Modbus TCP blocks. You must install the Siemens Open Modbus/TCP library and use the Modbus TCP Wizard to generate the configuration DB. Native Modbus TCP support exists on the S7-1200 (MB_CLIENT/MB_SERVER) and S7-1500 (MB_CLIENT/MB_SERVER) but not on the S7-300 architecture that the S7-mEC inherits.

How do I identify the correct Industrial Ethernet port in the Modbus TCP Wizard?

Open the wizard, click the port dropdown, and read each entry end-to-end. On the S7-mEC the first IE port string is long enough that the interface identifier (often a firmware marker like 2.0.5) is hidden by the combo box frame. Compare the IP address shown in the dropdown against the IP configured in HW Config for the IE port wired to your Modbus slave network, and select the matching entry.

Which example project variant should I use, 1xx, 2xx, 3xx, or 4xx?

Use 3xx for the majority of process instruments, variable-frequency drives, and energy meters that expose holding registers (function codes 3, 4, 6, 16). Use 1xx for coil-heavy I/O blocks, 2xx for input-register-only sensor front-ends, and 4xx for legacy meters that pack data into register bits.

Can the S7-mEC act as both a Modbus TCP master and slave at the same time?

Yes, by running two instances of the Open Modbus library (one FB100 for master, one FB101 for slave) on different TCP connection IDs. The IE port must support multiple TCP connections, which the S7-mEC does by default. Each instance must be on a separate wizard-generated configuration DB to avoid symbol clashes.

Why does my connection work for a few minutes and then time out?

The most common causes are: (1) Windows Firewall on the S7-mEC is dropping the socket after a quiet period - add a firewall rule for TCP 502; (2) TCP offload engine on the IE NIC is interfering with RTX scheduling - disable it in the advanced adapter properties; (3) an intermediate switch or firewall is closing the idle socket - enable TCP keep-alive or add a periodic no-op read to the polling list.

Back to blog