1. Problem Overview
The original requirement is straightforward but has several non-obvious technical constraints:
- A Siemens SIMATIC S7-300 CPU 313C needs to expose its process data to a laptop.
- Process values include methane concentration readings that must carry an associated timestamp so the historian/analytics layer can do trend analysis.
- The transport mechanism of choice is OPC UA, the modern IEC 62541 standard that replaces the older OPC Data Access (DA) and OPC HDA specifications.
The critical engineering decision is that an S7-300 CPU has no native OPC UA server. The OPC UA server capability was introduced starting with the S7-1500 family (firmware 2.0 and later, expanded in V4.x firmware) and the S7-1200 (firmware 4.4 and later). The CPU 313C belongs to the S7-300 line and must therefore be paired with a PC-based OPC UA server such as SIMATIC NET OPC Server that speaks S7 Communication (ISO-on-TCP, port 102) to the PLC and exposes the data as OPC UA (port 4840) to clients.
2. OPC UA Architecture and S7 PLC Integration Paths
OPC UA is a client/server protocol. The PLC is rarely the OPC UA server directly (unless it is S7-1500/1200). The laptop is the OPC UA client. The middle layer that translates between the PLC's native protocol (MPI/Profibus/PROFINET S7) and OPC UA is the OPC UA server running on a PC station or a third-party gateway.
| Path | Server Platform | PLC Side | PC ↔ PLC Protocol | PC ↔ Client Protocol |
|---|---|---|---|---|
| A. SIMATIC NET PC station | PC running SIMATIC NET | S7-300 / S7-400 / S7-1500 / S7-1200 | S7comm over ISO-on-TCP (TCP/102) | OPC UA (TCP/4840) or OPC DA |
| B. Native OPC UA server | PLC firmware | S7-1500 / S7-1200 (FW ≥ 4.4) | — | OPC UA (TCP/4840) |
| C. Third-party gateway | TOP Server, Kepware, Ignition Edge, etc. | Any S7 family | Vendor-specific S7 driver | OPC UA (TCP/4840) |
Path A is the canonical Siemens-supported answer for an S7-300. Paths B and C apply if the user migrates to S7-1500 or accepts a non-Siemens gateway. Each path is detailed below.
3. Why S7-300 Cannot Run a Native OPC UA Server
The S7-300 family (including CPU 313C, 314, 315, 317, 319) is built around the STEP 7 V5.x engineering environment and predates the OPC UA specification (IEC 62541, first published 2010). The CPUs do not embed an OPC UA stack and there is no firmware option to add one. STEP 7 V5.5 SPx contains OPC configuration through SIMATIC NET only — there is no CPU-side OPC UA dialog.
For OPC UA exposure you must therefore install SIMATIC NET on a Windows PC, configure an OPC Server instance tied to the S7-300's IP address and rack/slot, and define the memory addresses (Input/Output/Merk/DB) that should be visible to OPC UA clients on the network.
4. Option A — SIMATIC NET OPC Server for S7-300 (CPU 313C)
4.1 Required software
- SIMATIC NET PC software (current release: SIMATIC NET V20 — must be matched to STEP 7 V5.x or TIA Portal compatibility)
- STEP 7 V5.5 SPx or TIA Portal for project engineering
- OPC UA client on the laptop (e.g., Prosys OPC UA Client, UaExpert, Ignition OPC-UA Client, or an Excel add-in)
- Ethernet CP (CP 343-1) on the S7-300 or use the integrated PN interface of the CPU 313C-2 PN/DP variants
4.2 Station configuration
Use the SIMATIC NET Station Configuration Editor to build a PC station containing an OPC Server slot and an IE General (Industrial Ethernet) interface. The IE interface must be bound to the network adapter that physically reaches the S7-300.
4.3 S7 connection configuration
Open the PC station's Configuration in STEP 7 or the SIMATIC NET configurator and add an S7 connection with the following parameters:
| Parameter | Value |
|---|---|
| Partner IP address | 192.168.0.10 (example, replace with CPU PN/CP address) |
| Partner rack | 0 |
| Partner slot | 2 (CPU 313C slot) |
| Connection resource | 1 (any free S7 connection resource on the CPU) |
| Local TSAP | 10.01 (default for OPC server) |
| Transport | ISO-on-TCP (RFC 1006), port 102 |
4.4 Defining OPC items (tags)
In the OPC Server's tag editor, define items that reference PLC memory areas. The address syntax for S7-300 is:
DB1.DBD0 // Data Block 1, Double Word at offset 0 (REAL)
DB1.DBW4 // Data Block 1, Word at offset 4 (INT)
DB1.DBX6.0 // Data Block 1, Bit at byte 6 bit 0 (BOOL)
MW100 // Merker Word 100
EW0 // Input Word 0
AB2 // Output Byte 2
5. Option B — Native OPC UA Server on S7-1500 / S7-1500T
If the application can be migrated to S7-1500 (or to S7-1200 with firmware 4.4 or later), the OPC UA server is embedded in the CPU firmware and no PC station is required. The official Siemens documentation "Enabling the OPC UA server (S7-1500, S7-1500T)" describes the procedure in detail. The condensed steps for TIA Portal V20:
- In the project tree, select the S7-1500 CPU.
- Open Properties → OPC UA → General.
- Set "Activate OPC UA server" = enabled.
- Enter a meaningful server name (appears as the OPC UA ApplicationDescription).
- Set the port (default 4840).
- Choose the security policy: None, Basic128Rsa15, Basic256Sha256, or Aes128Sha256RsaOaep. Field deployments should disable None and use at least Basic256Sha256 with a signed certificate.
- Configure user authentication (anonymous, username/password, or certificate-based).
- Define the runtime license: Basic, Plus, or PRO. Plus/PRO unlock the full tag count and security policies.
- Under OPC UA → Server interfaces / Server methods / Runtime licenses, expose specific DBs or optimizable data blocks.
- Compile and download the project. The CPU exposes the OPC UA endpoint immediately on the configured port.
6. Option C — Third-Party OPC UA Gateway
Several vendors wrap a Siemens S7 driver inside an OPC UA server. Typical examples include Software Toolbox TOP Server (see Integrate Your S7-1500 via OPC UA using TOP Server), Kepware / KEPServerEX, and Inductive Automation Ignition Edge. These are useful when:
- You have a mix of S7-300 and S7-1500 fleets.
- You want to expose OPC UA without buying SIMATIC NET licenses.
- You already own the third-party SCADA/MES and need a single server endpoint.
Engineering steps are similar to Path A: define an S7 channel, point it at the CPU 313C, and map tags. The gateway then publishes the same tags on OPC UA port 4840.
7. Data Types, Memory Areas, and Timestamp Handling
The PLC does not deliver "raw" bytes to the OPC client — it delivers a typed value. Each OPC UA item has a Variant type that mirrors the SIMATIC datatype defined in STEP 7 / TIA Portal.
| SIMATIC type | Width | OPC UA built-in type | Range / Notes |
|---|---|---|---|
| BOOL | 1 bit | Boolean | true / false |
| BYTE | 8 bit | Byte | 0 … 255 |
| WORD | 16 bit | UInt16 | 0 … 65 535 |
| DWORD | 32 bit | UInt32 | 0 … 4 294 967 295 |
| INT | 16 bit | Int16 | −32 768 … 32 767 |
| DINT | 32 bit | Int32 | −2 147 483 648 … 2 147 483 647 |
| REAL | 32 bit | Float | IEEE 754 single precision |
| LREAL | 64 bit | Double | IEEE 754 double precision (S7-1500 only) |
| S5TIME | 16 bit | UInt16 | S7-300 legacy time base |
| TIME | 32 bit | Int32 | IEC 61131-3 duration in ms |
| DATE_AND_TIME | 64 bit | DateTime | S7-300/400 BCD-coded timestamp |
| DTL | 96 bit (12 B) | DateTime | S7-1500/1200 only; ns resolution |
| STRING | n+2 bytes | String | S7-1500 UTF-16, S7-300 ASCII |
7.1 Timestamps for methane concentration
For the methane measurement use case the original poster correctly anticipated that a timestamp is needed. Three approaches are common in S7-300 projects:
- Use the OPC UA server's source timestamp. SIMATIC NET stamps each read with the wall-clock time of the PC. Resolution is milliseconds; accuracy depends on the PC's NTP sync.
-
Map an S7
DATE_AND_TIMEtag from the PLC. The PLC constructs the timestamp (e.g., via SFC 1 "READ_CLK") and stores it in a DB; SIMATIC NET maps it to OPC UADateTime. This survives PC clock drift. -
Combine timestamp + concentration in one tag structure in a DB and expose the whole structure as a single OPC UA tag. On S7-1500 use
DTL; on S7-300 use pairedDATE_AND_TIME+REAL.
8. Step-by-Step — Building an OPC UA Connection from the Laptop
The following procedure assumes Path A (SIMATIC NET) because the target CPU is a 313C.
8.1 Prerequisites
- Windows 10/11 PC, admin rights
- SIMATIC NET V20 (or matching version) installed
- STEP 7 V5.5 SPx (or TIA Portal if STEP 7 project is migrated)
- Ethernet from PC to the CPU 313C's PN port (or CP 343-1)
- OPC UA client software (UaExpert or Prosys recommended for verification)
8.2 Configuration procedure
- Open Station Configuration Editor. Add an OPC Server module and an IE General module. Bind the IE module to the physical NIC connected to the S7-300.
- In STEP 7 V5.5, open the PC station and add an S7 connection to the CPU 313C (parameters in Table 2).
- Compile and download the PC station configuration.
- Open OPC Scout V10 (bundled with SIMATIC NET). Add a new group and define items using the syntax from Section 4.4.
- Activate the S7 connection. OPC Scout must display the items as "Good" quality.
- On the laptop's OPC UA client, point the endpoint URL at
opc.tcp://<PC_IP>:4840(or whatever port SIMATIC NET OPC UA is configured for; default is 4840). - Browse the server namespace. The previously defined items appear as nodes under the configured folder.
- Subscribe to the items with a sampling interval of, for example, 1000 ms. The client receives value updates with source timestamp.
9. Verification and Diagnostics
After configuration, perform the following checks before declaring the link operational:
| # | Check | Expected Result |
|---|---|---|
| 1 |
ping from PC to CPU 313C IP |
< 1 ms RTT, 0% loss |
| 2 | OPC Scout "Quality" for each item | Good (0x00000000) |
| 3 | Force a value in STEP 7 and observe OPC client update | Value changes within one sampling interval |
| 4 | Inspect OPC UA SourceTimestamp | UTC, monotonic, increments with PLC writes |
| 5 | Disable PC network and re-enable | Client reconnects automatically (good UA implementations retry) |
| 6 | Stop/start the OPC server service | Client receives ServerState transition Shutdown → Running |
9.1 Useful diagnostics tools
- SIMATIC NET Commissioning tool — tests S7 connection at the transport layer.
-
Wireshark with the
s7commandopcuadissectors — confirms ISO-on-TCP and OPC UA traffic. - OPC Scout V10 — browse and read/write items.
- UaExpert (free) — full OPC UA client with security diagnostics.
10. Troubleshooting Matrix
| Symptom | Likely Cause | Remedy |
|---|---|---|
| Client reports BadCommunicationError | S7 connection not downloaded to PC station | Download PC station configuration via Station Configuration Editor; verify with OPC Scout |
| Client connects but all items are Bad | Incorrect DB number, byte offset, or bit number | Cross-check against STEP 7 symbol table; verify DB exists and is non-optimized |
Item reads 0 permanently |
Address in input/process image not updated | Confirm the program is writing the value (monitor online in STEP 7) |
| Connection refuses on port 4840 | Windows Firewall blocks the port | Add inbound rule for opc.tcp on port 4840; or temporarily disable firewall for bench test |
| Client connects on port 4840 but no items visible | Wrong endpoint URL or security mismatch | Match SecurityPolicy, MessageSecurityMode, and authentication token |
| Timestamp lags behind PLC by hours | PC clock unsynchronized | Enable NTP on the PC; or move timestamp source into the PLC using SFC 1 |
| CPU 313C connection resource exhausted (SF LED) | All S7 connection resources in use | CPU 313C allows max 8 S7 connections; consolidate to a single OPC channel |
| Items appear but writes from client are rejected | Address in read-only area (e.g., IW) or DB write-protected | Use a DB marked as writable; avoid inputs/process inputs |
| OPC UA client times out sporadically | Keep-Alive too aggressive; PC busy | Raise timeout (e.g., 60 s) and adjust publishing interval |
| BadCertificateUntrusted on every connect | Server certificate not trusted by client | Export the server's self-signed cert and add to client trust list |
11. Field-Commissioning Notes for Methane Measurement
Because the original application is methane concentration monitoring, the OPC link must satisfy a few domain-specific constraints:
-
Deterministic sampling: Methane detectors typically output 4–20 mA or Modbus. If the S7-300 scales the analog input into a DB REAL, expose that DB REAL (e.g.,
DB20.DBD0asFloat) and not the raw input word — the client then receives engineering units (e.g., % LEL). -
Timestamp granularity: For alarm analysis, the source timestamp should come from the PLC, not the OPC server. In S7-300 use SFC 1 "READ_CLK" to load
DATE_AND_TIMEat the moment the measurement is latched. - Retention: If you also need historical values (HDA), OPC UA's historical access requires the server to buffer them — SIMATIC NET HDA is limited; for true trending forward samples to a time-series DB via the OPC client.
- Cybersecurity: Methane monitoring often sits in a regulated safety environment. Disable anonymous authentication, require Basic256Sha256, and pin certificates on the OPC client.
- Redundancy: For SIL-relevant paths, evaluate migrating to S7-1500 with native OPC UA; this removes the PC as a single point of failure.
12. Frequently Asked Questions
Can a Siemens S7-300 CPU 313C be an OPC UA server directly?
No. The S7-300 family has no native OPC UA server capability. You must pair the CPU with SIMATIC NET PC software, which terminates S7 communication on port 102 and re-exposes the data as OPC UA on port 4840. Native OPC UA is available only on S7-1500 and on S7-1200 with firmware 4.4 or later.
Which port does OPC UA use, and why does my S7-1200 talk on port 102?
OPC UA uses port 4840 by default (IANA assignment). Port 102 is ISO-on-TCP (RFC 1006), used by S7 communication and by SIMATIC NET to talk to S7-300/400 CPUs. They are different protocols; an OPC UA client pointed at port 102 will fail.
How do I enable the OPC UA server on an S7-1500 in TIA Portal V20?
Select the CPU in the project, open Properties → OPC UA → General, enable "Activate OPC UA server", assign a server name and port (default 4840), choose a security policy (at least Basic256Sha256 in production), define authentication, and download the project. Full procedure: Siemens TIA Portal V20 documentation.
In what data format does the data arrive on the laptop?
OPC UA delivers typed Variants. A PLC REAL (32-bit IEEE 754) becomes an OPC UA Float; an INT becomes an Int16; a BOOL becomes a Boolean; a DATE_AND_TIME or DTL becomes a DateTime. Timestamps are part of the data structure (SourceTimestamp, ServerTimestamp) and can come from the PLC or the OPC server depending on configuration.
What is the simplest free client to verify the connection?
Install UaExpert or Prosys OPC UA Client on the laptop, point it at opc.tcp://<PC_IP>:4840, browse the namespace, and add the methane concentration tag to a subscription. If quality stays "Good" and the value updates, the full chain (PLC → S7comm → SIMATIC NET OPC → OPC UA → client) is operational.