Overview
The Siemens SIMATIC S7-300 CPU 317-2 PN/DP (order number 6ES7317-2EK14-0AB0, firmware V3.x) ships with two integrated PROFINET interfaces on the first PROFINET port (X1) and PROFIBUS DP master/slave on X2. The integrated PROFINET port supports standard TCP/IP transport, which allows the controller to communicate with Modbus TCP devices. The catch: the S7-300 system libraries do not include a native Modbus application layer. The protocol must be implemented through one of three engineering paths: a Siemens-supplied Modbus TCP library, an external protocol gateway (Anybus, Prosoft, MOXA, HMS/IXXAT), or a custom implementation using the standard TCON, TDISCON, TSEND, TRCV open communication blocks.
This reference consolidates the configuration of the integrated PN interface, the selection of the integration method, the programming patterns for the Modbus application layer (Function Codes 0x03, 0x04, 0x06, 0x10), and the verification steps to bring the ICONICS SCADA endpoint online.
CPU 317-2 PN/DP Hardware and Interface Specifications
| Property | Value |
|---|---|
| Order number (MLFB) | 6ES7317-2EK14-0AB0 (also 6ES7317-2AJ10-0AB0 predecessor) |
| Firmware (typical) | V3.3 (as of catalog update) |
| Work memory | 1 MB code / 2 MB data (typical 317-2 PN/DP variant) |
| PROFINET interface X1 (port 1) | 10/100 Mbit/s, RJ45, supports TCP/IP, UDP, ISO-on-TCP, PROFINET IO Controller |
| PROFINET interface X1 (port 2) | 10/100 Mbit/s, RJ45, switch port |
| PROFIBUS interface X2 | RS485, DP master/slave, 12 Mbit/s |
| Open IE communication connections | Up to 16 (firmware-dependent) |
| Number of PROFINET IO devices | Up to 256 |
| Number of PG/OP connections | Up to 16 |
For the detailed module data sheet see the SIMATIC S7-300 CPU 317-2 PN/DP datasheet (PDF).
Protocol Architecture
Modbus TCP, as defined by the Modbus Organization (MODBUS Messaging on TCP/IP Implementation Guide V1.0b), is an application-layer protocol riding on TCP port 502. Each ADU consists of:
- MBAP Header (7 bytes): Transaction Identifier (2), Protocol Identifier = 0x0000 (2), Length (2), Unit Identifier (1).
- PDU: Function Code (1 byte) + Data (N bytes).
The S7-300 CPU PN port only provides the TCP transport. The MBAP wrapper must be assembled and parsed in the user program unless a library or gateway does it for you.
Integration Method Comparison
| Criterion | Siemens Modbus TCP PN CPU Library | External Gateway (Anybus / Prosoft / MOXA) | Custom TCON/TSEND/TRCV |
|---|---|---|---|
| Engineering effort | Low (FB call) | Very low (gateway config) | High (build MBAP parser) |
| Hardware cost | Library license fee (paid) | Gateway + license | Free (CPU only) |
| CPU load | Low to medium | Negligible | Medium to high |
| Maintenance | Vendor updates | Vendor firmware | In-house |
| Supported function codes | 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x0F, 0x10 | Most, gateway-dependent | Whatever you implement |
| SCADA compatibility (ICONICS) | Yes (CPU as Modbus server) | Yes (gateway as server) | Yes |
| Field-proven for S7-300 | Yes (Siemens-tested) | Yes (HMS, Prosoft, MOXA) | Engineer-dependent |
Method 1: Siemens Modbus TCP PN CPU Library (S7 Open Modbus TCP)
The official Siemens approach for SIMATIC S7-300/400 with integrated PROFINET interface is the MODBUS/TCP Communication over the integrated PROFINET Interface library. It uses the Open IE communication blocks internally and provides ready-made FBs (MB_RED_CLIENT, MB_RED_SERVER for redundancy) and a wizard for STEP 7 / TIA Portal.
- Download the library from the Siemens support site. Search entry ID 75330636 - MODBUS/TCP Communication over integrated PROFINET Interface (PDF).
- Open STEP 7 V5.5 (or TIA Portal V13+). Add the library from Options > Open global library.
- Insert the wizard block from the library. Configure the IP address, port (502), connection ID, and Modbus role (server when ICONICS is the client; client when reading a Modbus slave device).
- The wizard generates DBs and FBs that handle MBAP parsing and the most common Function Codes.
- Call the generated FB in OB1 with the appropriate instance DB.
Method 2: External Gateway
For projects that already have a heterogeneous network or that need to add Modbus TCP to a PROFIBUS/PROFINET segment without programming the PLC, use a stand-alone gateway. The gateway sits between the S7-300 PN port and the Modbus TCP device(s), or in front of the SCADA if the SCADA is the Modbus client.
Recommended gateways
- HMS Anybus X-gateway (PROFINET slave to Modbus TCP master/server). Two Ethernet ports, integrated switch. Catalog: Anybus X-gateway page.
- Prosoft PLX31-EIP-MBTCP (Modbus TCP/IP to Siemens Industrial Ethernet). Acts as both Modbus client and server. Reference: Prosoft Technology.
- MOXA MGate MB3170 / MB3270 (Modbus TCP gateway). Field-proven with S7-300 in many SCADA integrations, including the verified case study at SiePortal: Modbus TCP communication between CPU 317-2 PN and MOXA gateway.
Wiring topology
Gateway configuration outline
- Assign the gateway a fixed IP in the same subnet as the CPU (default 192.168.0.20, mask 255.255.255.0).
- Define the Modbus TCP role: gateway as server, ICONICS as client. Map each Modbus register to a PROFINET slot/word the S7-300 exchanges cyclically.
- On the S7-300, in TIA Portal, install the GSD file of the gateway (PROFINET device). Drag the gateway into the PROFINET topology under the CPU's PN interface.
- Insert the input/output modules to match the data width (e.g. 8 words in / 8 words out for a small data set).
- Compile and download. The ICONICS SCADA polls the gateway on port 502 and reads the data the S7-300 has deposited in the gateway input area.
Method 3: Custom Implementation with TCON/TSEND/TRCV
When licensing is a constraint, the S7-300 PN port can be used directly with the Open IE blocks. The FBs are part of the standard SIMATIC_NET_CP library (STEP 7 V5.5) or of the IEC standard blocks in TIA Portal.
Required blocks (STEP 7 V5.5)
| FB / FC | Description |
|---|---|
| FB65 "TCON" | Establish TCP connection |
| FB66 "TDISCON" | Terminate connection |
| FB63 "TSEND" | Send data |
| FB64 "TRCV" | Receive data |
| FB67 "TUSEND" | Send via UDP (not used here) |
| FB68 "TURCV" | Receive via UDP |
Connection DB (UDT65 "TCON_PARAM")
DATA_BLOCK "dbConnModbus"
{ S7_Optimized_Access := 'FALSE' }
VERSION : 0.1
NON_RETAIN
STRUCT
ConnType : BYTE := B#16#11; // 0x11 = TCP native (0x0B for ISO-on-TCP)
ActiveEst : BOOL := TRUE; // CPU is Modbus server (passive open)
RemPort : WORD := W#16#01F6; // Remote port 502 decimal
LocPort : WORD := W#16#01F6; // Local port 502
RemIp[1..4]: BYTE := 192,168,0,50; // ICONICS SCADA IP
LocIp[1..4]: BYTE := 192,168,0,10; // CPU PN IP
ID : WORD := W#16#0001; // Connection ID
END_STRUCT;
END_DATA_BLOCK
Sequence in OB1
- Call
TCONonce on startup with the connection DB above. Wait forDONE. - On
TRCVcompletion, the receive buffer contains the MBAP header + PDU. Parse the Transaction ID, Protocol ID, Length, and Unit ID. - Decode the Function Code. Implement at minimum FC 0x03 (Read Holding Registers), 0x06 (Write Single Register), and 0x10 (Write Multiple Registers) for SCADA integration.
- Build the response: copy the request MBAP header, set the function code, append the requested register data from a configured DB (e.g. DB100 "ModbusMap").
- Call
TSENDto return the response.TRCVmust be re-armed withEN_R = TRUEto wait for the next request.
Example FB call (SCL)
// In OB1
// Passive open (CPU is server, SCADA is client)
IF "startup" THEN
"dbConnModbus".ID := 1;
"dbConnModbus".ActiveEst := FALSE; // passive open
"instTCON"(REQ := TRUE, ID := 1, CONNECT := "dbConnModbus", DONE => .., ERROR => .., STATUS => ..);
END_IF;
// Receive loop
"instTRCV"(EN_R := TRUE, ID := 1, LEN := 0, DATA := "rcvBuf", NDR => .., ERROR => .., STATUS => .., RCVD_LEN => ..);
// Process MBAP and PDU in custom FB "FB_ModbusServer"
// Send response
"instTSEND"(REQ := "sendReq", ID := 1, LEN := "respLen", DATA := "sndBuf", DONE => .., ERROR => .., STATUS => ..);
Hardware and IP Configuration
- Open the CPU 317-2 PN/DP in the project (HW Config in STEP 7, or Device View in TIA Portal).
- Double-click the PROFINET interface X1. In Properties > General > Ethernet addresses, enter:
- IP address:
192.168.0.10 - Subnet mask:
255.255.255.0 - Router (if any):
192.168.0.1
- IP address:
- Assign a subnet (e.g.
PN/IO_1). Make sure the router checkbox is unchecked if no external router is required. - Open Properties > General > PROFINET interface > Port 1 / Port 2 and verify "End of detection of accessible nodes" is disabled, monitor mode is off.
- Compile and download HW Config.
Connection Limits on the S7-300
The CPU 317-2 PN/DP supports a maximum of 16 Open IE communication connections, shared with PG/OP/HMI. Plan accordingly:
| Service | Reserved connections |
|---|---|
| PG (programming) | 1 |
| OP/HMI (operator panel) | 1 |
| S7 communication (PUT/GET) | Configurable, count toward the same budget |
| Open IE (TCON, Modbus TCP) | Up to 16 total, of which a subset can be used for Modbus |
If the ICONICS SCADA opens a single TCP connection that is kept open and reused, this uses only one of the 16 slots. If the SCADA is configured to open one socket per request, you will exhaust the budget quickly.
ICONICS SCADA Configuration
- Install the ICONICS Modbus TCP/IP driver (typically bundled with Genesis64 or GraphWorX64).
- Create a new channel. Set Device ID = IP of the gateway or CPU (
192.168.0.20for MOXA,192.168.0.10for direct CPU connection). - Set Port =
502. Set Connection Type =TCP/IP. - Set Modbus Function Code =
3(Read Holding Registers) for measurement data,4(Read Input Registers) if the slave differentiates them. - Map each ICONICS tag to a Modbus register address. The address range starts at 40001 for FC03, 30001 for FC04, 00001 for FC01/FC02 (coils).
- Configure scan rate (typical 1 s for process values, 100 ms for fast control loops).
For details on the Modbus addressing scheme, see the Modbus Application Protocol V1.1b3 (PDF).
Verification and Diagnostics
-
PG/PC ping test: From the STEP 7 PC, ping
192.168.0.10and192.168.0.20(gateway) or the SCADA host. The CPU replies via the integrated PN port only when the project has been downloaded with an IP address. - Connection status in TIA Portal: Online > Diagnostics > PROFINET interface shows the open TCP connections. The Modbus socket (ID 1) should show state = established.
-
Block status of TCON/TSEND/TRCV:
STATUS=0x0000= OK. Common non-zero values:-
0x8081– Connection ID already in use. -
0x8085– Connection not yet established,TCONnot called orDONEmissing. -
0x80A1– Connection terminated by remote (SCADA closed the socket).
-
- SCADA driver trace: In ICONICS, enable the Modbus driver trace. A successful read returns FC03 response with length = 2*N + 3 (Unit ID + FC + byte count + 2*N data bytes).
-
Wireshark capture: Place a SPAN port on the switch. Filter on
tcp.port == 502. Verify MBAP header bytes: TxID (any), Protocol ID =0x0000, Length field, Unit ID =0xFFor0x01.
Troubleshooting Matrix
| Symptom | Likely cause | Action |
|---|---|---|
| SCADA cannot connect to CPU IP :502 | Firewall on PC blocking outbound 502, or CPU not listening (FB65 never called) | Verify TCON ran, open Windows Firewall rule, ping test |
| Connection establishes, no data | Wrong Modbus register map; FC mismatch (e.g. SCADA reads FC04 from a FC03 server) | Wireshark check the function code echo in response |
| SCADA gets "Illegal Function" (0x01) | Function code not implemented in custom FB | Add the missing FC handler |
| SCADA gets "Illegal Data Address" (0x02) | Modbus address outside the configured DB range | Extend DB100 boundaries or remap ICONICS tag |
| Intermittent timeouts after a few hours | TCP keepalive not configured; SCADA closes idle sockets | Re-establish connection in OB1 on TRCV error = 0x80A1 |
| TCON error 0x8085 | CPU already uses 16 Open IE connections | Reduce PG/OP connections or switch to a gateway |
| CPU goes to SF (system fault) | OB121 missing, divide by zero in custom FB | Add OB121, download, clear fault |
Performance and Timing Notes
Typical Modbus TCP transaction round-trips on a 100 Mbit/s PROFINET segment with a CPU 317-2 PN/DP running FC03 read of 10 registers:
- OB1 cycle (CPU 317-2 PN/DP @ 100 ms): typical 5 to 20 ms for the request handling.
- Ethernet RTT (1 switch hop): < 1 ms.
- SCADA scan at 250 ms yields plenty of headroom.
For high-speed polling (sub-50 ms), consider the gateway approach so the SCADA never competes with the PLC OB1 cycle for the same connection resources.
Choosing the Right Method
- Direct CPU with Siemens library – Cleanest, single component, but paid license. Best for new projects where the S7-300 is the only PLC.
- External gateway (MOXA, Anybus, Prosoft) – Best when multiple Modbus slaves exist, when the SCADA already has a proven Modbus driver, or when the PLC user program must remain untouched. Field-proven pattern for the CPU 317-2 PN/DP per the SiePortal case study.
- Custom TCON-based server – Only when licensing is impossible and you have the engineering capacity to maintain the MBAP parser and FC handlers. Audit your code against MODBUS Application Protocol V1.1b3.
FAQ
Does the CPU 317-2 PN/DP natively support Modbus TCP out of the box?
No. The integrated PROFINET port supports TCP/IP transport (port 502 is just a TCP socket), but the Modbus application layer (MBAP + function codes) must be implemented through the Siemens Modbus TCP PN CPU library, an external gateway, or a custom TCON/TSEND/TRCV program.
How many Modbus TCP connections can the CPU 317-2 PN/DP accept simultaneously?
Up to 16 Open IE connections total, shared with PG/OP and S7 communication. For a single ICONICS SCADA client, plan on 1 persistent TCP connection to keep this budget healthy.
What IP address and subnet should I assign to the CPU for Modbus TCP integration?
Use a static IP such as 192.168.0.10 with subnet mask 255.255.255.0, on the same subnet as the SCADA and any gateway. The SCADA or Modbus client must be in the same subnet or routed through a managed switch/router.
Is the Siemens Modbus TCP PN CPU library free?
No. It is a licensed product line (S7 Open Modbus TCP / Modbus TCP PN CPU). The license is typically keyed to the CPU serial number. For budget-sensitive projects, an external gateway is often cheaper than the runtime license.
Can I connect ICONICS SCADA directly to the CPU 317-2 PN/DP without a gateway?
Yes, by using the Siemens Modbus TCP PN CPU library on the CPU, or by writing a custom Modbus server using TCON/TSEND/TRCV. ICONICS Genesis64 has a built-in Modbus TCP/IP driver that polls the CPU on port 502 once the server is in place.
Which port does Modbus TCP use and does it need to be opened on the CPU firewall?
Modbus TCP uses TCP port 502. The CPU itself has no host firewall (it is a slave/server), but Windows Firewall on the SCADA PC must allow outbound traffic to port 502. The SCADA-side driver is usually configured with retries and a longer timeout (typically 3 to 5 s) to ride out momentary network blips.
What is the difference between FC03 (Read Holding Registers) and FC04 (Read Input Registers)?
FC04 is intended for analog input data; FC03 is for holding registers. Many Modbus devices treat them identically. Implement both in your server if the SCADA tag database contains a mix of measurement and command registers.