Skip to main content

Siemens S7 PLC Connectivity


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.


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 PLCSiemens CNC (840D, etc.)
Automation controller for machines/processesCNC 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 FamilyDescriptionCommon Models
S7-300Modular PLC for mid-range applicationsCPU 313, CPU 314, CPU 315, CPU 317
S7-400High-performance modular PLCCPU 412, CPU 414, CPU 416, CPU 417
S7-1200Compact PLC for small to medium machinesCPU 1211, CPU 1212, CPU 1214, CPU 1215
S7-1500Advanced modular PLC with high performanceCPU 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

  1. Locate Ethernet port on PLC:
    • S7-1200/1500: Built-in Ethernet port on CPU
    • S7-300/400: Ethernet port on CP communication module
  2. Connect network cable from PLC to network switch
  3. Verify link lights are active

Step 2: Configure PLC IP Address

For S7-1200/1500 (TIA Portal):

  1. Open TIA Portal
  2. Connect to PLC (online or via project)
  3. Navigate to PLC device configuration
  4. Select Ethernet interface (PROFINET interface)
  5. 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)
  6. Set IP address assignment to Set IP address in the project (static)
  7. Download configuration to PLC

For S7-300/400 (STEP 7):

  1. Open STEP 7
  2. Navigate to Hardware Configuration
  3. Select CP 343-1 or CP 443-1 communication module
  4. Double-click to open properties
  5. 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)
  6. Save and download to PLC

Step 3: Enable S7 Communication

For S7-1200/1500:

  1. In TIA Portal, go to PLC Properties
  2. Navigate to Protection & SecurityConnection mechanisms
  3. Enable Permit access with PUT/GET communication
  4. 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 TypeExample VariablesData Type in PLC
Machine StatusRunning, Idle, StoppedBOOL or INT
Part CountParts produced, parts rejectedINT or DINT
Cycle TimeCurrent cycle time (seconds)REAL or INT
Program NumberActive program/recipe IDINT or STRING
Process VariablesTemperature, pressure, speedREAL
AlarmsActive alarm flagsBOOL or WORD

Step 2: Create or Locate Data Block

Option A: Create New Data Block (Recommended)

Create a dedicated data block for MachineMetrics:

  1. In TIA Portal or STEP 7, add new data block
  2. Name it (e.g., "DB100_MachineMetrics")
  3. Set as Standard DB (not Optimized for S7-1200/1500)
  4. 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:

  1. Select data block in project tree
  2. Go to Properties
  3. Under Attributes, set:
    • Optimized block access: Disabled (important!)
    • Access: Standard - compatible with S7-300/400
  4. 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

  1. Log into MachineMetrics at app.machinemetrics.com
  2. Navigate to AssetsMachines
  3. Click Add Machine
  4. 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")
  5. Click Next

Step 2: Select S7 Connector

  1. In Data Collection Method, select Siemens S7 or S7 PLC
  2. If not visible, select Custom Adapter and enter s7 or siemens-s7 adapter

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 2 or 3 (check hardware config)
  • 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:

  1. JSON Configuration: Extracts raw data from PLC data blocks and makes it available as variables
  2. Transform Script: Processes those variables into meaningful states and metrics
  3. 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

  1. Click Test Connection
  2. Verify successful connection
  3. 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 TypeSize (bytes)DescriptionExample
BOOL1 bitBoolean (TRUE/FALSE)Machine running flag
BYTE18-bit unsigned integer (0-255)Status byte
INT216-bit signed integer (-32768 to 32767)Program number
DINT432-bit signed integerPart count
REAL432-bit floating pointTemperature, pressure
STRINGVariableText stringProgram 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:

  1. Open data block
  2. View Declaration section
  3. Offsets are shown in left column (e.g., DBX 0.0, DBW 2, DBD 6)

