Siemens S7 PLC Connectivity
- Overview
- What is Siemens S7
- Applicable PLCs
- Prerequisites
- Network Configuration
- PLC Configuration
- MachineMetrics Connector Setup
- Data Block Configuration
- Part Counting Configuration
- Data Mapping
- Troubleshooting
- Additional Resources
- Getting Help
Overview
MachineMetrics can connect to Siemens S7 PLCs (Programmable Logic Controllers) to collect production data from machines controlled by Siemens automation systems. This connector enables data collection from assembly lines, automated work cells, custom machines, and industrial equipment using Siemens S7 control systems.
Key Features:
- Direct communication with Siemens S7 PLC over Ethernet
- Read data from PLC data blocks (DBs)
- Real-time monitoring of machine states, counters, and process variables
- Support for multiple S7 PLC families (S7-300, S7-400, S7-1200, S7-1500)
- Part counting and production tracking
Important: This guide covers Siemens S7 PLCs (automation controllers), not Siemens CNC controls.
- For Siemens CNC controls (840D, etc.), see OPC-UA Guide
What is Siemens S7
Siemens S7 is a family of Programmable Logic Controllers (PLCs) manufactured by Siemens for industrial automation and control applications.
Key Characteristics:
- PLC Platform: Controls machines, production lines, and automated processes
- Ladder Logic Programming: Uses TIA Portal or STEP 7 software
- Industrial Ethernet: Communicates via PROFINET or Ethernet
- Data Blocks (DBs): Stores process data, counters, timers, and variables
- S7 Protocol: Native communication protocol for data exchange
Difference from Siemens CNCs:
| Siemens S7 PLC | Siemens CNC (840D, etc.) |
|---|---|
| Automation controller for machines/processes | CNC control for machine tools (mills, lathes) |
| Programmed with ladder logic (TIA Portal) | Programmed with G-code and PLC |
| Use S7 connector (this guide) | Use OPC-UA or EtherNet/IP |
| Data in data blocks (DBs) | Data via CNC-specific protocols |
Applicable PLCs
MachineMetrics supports the following Siemens S7 PLC families:
✅ Supported PLC Models:
| PLC Family | Description | Common Models |
|---|---|---|
| S7-300 | Modular PLC for mid-range applications | CPU 313, CPU 314, CPU 315, CPU 317 |
| S7-400 | High-performance modular PLC | CPU 412, CPU 414, CPU 416, CPU 417 |
| S7-1200 | Compact PLC for small to medium machines | CPU 1211, CPU 1212, CPU 1214, CPU 1215 |
| S7-1500 | Advanced modular PLC with high performance | CPU 1511, CPU 1513, CPU 1515, CPU 1517 |
Communication Modules:
- CP 343-1 (for S7-300)
- CP 443-1 (for S7-400)
- Integrated Ethernet (S7-1200/1500)
Important Notes:
- ⚠️ S7-200 series has limited support (use S7-200 SMART or upgrade to S7-1200)
- ✅ S7-1200 and S7-1500 have integrated Ethernet (no communication module needed)
- ✅ S7-300 and S7-400 require Ethernet communication modules (CP 343-1, CP 443-1)
Prerequisites
Before setting up S7 PLC connectivity, ensure you have:
Hardware Requirements:
- Siemens S7 PLC (300, 400, 1200, or 1500 series)
- Ethernet communication capability:
- Built-in Ethernet port (S7-1200/1500)
- OR Ethernet communication module (S7-300/400)
- Network cable (Cat5e or Cat6)
- MachineMetrics Edge device on the same network
Network Requirements:
- Static IP address for PLC (highly recommended)
- Accessible Ethernet network between PLC and Edge device
- Firewall rules allowing S7 protocol communication (port 102)
PLC Programming Requirements:
- Access to PLC programming software:
- TIA Portal (for S7-1200/1500)
- STEP 7 (for S7-300/400)
- Knowledge of PLC data blocks (DBs) structure
- Ability to create or modify data blocks
- PLC program documentation (data block layout)
Access Requirements:
- Physical or remote access to PLC
- PLC programming permissions
- Network configuration access
Network Configuration
Connecting PLC to Company Network
Step 1: Physical Connection
- Locate Ethernet port on PLC:
- S7-1200/1500: Built-in Ethernet port on CPU
- S7-300/400: Ethernet port on CP communication module
- Connect network cable from PLC to network switch
- Verify link lights are active
Step 2: Configure PLC IP Address
For S7-1200/1500 (TIA Portal):
- Open TIA Portal
- Connect to PLC (online or via project)
- Navigate to PLC device configuration
- Select Ethernet interface (PROFINET interface)
- Set IP configuration:
- IP Address: (e.g., 192.168.1.100)
- Subnet Mask: (e.g., 255.255.255.0)
- Gateway: (e.g., 192.168.1.1)
- Set IP address assignment to Set IP address in the project (static)
- Download configuration to PLC
For S7-300/400 (STEP 7):
- Open STEP 7
- Navigate to Hardware Configuration
- Select CP 343-1 or CP 443-1 communication module
- Double-click to open properties
- Configure Ethernet settings:
- IP Address: (e.g., 192.168.1.100)
- Subnet Mask: (e.g., 255.255.255.0)
- Gateway: (e.g., 192.168.1.1)
- Save and download to PLC
Step 3: Enable S7 Communication
For S7-1200/1500:
- In TIA Portal, go to PLC Properties
- Navigate to Protection & Security → Connection mechanisms
- Enable Permit access with PUT/GET communication
- Download configuration to PLC
For S7-300/400:
- S7 communication is typically enabled by default
- Verify in CP module properties if needed
Step 4: Test Network Connectivity
From Edge device or another computer:
ping 192.168.1.100
Expected Result: Successful ping responses
PLC Configuration
Creating Data Blocks for MachineMetrics
MachineMetrics reads data from Data Blocks (DBs) in the PLC. You need to create or identify data blocks containing the information you want to collect.
Step 1: Identify Data to Collect
Common data points for production monitoring:
| Data Type | Example Variables | Data Type in PLC |
|---|---|---|
| Machine Status | Running, Idle, Stopped | BOOL or INT |
| Part Count | Parts produced, parts rejected | INT or DINT |
| Cycle Time | Current cycle time (seconds) | REAL or INT |
| Program Number | Active program/recipe ID | INT or STRING |
| Process Variables | Temperature, pressure, speed | REAL |
| Alarms | Active alarm flags | BOOL or WORD |
Step 2: Create or Locate Data Block
Option A: Create New Data Block (Recommended)
Create a dedicated data block for MachineMetrics:
- In TIA Portal or STEP 7, add new data block
- Name it (e.g., "DB100_MachineMetrics")
- Set as Standard DB (not Optimized for S7-1200/1500)
- Add data elements:
Example Data Block Structure (TIA Portal):
DB100_MachineMetrics
- Machine_Status (INT) // 0=Stopped, 1=Idle, 2=Running
- Part_Count (DINT) // Total parts produced
- Cycle_Time (REAL) // Current cycle time in seconds
- Program_Number (INT) // Active program ID
- Temperature (REAL) // Process temperature
- Alarm_Active (BOOL) // TRUE if alarm present
Step 3: Populate Data Block
In your PLC program, write process data to the data block:
Example Ladder Logic (ST/SCL):
// Update machine status
DB100_MachineMetrics.Machine_Status := Machine_State;
// Update part count when part completes
IF Part_Complete THEN
DB100_MachineMetrics.Part_Count := DB100_MachineMetrics.Part_Count + 1;
END_IF;
// Update cycle time
DB100_MachineMetrics.Cycle_Time := Current_Cycle_Time;
// Update program number
DB100_MachineMetrics.Program_Number := Active_Program;
Step 4: Set Data Block Access
For S7-1200/1500:
- Select data block in project tree
- Go to Properties
- Under Attributes, set:
- Optimized block access: Disabled (important!)
- Access: Standard - compatible with S7-300/400
- Download to PLC
For S7-300/400:
- Data blocks are accessible by default
- No special configuration needed
MachineMetrics Connector Setup
Step 1: Add Machine in MachineMetrics
- Log into MachineMetrics at app.machinemetrics.com
- Navigate to Assets → Machines
- Click Add Machine
- Enter machine details:
- Machine Name: (e.g., "Assembly-Line-01", "Packaging-Station-A")
- Machine Type: (Select appropriate type)
- Make: (Machine builder or "Siemens S7 PLC")
- Click Next
Step 2: Select S7 Connector
- In Data Collection Method, select Siemens S7 or S7 PLC
- If not visible, select Custom Adapter and enter
s7orsiemens-s7adapter
Step 3: Configure Data Block Extraction (JSON)
First, configure the S7 connector with a JSON script to extract data from the PLC data blocks. This is entered in the adapter settings JSON field:
{
"device": {
"rack": 0,
"slot": 1
},
"datablocks": {
"machine_status": {
"db": 100,
"offset": 0,
"type": "INT"
},
"part_count": {
"db": 100,
"offset": 2,
"type": "DINT"
},
"cycle_time": {
"db": 100,
"offset": 6,
"type": "REAL"
},
"program_number": {
"db": 100,
"offset": 10,
"type": "INT"
}
}
}
Configuration Parameters:
- device.rack: Rack number (typically 0 for all PLCs)
- device.slot: CPU slot number:
- S7-1200/1500: Usually
1 - S7-300: Usually
2(depends on hardware config) - S7-400: Usually
2or3(check hardware config)
- S7-1200/1500: Usually
- datablocks: Object containing all data block variables to extract
- db: Data block number
- offset: Byte offset within the data block
- type: PLC data type (INT, DINT, REAL, BOOL, etc.)
Step 4: Configure Transform Script (Optional)
If you need to process the extracted data (e.g., derive execution state, perform calculations), create a separate transform script:
version: 2
declare-keys:
- machine_status
- part_count
- cycle_time
- program_number
variables:
execution:
- source: machine_status == 2
- state:
- ACTIVE: this
- READY: machine_status == 1
- INTERRUPTED: machine_status == 0
data-items:
- execution
- machine_status
- part_count
- cycle_time
- program_number
How This Works:
- JSON Configuration: Extracts raw data from PLC data blocks and makes it available as variables
- Transform Script: Processes those variables into meaningful states and metrics
- Data Items: Lists which variables/states to send to MachineMetrics
Note: The JSON data block configuration is required. The transform script is optional and only needed if you need to process or derive data from the raw PLC values.
Step 4: Save and Test
- Click Test Connection
- Verify successful connection
- If successful, click Save
Data Block Configuration
Understanding Data Block Offsets
Each variable in a data block has an offset (byte position) and a data type (size).
Common S7 Data Types:
| S7 Type | Size (bytes) | Description | Example |
|---|---|---|---|
| BOOL | 1 bit | Boolean (TRUE/FALSE) | Machine running flag |
| BYTE | 1 | 8-bit unsigned integer (0-255) | Status byte |
| INT | 2 | 16-bit signed integer (-32768 to 32767) | Program number |
| DINT | 4 | 32-bit signed integer | Part count |
| REAL | 4 | 32-bit floating point | Temperature, pressure |
| STRING | Variable | Text string | Program name |
Calculating Offsets:
Offsets are byte addresses in the data block:
Example Data Block Layout:
Byte 0-1: Machine_Status (INT) - offset: 0
Byte 2-5: Part_Count (DINT) - offset: 2
Byte 6-9: Cycle_Time (REAL) - offset: 6
Byte 10-11: Program_Number (INT) - offset: 10
Byte 12-15: Temperature (REAL) - offset: 12
Rules:
- Offsets start at 0
- Next offset = current offset + size of previous variable
- Example: INT at offset 0 (2 bytes) → next variable at offset 2
Reading Data from TIA Portal / STEP 7
To find offsets in TIA Portal:
- Open data block
- View Declaration section
- Offsets are shown in left column (e.g.,
DBX 0.0,DBW 2,DBD 6)
Offset Notation:
DBX= Bit addressDBB= Byte addressDBW= Word address (2 bytes)DBD= Double word address (4 bytes)
Example:
DBW 0= Word at offset 0 (INT)DBD 2= Double word at offset 2 (DINT or REAL)
Complete Data Block Configuration Example
Here's a comprehensive example showing how to extract various data types from multiple data blocks, including counters, status bits, and process variables:
{
"device": {
"rack": 0,
"slot": 1
},
"datablocks": {
"part_count_line_a": {
"db": 250,
"offset": 200,
"type": "DINT"
},
"reject_count": {
"db": 250,
"offset": 240,
"type": "DINT"
},
"manual_mode": {
"db": 500,
"offset": 800,
"bit": 0
},
"auto_mode": {
"db": 500,
"offset": 801,
"bit": 0
},
"machine_running": {
"db": 500,
"offset": 801,
"bit": 0
},
"machine_fault": {
"db": 500,
"offset": 795,
"bit": 2
},
"production_type": {
"db": 500,
"offset": 1500,
"bit": 0
},
"safety_door": {
"db": 500,
"offset": 920,
"bit": 0
},
"station_a_ready": {
"db": 520,
"offset": 1200,
"bit": 0
},
"station_b_ready": {
"db": 520,
"offset": 1200,
"bit": 1
},
"robot_at_home": {
"db": 600,
"offset": 850,
"bit": 0
},
"robot_no_fault": {
"db": 600,
"offset": 860,
"bit": 3
},
"robot_teach_mode": {
"db": 600,
"offset": 1850,
"bit": 7
},
"conveyor_fault": {
"db": 540,
"offset": 1420,
"bit": 4
},
"conveyor_manual": {
"db": 540,
"offset": 1380,
"bit": 3
},
"conveyor_home": {
"db": 540,
"offset": 850,
"bit": 0
},
"clamp_closed": {
"db": 520,
"offset": 850,
"bit": 0
},
"clamp_no_fault": {
"db": 520,
"offset": 860,
"bit": 3
},
"press_at_home": {
"db": 560,
"offset": 850,
"bit": 0
},
"press_no_fault": {
"db": 560,
"offset": 860,
"bit": 3
},
"coolant_low_flow": {
"db": 500,
"offset": 980,
"bit": 1
}
}
}
Key Points About This Configuration:
-
Device Section: Specifies the PLC rack and slot
rack: 0- Most common, but verify with your PLC configurationslot: 1- CPU slot number, typically 1 for S7-300/400, may be 0 for S7-1200/1500
-
Integer Counters (DINT):
part_count_line_a- Production counter from DB250reject_count- Scrap/reject counter from DB250- Use DINT (32-bit) for counters to avoid rollover
-
Boolean Status Bits:
- Each bit requires both
offset(byte) andbit(0-7) position - Example:
"offset": 800, "bit": 0reads bit 0 of byte 800 - Multiple bits can be read from the same byte (e.g.,
station_a_readyandstation_b_ready)
- Each bit requires both
-
Multiple Data Blocks:
- This example reads from DB250, DB500, DB520, DB540, DB560, DB600
- You can read from as many data blocks as needed
- Each data block contains different aspects of the system
Transform Script for Execution State:
After extracting the raw data blocks, you need a separate transform script to derive execution states and other metrics:
version: 2
declare-keys:
- part_count_line_a
- reject_count
- manual_mode
- auto_mode
- machine_running
- machine_fault
- production_type
- safety_door
- station_a_ready
- station_b_ready
- robot_at_home
- robot_no_fault
- robot_teach_mode
- conveyor_fault
- conveyor_manual
- conveyor_home
- clamp_closed
- clamp_no_fault
- press_at_home
- press_no_fault
- coolant_low_flow
variables:
execution:
- source: machine_running and not machine_fault and not safety_door
- state:
- ACTIVE: this
- READY: not machine_fault and not safety_door
- INTERRUPTED: machine_fault or safety_door
data-items:
- execution
- part_count_line_a
- reject_count
- machine_running
- machine_fault
- manual_mode
- auto_mode
Important Notes:
- The JSON configuration extracts raw data from the PLC data blocks
- The transform script processes that data into meaningful states (execution, availability, etc.)
- Always verify data block numbers, offsets, and bit positions in your TIA Portal/STEP 7 project
- Test thoroughly before production use
Part Counting Configuration
Setting Up Part Counting from S7 PLC
Step 1: Create Part Counter in PLC
In your PLC program, maintain a part counter:
// Part count logic
IF Part_Complete AND NOT Part_Complete_Old THEN
DB100_MachineMetrics.Part_Count := DB100_MachineMetrics.Part_Count + 1;
END_IF;
Part_Complete_Old := Part_Complete;
Step 2: Add Part Count to JSON Data Block Configuration
Ensure part counter is included in your JSON data block configuration:
{
"device": {
"rack": 0,
"slot": 1
},
"datablocks": {
"part_count": {
"db": 100,
"offset": 2,
"type": "DINT"
}
}
}
Option 1: Map Part Count Directly
The simplest approach is to map the extracted part_count directly as a counter in MachineMetrics without a transform script.
- The JSON configuration extracts the part count value from the PLC
- Map it directly in Data Mapping as PART_COUNT
- No transform script needed
Option 2: Use Part Count in Transform Script
If you need to process the part count or use it in logic, reference it in a transform script:
version: 2
declare-keys:
- part_count
variables:
# Optional: You can create derived metrics from part_count
parts_per_hour:
- source: part_count # Use in calculations if needed
data-items:
- part_count
Step 3: Configure Data Mapping
- Go to Machine Settings → Data Mapping tab
- Map
part_countdata item:- Type: EVENT
- Subtype: PART_COUNT
- Component: Machine or Controller
- Click Save
Step 4: Configure Data Rules
- Go to Machine Settings → Data Rules tab
- Set Part Count Source to
part_count - Configure reset behavior:
- Reset on Program Start: Optional (depends on your process)
- Reset on Shift: Optional
- Click Save
Step 5: Verify Part Counting
- Trigger a part completion in your process
- Verify PLC counter increments (check online in TIA Portal)
- Check MachineMetrics Parts tab shows increment
- Verify count matches PLC value
Handling Part Counter Resets
Option 1: Never Reset (Cumulative Count)
- Part counter continuously increments
- MachineMetrics tracks total lifetime parts
Option 2: Reset via PLC Logic
Reset counter based on conditions:
// Reset part count on program start
IF Program_Start THEN
DB100_MachineMetrics.Part_Count := 0;
END_IF;
// Reset part count on shift change
IF Shift_Change THEN
DB100_MachineMetrics.Part_Count := 0;
END_IF;
Option 3: Reset via MachineMetrics Data Rules
Configure automatic reset in Data Rules:
- Reset on program start
- Reset on shift boundaries
- Reset on operator action
Data Mapping
Step 1: Configure Data Mapping
- Go to Machine Settings → Data Mapping tab
- Map S7 PLC data items to MachineMetrics standard types
Example Mappings:
| S7 Variable | MachineMetrics Type | Subtype | Component |
|---|---|---|---|
machine_status | EVENT | EXECUTION | Controller |
part_count | EVENT | PART_COUNT | Machine |
cycle_time | SAMPLE | Custom (Cycle Time) | Machine |
program_number | EVENT | PROGRAM | Controller |
temperature | SAMPLE | TEMPERATURE | Process |
Step 2: Create State Mapping (for Machine Status)
If machine_status is an integer representing states, you need to map the values properly. You must first extract the data with JSON, then declare it and map it in a transform script:
JSON Configuration (extract the value):
{
"device": {
"rack": 0,
"slot": 1
},
"datablocks": {
"machine_status": {
"db": 100,
"offset": 0,
"type": "INT"
}
}
}
Transform Script (map states):
version: 2
declare-keys:
- machine_status
variables:
execution:
- source: machine_status
- state:
- ACTIVE: this == 2 # 2 = Running
- READY: this == 1 # 1 = Idle
- INTERRUPTED: this == 0 # 0 = Stopped
data-items:
- execution
Step 3: Verify Data in Machine View
- Navigate to Machines → Select your machine
- Verify data displays correctly
- Check real-time updates
Troubleshooting
Connection Issues
Problem: Cannot Connect to PLC
Possible causes:
- Incorrect IP address
- Network connectivity issue
- Firewall blocking port 102
- Wrong rack/slot configuration
- PUT/GET not enabled (S7-1200/1500)
Solutions:
- Verify PLC IP address (check TIA Portal/STEP 7)
- Test with ping:
ping 192.168.1.100 - Verify firewall allows S7 communication (port 102, TCP)
- Check rack/slot numbers match PLC hardware configuration
- Verify PUT/GET enabled in PLC properties (S7-1200/1500)
- Check PLC is online and operational
Problem: Connection Intermittent
Possible causes:
- Network instability
- PLC high CPU load
- Polling interval too fast
- DHCP IP address changing
Solutions:
- Use static IP for PLC
- Monitor PLC CPU load in TIA Portal/STEP 7
- Increase poll_interval (e.g., 2000ms)
- Check network quality with continuous ping
- Verify no IP conflicts on network
Data Reading Issues
Problem: Data Not Updating
Possible causes:
- Incorrect data block number
- Wrong offsets
- Data block optimized (S7-1200/1500)
- PLC program not writing to data block
Solutions:
- Verify data block number matches PLC program
- Check offsets in TIA Portal/STEP 7 declaration view
- Ensure data block is not optimized (S7-1200/1500)
- Verify PLC program updates data block values
- Monitor data block online in programming software
- Check adapter logs for read errors
Problem: Wrong Data Values
Possible causes:
- Incorrect data type
- Wrong byte order (endianness)
- Offset calculation error
Solutions:
- Verify data type matches PLC declaration (INT, DINT, REAL, etc.)
- Check offset calculation (count bytes correctly)
- Monitor raw values in adapter diagnostics
- Compare with online values in TIA Portal/STEP 7
PLC Configuration Issues
Problem: PUT/GET Communication Denied (S7-1200/1500)
Possible causes:
- PUT/GET not enabled in PLC properties
Solutions:
- In TIA Portal, go to PLC Properties
- Navigate to Protection & Security → Connection mechanisms
- Enable Permit access with PUT/GET communication
- Download configuration to PLC
Problem: Data Block Access Denied
Possible causes:
- Data block optimized (S7-1200/1500)
- Data block protection enabled
Solutions:
- Set data block to Standard (not optimized)
- In data block properties, disable Optimized block access
- Check Access is set to Standard
- Download to PLC
Problem: Cannot Read Specific Variables
Possible causes:
- Incorrect offset
- Overlapping variables
- Data alignment issue
Solutions:
- Review data block layout carefully
- Verify no overlapping offsets
- Ensure proper data alignment (DINT/REAL on even boundaries)
- Recalculate offsets
Additional Resources
MachineMetrics Resources:
- Machine Settings Guide - Configure data mapping
- Transform Adapter Scripts Guide - Advanced data transformation
- Connectivity Overview - Compare connectivity methods
Siemens Resources:
- Siemens Industry website: https://www.siemens.com/industrial-automation
- TIA Portal downloads: https://support.industry.siemens.com/cs/document/109745155
- STEP 7 documentation
- S7 communication protocol documentation
Related Guides:
- OPC-UA Guide - For Siemens CNC controls (840D)
- Allen Bradley Guide - For Allen Bradley PLCs
- Edge Device Setup - Configure Edge
- Network Requirements - Firewall setup
Getting Help
MachineMetrics Support:
- Email: support@machinemetrics.com
- Phone: 844-822-0664
- Support Portal: https://support.machinemetrics.com
Before Contacting Support:
- Note Siemens PLC model (S7-300, 400, 1200, or 1500)
- Document CPU type and firmware version
- Note rack and slot configuration
- Verify network connectivity (ping test)
- Export data block declaration from TIA Portal/STEP 7
- Capture adapter configuration (YAML)
- Check adapter logs
Information to Provide:
- PLC model and CPU type (e.g., S7-1500 CPU 1513-1 PN)
- PLC firmware version
- Network configuration (IP address, subnet, gateway)
- Rack and slot numbers
- Data block number and structure (export from TIA Portal)
- Adapter configuration (YAML)
- Description of issue and troubleshooting steps taken
- Screenshots from TIA Portal showing data block and network config
For Data Reading Issues:
- Provide data block export or screenshot of declaration
- Note specific variables that aren't reading correctly
- Include expected vs actual values
- Provide PLC online monitoring screenshot