Offset Notation:

  • DBX = Bit address
  • DBB = Byte address
  • DBW = 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:

  1. Device Section: Specifies the PLC rack and slot

    • rack: 0 - Most common, but verify with your PLC configuration
    • slot: 1 - CPU slot number, typically 1 for S7-300/400, may be 0 for S7-1200/1500
  2. Integer Counters (DINT):

    • part_count_line_a - Production counter from DB250
    • reject_count - Scrap/reject counter from DB250
    • Use DINT (32-bit) for counters to avoid rollover
  3. Boolean Status Bits:

    • Each bit requires both offset (byte) and bit (0-7) position
    • Example: "offset": 800, "bit": 0 reads bit 0 of byte 800
    • Multiple bits can be read from the same byte (e.g., station_a_ready and station_b_ready)
  4. 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.

  1. The JSON configuration extracts the part count value from the PLC
  2. Map it directly in Data Mapping as PART_COUNT
  3. 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

  1. Go to Machine SettingsData Mapping tab
  2. Map part_count data item:
    • Type: EVENT
    • Subtype: PART_COUNT
    • Component: Machine or Controller
  3. Click Save

Step 4: Configure Data Rules

  1. Go to Machine SettingsData Rules tab
  2. Set Part Count Source to part_count
  3. Configure reset behavior:
    • Reset on Program Start: Optional (depends on your process)
    • Reset on Shift: Optional
  4. Click Save

Step 5: Verify Part Counting

  1. Trigger a part completion in your process
  2. Verify PLC counter increments (check online in TIA Portal)
  3. Check MachineMetrics Parts tab shows increment
  4. 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

  1. Go to Machine SettingsData Mapping tab
  2. Map S7 PLC data items to MachineMetrics standard types

Example Mappings:

S7 VariableMachineMetrics TypeSubtypeComponent
machine_statusEVENTEXECUTIONController
part_countEVENTPART_COUNTMachine
cycle_timeSAMPLECustom (Cycle Time)Machine
program_numberEVENTPROGRAMController
temperatureSAMPLETEMPERATUREProcess

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

  1. Navigate to Machines → Select your machine
  2. Verify data displays correctly
  3. 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:

  1. Verify PLC IP address (check TIA Portal/STEP 7)
  2. Test with ping: ping 192.168.1.100
  3. Verify firewall allows S7 communication (port 102, TCP)
  4. Check rack/slot numbers match PLC hardware configuration
  5. Verify PUT/GET enabled in PLC properties (S7-1200/1500)
  6. 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:

  1. Use static IP for PLC
  2. Monitor PLC CPU load in TIA Portal/STEP 7
  3. Increase poll_interval (e.g., 2000ms)
  4. Check network quality with continuous ping
  5. 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:

  1. Verify data block number matches PLC program
  2. Check offsets in TIA Portal/STEP 7 declaration view
  3. Ensure data block is not optimized (S7-1200/1500)
  4. Verify PLC program updates data block values
  5. Monitor data block online in programming software
  6. Check adapter logs for read errors

Problem: Wrong Data Values

Possible causes:

  • Incorrect data type
  • Wrong byte order (endianness)
  • Offset calculation error

Solutions:

  1. Verify data type matches PLC declaration (INT, DINT, REAL, etc.)
  2. Check offset calculation (count bytes correctly)
  3. Monitor raw values in adapter diagnostics
  4. 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:

  1. In TIA Portal, go to PLC Properties
  2. Navigate to Protection & SecurityConnection mechanisms
  3. Enable Permit access with PUT/GET communication
  4. Download configuration to PLC

Problem: Data Block Access Denied

Possible causes:

  • Data block optimized (S7-1200/1500)
  • Data block protection enabled

Solutions:

  1. Set data block to Standard (not optimized)
  2. In data block properties, disable Optimized block access
  3. Check Access is set to Standard
  4. Download to PLC

Problem: Cannot Read Specific Variables

Possible causes:

  • Incorrect offset
  • Overlapping variables
  • Data alignment issue

Solutions:

  1. Review data block layout carefully
  2. Verify no overlapping offsets
  3. Ensure proper data alignment (DINT/REAL on even boundaries)
  4. Recalculate offsets

Additional Resources

MachineMetrics Resources:

Siemens Resources:

Related Guides:


Getting Help

MachineMetrics Support:

Before Contacting Support:

  1. Note Siemens PLC model (S7-300, 400, 1200, or 1500)
  2. Document CPU type and firmware version
  3. Note rack and slot configuration
  4. Verify network connectivity (ping test)
  5. Export data block declaration from TIA Portal/STEP 7
  6. Capture adapter configuration (YAML)
  7. 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