0% found this document useful (0 votes)
127 views

S7-1x00 DataLogging DOC V4.0 en

This document provides information on recording and monitoring process data using Siemens SIMATIC S7-1200/S7-1500 and STEP 7 V16 (TIA Portal). It describes a solution for recording process data and making it available for further processing. The solution uses SIMATIC S7 controllers and HMI devices to record tag values and events over time. The data is stored in an SQL database for long-term archiving and analysis.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
127 views

S7-1x00 DataLogging DOC V4.0 en

This document provides information on recording and monitoring process data using Siemens SIMATIC S7-1200/S7-1500 and STEP 7 V16 (TIA Portal). It describes a solution for recording process data and making it available for further processing. The solution uses SIMATIC S7 controllers and HMI devices to record tag values and events over time. The data is stored in an SQL database for long-term archiving and analysis.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 59

Recording and

monitoring process
data
Siemens
SIMATIC S7-1200 / S7-1500, STEP 7 V16 (TIA Portal) Industry
Online
https://support.industry.siemens.com/cs/ww/en/view/64396156 Support
Legal information

Legal information
Use of application examples
Application examples illustrate the solution of automation tasks through an interaction of several
components in the form of text, graphics and/or software modules. The application examples are
a free service by Siemens AG and/or a subsidiary of Siemens AG (“Siemens”). They are non-
binding and make no claim to completeness or functionality regarding configuration and
equipment. The application examples merely offer help with typical tasks; they do not constitute
customer-specific solutions. You yourself are responsible for the proper and safe operation of the
products in accordance with applicable regulations and must also check the function of the
respective application example and customize it for your system.
Siemens grants you the non-exclusive, non-sublicensable and non-transferable right to have the
application examples used by technically trained personnel. Any change to the application
examples is your responsibility. Sharing the application examples with third parties or copying the
application examples or excerpts thereof is permitted only in combination with your own products.
The application examples are not required to undergo the customary tests and quality inspections
of a chargeable product; they may have functional and performance defects as well as errors. It is
your responsibility to use them in such a manner that any malfunctions that may occur do not
result in property damage or injury to persons.

Disclaimer of liability
Siemens shall not assume any liability, for any legal reason whatsoever, including, without
limitation, liability for the usability, availability, completeness and freedom from defects of the
application examples as well as for related information, configuration and performance data and
any damage caused thereby. This shall not apply in cases of mandatory liability, for example
under the German Product Liability Act, or in cases of intent, gross negligence, or culpable loss of
life, bodily injury or damage to health, non-compliance with a guarantee, fraudulent
non-disclosure of a defect, or culpable breach of material contractual obligations. Claims for
damages arising from a breach of material contractual obligations shall however be limited to the
© Siemens AG 2020 All rights reserved

foreseeable damage typical of the type of agreement, unless liability arises from intent or gross
negligence or is based on loss of life, bodily injury or damage to health. The foregoing provisions
do not imply any change in the burden of proof to your detriment. You shall indemnify Siemens
against existing or future claims of third parties in this connection except where Siemens is
mandatorily liable.
By using the application examples you acknowledge that Siemens cannot be held liable for any
damage beyond the liability provisions described.

Other information
Siemens reserves the right to make changes to the application examples at any time without
notice. In case of discrepancies between the suggestions in the application examples and other
Siemens publications such as catalogs, the content of the other documentation shall have
precedence.
The Siemens terms of use (https://support.industry.siemens.com) shall also apply.

Security information
Siemens provides products and solutions with industrial security functions that support the secure
operation of plants, systems, machines and networks.
In order to protect plants, systems, machines and networks against cyber threats, it is necessary
to implement – and continuously maintain – a holistic, state-of-the-art industrial security concept.
Siemens’ products and solutions constitute one element of such a concept.
Customers are responsible for preventing unauthorized access to their plants, systems, machines
and networks. Such systems, machines and components should only be connected to an
enterprise network or the Internet if and to the extent such a connection is necessary and only
when appropriate security measures (e.g. firewalls and/or network segmentation) are in place.
For additional information on industrial security measures that may be implemented, please visit
https://www.siemens.com/industrialsecurity.
Siemens’ products and solutions undergo continuous development to make them more secure.
Siemens strongly recommends that product updates are applied as soon as they are available
and that the latest product versions are used. Use of product versions that are no longer
supported, and failure to apply the latest updates may increase customer’s exposure to cyber
threats.
To stay informed about product updates, subscribe to the Siemens Industrial Security RSS Feed
at: https://www.siemens.com/industrialsecurity.

Recording and monitoring process data


Article ID: 64396156, V4.0, 06/2020 2
Table of Contents

Table of Contents
Legal information ......................................................................................................... 2
1 Task ..................................................................................................................... 4
1.1 Overview............................................................................................... 4
2 Solution............................................................................................................... 5
2.1 Overview of the overall solution ........................................................... 5
2.2 Description of the core functionality ..................................................... 8
2.3 Hardware and software components used......................................... 11
3 Function Mechanisms of this application example ..................................... 14
3.1 General functions ............................................................................... 16
3.1.1 FB "LGF_SinusCI" .............................................................................. 16
3.1.2 FB "LGF_Impulse" .............................................................................. 16
3.2 FB "DataLog1200"/"DataLog1500" .................................................... 17
3.2.1 FC "Num2Name" ................................................................................ 20
3.3 FB "TMAIL_C" .................................................................................... 21
3.4 SIMATIC Automation Tool.................................................................. 23
3.5 Remote access to the controller ......................................................... 26
4 Commissioning the application example ...................................................... 27
4.1 Hardware customization ..................................................................... 27
4.2 PG/PC system settings ...................................................................... 28
© Siemens AG 2020 All rights reserved

4.2.1 Regional settings ................................................................................ 28


4.2.2 Task Scheduler .................................................................................. 29
4.3 Modifying the project .......................................................................... 37
4.3.1 TMAIL_C ............................................................................................ 37
4.3.2 CPU properties ................................................................................... 39
4.3.3 Downloading the project ..................................................................... 43
4.3.4 Changing the recorded data ............................................................... 45
4.4 Internet browser settings (Google Chrome) ....................................... 47
5 Operating the application example ................................................................ 50
5.1 Overview............................................................................................. 50
5.2 Remote maintenance ......................................................................... 50
5.3 Manual upload of the DataLog file ..................................................... 52
5.4 Automatic upload of the DataLog file ................................................. 53
5.5 Alarm generation by sending an email ............................................... 55
5.6 Data log sending as email attachment ............................................... 56
6 Appendix .......................................................................................................... 57
6.1 Service and support ........................................................................... 57
6.2 Links and literature ............................................................................. 58
6.3 Change documentation ...................................................................... 59

Recording and monitoring process data


Article ID: 64396156, V4.0, 06/2020 3
1 Task

1 Task
1.1 Overview
Introduction
Supermarkets and discount retailers must guarantee certain foodstuffs remain
refrigerated. If the cooling chain is broken, these foodstuffs can no longer be sold
but must be discarded.
This is why the cooling temperature must be continually recorded, archived and
monitored (with reporting functionality).

Overview of the automation task


The following Figure provides an overview of the automation task.
Figure 1-1

Discounter
© Siemens AG 2020 All rights reserved

Data Logging

ALARM

Description of the automation task


The automation task must contain the following requirements:
• It must be possible to invoke the data log via remote access.
• Program modifications should be implemented via remote management
where needed.
• The recorded data must be automatically transmitted (to a server) and
archived.
• If a maximum temperature is exceeded, a message must be issued to a
maintenance technician who then investigates the cause.

Recording and monitoring process data


Article ID: 64396156, V4.0, 06/2020 4
2 Solution

2 Solution
2.1 Overview of the overall solution
The STEP 7 development environment (TIA Portal) provides "Data log" data
recording for the SIMATIC S7-1200/S7-1500. Using these instructions, process
data can be saved in CSV format (comma-separated value) in the CPU's flash
memory (only with S7-1200) or on an inserted Memory Card.
You can access these CSV data logs as follows (for instance, to analyze them in
Microsoft Excel):
Table 2-1
No. Access type Saved in flash memory...
Reading out via... ...of the CPU ...On the SIMATIC Memory Card
(S7-1200 only) (SMC)
1. ...card reader no yes (CPU must be stopped for this)
2. ...integrated PLC web server yes yes
3. …SIMATIC Automation Tool no yes (also possible to automate
Version V3.1.4 (\16\) using
ApplicationProgrammingInterface)
4. ...as an attachment to an yes yes (automated by calling the
email sent from the CPU instruction "TMAIL_C" V6.0)
© Siemens AG 2020 All rights reserved

In the application example, the data logs will be saved on a Memory Card that is
inserted into the CPU. Manual access from the remote station will be displayed via
the integrated PLC web server. The DataLog files will be automatically uploaded
through the SIMATIC Automation Tool Version 3.1 SP4.
The SIMATIC S7-1x001 is capable of routing, which makes remote access over the
internet possible. For secure communication, the connection is available via a VPN
tunnel (virtual private network) with the appropriate hardware.
The "TMAIL_C" instruction V6.0 offers encrypted email sending through the
internal interface of the CPU, along with optional attachment functionality for files in
the file browser (such as Data Logs). To do this, the CPU needs an internet
connection and an existing account with an email provider with SMTP server
(simple mail transfer protocol) (\17\).
This function is used to implement alarm messaging and sending of the data log
file.
You can also send the alarm message as an SMS using a communications
extension:
• via SCALANCE M router or (\14\)
• via the CP 1242-7 GPRS for the S7-1200 (\15\)
This application example was tested with
• STEP 7 V16 (TIA Portal)
• S7-1200 CPU Firmware V4.4
• S7-1500 CPU Firmware V2.8

Note Additional information on calculating the service life of the SIMATIC Memory
Card can be found under \13\.

1 In the following, the S7-1200 and S7-1500 will be collectively referred to as S7-1x00.

Recording and monitoring process data


Article ID: 64396156, V4.0, 06/2020 5
2 Solution

Diagram
The following figure shows the most important components of the solution:
Figure 2-1
Service-PC with Email-Provider Email-Provider (Sender) Automation
• TIA Portal for remote maintenance • Receipt of the email dispatch order
(Recipient) • Sending email to recipient
network
• Goggle Chrome for • Receiving the email
manual DataLog upload
• SIMATIC Automation Tool for
automatic DataLog upload
• Email reception (email client
• for recipient providers)
Gateway- Gateway-
Server Server

SCALANCE
TS Adapter IE
Internet Internet Internet M874-x
Advanced
Win 10 Modem/ Router
Modem/ Router Router

Statische Static WAN IP address


WAN-IP-Adresse SIMATIC S7-1200
VPN-Client VPN-Server (Email client for
VPN tunnel
VPN tunnel
IndustrialEthernet
Ethernet
VPN-Server sender SIMATIC
provider) S7
Industrial Stationen

The cooling temperature can be measured using thermo elements or resistance


thermometers. The SIMATIC S7-1x00 offers specialized signal expansion modules
(TC and RTD) for interfacing.
Using the "Data Log" instruction, the temperature is written to a CSV file in the
© Siemens AG 2020 All rights reserved

storage on the SMC at a specified interval.


You can access the CPU's web server through a web browser (such as Google
Chrome) to download the CSV file to your service PC.
The remote connection between service PC and CPU is made via the internet.
A VPN tunnel is established for secure data transmission. A VPN-capable
modem/router is required on the CPU side in order to do this. On the PC side, the
internet connection is tied to suitable VPN software. The respective internet service
provider (ISP) assigns IP addresses on both sides. In order to address the CPU on
the plant side, you will need a static public IP address.
The cooling temperature is monitored continuously. If the specified maximum
temperature is exceeded, the "TMAIL_C" function sends an encrypted email
request via the internal Ethernet interface of the S7-1x00 to the output server of a
sender email provider (account required). Via its email provider, the recipient
receives the alarm message about the critical temperature increase and can
respond to it.
If the email provider offers the "Mail2SMS" service, it is even possible to send the
alarm message to a cellular phone as an SMS.
The logged temperature process values are archived as an attachment in a
separate encrypted email from the CPU.
The SIMATIC Automation Tool can also be used. An executable file is run at
regular intervals using the Windows Task Scheduler. The Task Scheduler access
the SIMATIC Automation Tool's API and saves the uploaded data log files to the
hard drive.

Recording and monitoring process data


Article ID: 64396156, V4.0, 06/2020 6
2 Solution

Advantages
This application example offers you the following advantages:
• Introduction to data logging with all functions
• Alarm generation via secure email
• Transmission of data logging, event-triggered as an email attachment
• Transmission of data logging, time-triggered via the API of the SIMATIC
Automation Tool
• Basics of remote maintenance through a VPN tunnel

Delimitation
The following system function blocks are called according to their function and
described:
• For data logging:
– DataLogCreate V1.0
– DataLogOpen V1.1
– DataLogWrite V1.0
– DataLogClear V1.1
– DataLogClose V1.0
– DataLogDelete V1.1
© Siemens AG 2020 All rights reserved

– DataLogNewFile V1.1
• "TMAIL_C" V6.0 for email sending
A detailed description of these instructions can be found in the Online Help in TIA
Portal by selecting the block and pressing F1, or in the system manual for STEP 7
(TIA Portal) (\6\).
This application example only describes the basics on creating a VPN tunnel.
Please refer to \10\ for a detailed description of the topic "Secure remote access
with VPN".
Secure email sending is implemented with the CPU's internal interface. This variant
also offers data log file sending as an email attachment. Further information on
sending secure requests to the email provider, even via the communications
extension with a Security CP, can be found in the application example
"Sending e-mails to the SMTP server with an S7 CPU" (\17\).
Refer to the application examples \14\ and \15\ for the alarm message via SMS
function.
The API of the SIMATIC Automation Tool provides the basis for automatic
uploading of data log files. A detailed description of the SIMATIC Automation Tool
V3.1 SP4 can be found in the user manual (\19\).

Required knowledge
Basic knowledge on the topic of "network communication" is assumed.

Recording and monitoring process data


Article ID: 64396156, V4.0, 06/2020 7
2 Solution

2.2 Description of the core functionality


Recording process values with data logging constitutes the core function of the
application example.
Figure 2-2
© Siemens AG 2020 All rights reserved

The data log instructions are used in the user program to save process values to
log files. The log files can be stored on the Memory Card (MC) or in the internal
storage of the CPU (only S7-1200). The log files are saved in CSV format. You can
access the CSV file as described in Table 2-1.
In this application example, the "Data Log" functionality consists of the following
seven instructions:

"DataLogCreate"
Figure 2-3

Use the "DataLogCreate" instruction to create data log file in the "\DataLogs" folder
of the load memory and specify the name ("NAME" parameter) and the maximum
number of data records ("RECORDS" parameter).
Choose the time stamp format with the "TIMESTAMP" parameter.
The data to be recorded are specified as a structure or PLC data type via the
"DATA" parameter.

Recording and monitoring process data


Article ID: 64396156, V4.0, 06/2020 8
2 Solution

Specify the headers (column headers) of the recorded data in the data log with the
"HEADER" parameter.
Creating a data log file with a specified name will generate a number ("ID"
parameter), which can be used to identify this file.

"DataLogOpen"
Figure 2-4

S7-1200 S7-1500

The "DataLogOpen" instruction opens an already existing data log file. A data log
file must be opened in order to write new data records to the file. You can use the
parameter "MODE" to decide whether the existing data records will be overwritten.
You can select the data log with the "ID" parameter. When "ID" = 0, the data log to
be opened will be specified by the name "NAME".
Opening the data log file with the "NAME" parameter will return the "ID" that other
DataLog instructions can use to access this file.
© Siemens AG 2020 All rights reserved

For the S7-1500, the "DataLogOpen" instructions also contain the interface
parameter "Data" (pointer to the data structure of the data log). In comparison to
the S7-1200, this enables verification of data consistency.

"DataLogWrite"
Figure 2-5

The "DataLogWrite" instruction writes a data record to the specified data log. The
already existing target data log must be opened so that the "DataLogWrite"
instruction can be run.
You can select the data log with the "ID" parameter.

Recording and monitoring process data


Article ID: 64396156, V4.0, 06/2020 9
2 Solution

"DataLogClear"
Figure 2-6

The "DataLogClear" instruction deletes all data records of a data log.


You can select the data log with the "ID" parameter.

"DataLogClose"
Figure 2-7

The "DataLogClose" instruction closes an open data log.


© Siemens AG 2020 All rights reserved

You can select the data log with the "ID" parameter.

"DataLogNewFile"
Figure 2-8

S7-1200 S7-1500

You will use the "DataLogNewFile" instruction to create a new data log with the
same properties as an existing data log file and a new name. Specify the maximum
number of data records with the "RECORDS" parameter.
The template file is specified with the "ID" parameter. Once the new data log file
with a new name ("NAME" parameter) is created, a new "ID" will be generated and
output for this file.
For the S7-1500, the "DataLogNewFile" instructions also contain the interface
parameter "Data" (pointer to the data structure of the data log). In comparison to
the S7-1200, this enables verification of data consistency.

Recording and monitoring process data


Article ID: 64396156, V4.0, 06/2020 10
2 Solution

"DataLogDelete"
Figure 2-9

The "DataLogDelete" instruction deletes the data log.


You can select the data log with the "ID" parameter. When "ID" = 0, the data log to
be deleted will be specified by the name "NAME". The "DelFile" parameter must be
"TRUE" in order to delete the data log.

Note More detailed information on Data Logging can be found in the Online Help in
TIA Portal by selecting the block and pressing F1, or in the system manual for
STEP 7 (TIA Portal) (\6\).

2.3 Hardware and software components used


The application example was created with the following components:
© Siemens AG 2020 All rights reserved

Hardware components
Table 2-2
Components Qty. Order number Note
POWER SUPPLY S7-1200 1 6EP1332-1SH71
PM1207
CPU 1211C, DC/DC/DC, 1 6ES7211-1AE40-0XB0 Firmware V4.4.0 (\4\)
6DI/4DO/2AI
CPU 1511C-1 PN 1 6ES7511-1CK01-0AB0 Firmware V2.8.2 (\5\)
SIMATIC S7 MEMORY 1 6ES7954-8LF02-0AA0 Insertable load memory; for saving the
CARD, 24 MB DataLog files;
created as Program card (\3\)
Remote service PC 1 With internet connection
Ethernet cable 4 6XV1870-3QH20
TP CORD RJ45/RJ45 2M
Circuit breakers 1 5SY6116-6 1-pin B, 16A
DSL modem 1–2 --- Depends on provider and router
TS Adapter IE Advanced 1 6ES7972-0EA00-0XA0 Optional (for other VPN server variants,
see \10\)

Recording and monitoring process data


Article ID: 64396156, V4.0, 06/2020 11
2 Solution

Standard software components

Table 2-3
No. Components Qty. Order number Note
5. SIMATIC STEP 7 1 6ES7822-0AA06-0YA5 • With update 1 (\8\)
Basic V16 • For configuration of the
S7-1200
6. SIMATIC STEP 7 1 6ES7822-1AA06-0YA5 • With update 1 (\8\)
Professional V16 • For configuration of the
S7-1200 and S7-1500
7. SIMATIC Automation 1 6ES7853-1AE03-0YA5 (\16\);
Tool V3.1 SP4 license required for use of the API
8. .NET Framework 4.6.2 1 Required to run the
"UploadDataLog.exe" file
9. Microsoft Excel 1 Component of
Microsoft Office
10. Task Scheduler Part of Windows 10 operating
system

Sample files and projects


© Siemens AG 2020 All rights reserved

The following list contains all files and projects used in this example.

Table 2-4
No. Components Note
1. 64396156_S7-1x00_DataLogging _TiaV16_CODE_V4.0.zip This compressed file contains the
STEP 7 project.
2. 64396156_SAT_UploadDataLog_SatV3.1.4_EXE_V1.4.zip This packed file contains the
executable program,
"UploadDataLog.exe", for
uploading the DataLog data in
connection with the SIMATIC
Automation Tool V3.1.4 or later
(\16\), as well as the source code
in C#.
3. 64396156_S7-1x00_DataLogging_DOC_V4.0_en.pdf This document.

Recording and monitoring process data


Article ID: 64396156, V4.0, 06/2020 12
2 Solution

Passwords
Project registration
Figure 2-10

Siemens.1

For the S7-1x00, the access level "HMI access" is selected (chapter 4.3.2).
The following passwords are assigned:
Table 2-5
Access level Password
© Siemens AG 2020 All rights reserved

Full access (no protection) full


Read access read

Recording and monitoring process data


Article ID: 64396156, V4.0, 06/2020 13
3 Function Mechanisms of this application example

3 Function Mechanisms of this application


example
Complete overview
Figure 3-1 shows the chronological sequence of the block calls in the example
project.
The cyclic interrupt OB "CyclicInterrupt" calls the FB "LGF_SinusCI". This imulates
the freezer temperature as a sine curve.
The following function blocks are called from the cyclic OB:
• FB "LGF_Impulse" supplies the trigger signal to log the temperature via the FB
"DataLog1x00".
• FB "DataLog1x00", together with the instance DB "InstDataLogSameFile",
coordinates the logging of the freezer temperature. Once the maximum
number of data records is reached, the recording begins again at the first data
record and overwrites it (with the already configured parameters).
• FB "TMAIL_C", together with the instance DB "InstTmailcAlarm", sends an
alarm email when a certain maximum temperature is exceeded.
• FB "DataLog1x00", together with the instance DB "InstDataLogNewFile",
coordinates the logging of the freezer temperature. Once the maximum
number of data records is reached, the current data log is closed and an
identical one with a different name is created and written to. This process
© Siemens AG 2020 All rights reserved

repeats until the specified maximum number of new data logs is reached and
the labeling begins again from the start in the original data log. Using the
preset parameters, the data records are deleted before the first recording.
• FB "TMAIL_C", together with the instance DB "InstTmailcCsvTransfer" sends
an email with the temperature data log as an attachment once the maximum
number of data records has been reached (FB "DataLog1x00" with instance
DB "InstDataLogNewFile").
The tags for parameter entry of the interfaces for the function blocks are located in
the DB "Data".
The last error-free and error-containing runs through the functions described above
are each retained with a time stamp. In the event of a run with errors, the status
and sub-status will be saved.

Recording and monitoring process data


Article ID: 64396156, V4.0, 06/2020 14
3 Function Mechanisms of this application example

Figure 3-1

Cyclic LGF_
Interrupt SinusCI

LGF_
Impulse

DataLog
Main Data
1x00

InstDataLog
SameFile

TMAIL_C
© Siemens AG 2020 All rights reserved

InstTmailc
Alarm

DataLog
1x00

InstDataLog
NewFile

TMAIL_C

InstTmailc
CsvTransfer

Organisation Instance
blocks Instructions data blocks Data blocks

Recording and monitoring process data


Article ID: 64396156, V4.0, 06/2020 15
3 Function Mechanisms of this application example

3.1 General functions


The following blocks used in the application example originate from the library with
general functions (LGF) for SIMATIC STEP 7 (TIA Portal) and SIMATIC S7-
1200/S7-1500 (\18\); they are described there in detail.

3.1.1 FB "LGF_SinusCI"

The FB "LGF_SinusCI" V3.0.0 simulates the temperature progression as a sine


curve.
Based on the parameterization in the application example, the temperature
simulation proceeds through a sine wave oscillation with an offset of -22 °C with an
amplitude of +/- 6°C and a period length of one minute (see Figure 3-2).
The FB "LGF_SinusCI" is called with a cycle time of 100 ms in the cyclic interrupt
OB "CyclicInterrupt".
Figure 3-2
© Siemens AG 2020 All rights reserved

3.1.2 FB "LGF_Impulse"

The FB "LGF_Impulse" V3.0.0 supplies the trigger signal to call the FB


"DataLog1x00".
With the parameters assigned in the application example, the FB "DataLog1x00" is
called every 2 seconds ("frequency" = 0.5 Hz) (input "write") in order to write an
entry in the data logging.
The FB "LGF_Impulse" is called in the cyclic OB "Main".

Recording and monitoring process data


Article ID: 64396156, V4.0, 06/2020 16
3 Function Mechanisms of this application example

3.2 FB "DataLog1200"/"DataLog1500"
The FB "DataLog1x00" coordinates data logging. The aim is to write a data record
into the data log (data logging file). To do this, the data log is created, opened and
written to, depending on the initial circumstances.
You can program the behavior in the event of an overflow (maximum number of
data records exceeded):
• Write to the existing data log with/without prior emptying (ring buffer)
• Close the existing data log and create/open and write to a new data log
with/without prior emptying
You also have the option of deleting the (newly) created data log.
The FB "DataLog1x00" exists for the SIMATIC S7-1200 (FB "DataLog1200") and
the S7-1500 (FB "DataLog1500"), as the interfaces for the instructions
"DataLogOpen" and "DataLogNewFile" contained therein differ depending on
controller.
The functionality of the FB "DataLog1x00" is identical, however.

Figure 3-3: FB "DataLog1x00"


DataLog1x00

Bool write done Bool


© Siemens AG 2020 All rights reserved

UDInt records busy Bool

UInt timestamp error Bool

String name status Word


subFunctionS
String header Word
tatus
Bool clear id DWord
numberRecor
USInt newFileMax UDInt
ds
Bool delete sync Bool

full Bool

currentName String
data
Variant Variant

Table 3-1: Parameters of the FB "DataLog1x00"


Name P type Data Description
type
write IN Bool Writes a data record ("data" data structure) into the data log
"currentName" upon a rising edge
Precondition: "delete" = FALSE
records IN UDInt Maximum number of data records in the data log
(DataLogCreate parameter*)
timestamp IN UInt Time stamping:
0: No time stamping
S7-1200 S7-1500
1: System time mm/dd/yyyy, yyyy-mm-dd,
Default: S7-1200 hh:mm:ss hh:mm:ss.999
2: Local time mm/dd/yyyy, mm/dd/yyyy,

Recording and monitoring process data


Article ID: 64396156, V4.0, 06/2020 17
3 Function Mechanisms of this application example

Name P type Data Description


type
hh:mm:ss hh:mm:ss[.999]
3: System time mm/dd/yyyy,
Default: S7-1500 hh:mm:ss[.999]
4: Local time yyyy-mm-dd,
hh:mm:ss.[999]
5: System time yyyy-mm-dd,
hh:mm:ss.[999]
(DataLogCreate-Parameter*)
name IN String Name of the data log (DataLogCreate parameter*)
header IN String Header of the data log (DataLogCreate parameter*)
clear IN Bool TRUE: Delete all data records in the data log "currentName"
before writing the first data record after overflow ("full" =
TRUE)
newFileMax IN USInt Maximum number of new data logs that will be
created/opened in the event of an overflow ("full" = TRUE)
delete IN Bool TRUE: Delete all data logs with the name "<name>" until
"<name>_<newFileMax>"
- invalidates "write"
done OUT Bool TRUE: The function was processed successfully
busy OUT Bool TRUE: The function is being processed
© Siemens AG 2020 All rights reserved

error OUT Bool TRUE: An error occurred during processing


status OUT Word 16#0000 - 16#7FFF: Error-free status of the FB
16#8000 - 16#FFFF: Error source
16#8601: Instruction "DataLogCreate"
16#8602: Instruction "DataLogOpen"
16#8603: Instruction "DataLogWrite"
16#8604: Instruction "DataLogClear"
16#8605: Instruction "DataLogClose"
16#8606: Instruction "DataLogNewFile"
16#8607: Instruction "DataLogDelete"
subFunctionStatus OUT Word status of the sub-function (see "status")
id OUT DWord Object ID of the data log
numberRecords OUT UDInt Current number of written data records
sync OUT Bool "numberRecords" is synchronized (retentive memory
available)
full OUT Bool TRUE: "numberRecords" = "records"
currentName OUT String Name of the data log
data IN_OUT Variant Pointer to the data structure which is written as data record
*DataLogCreate parameter: These parameters pertain to the creation of the data
logs via the instruction "DataLogCreate" and therefore have no effects on existing
data logs for the runtime!

Note The FB "DataLog1x00" counts the number of written data records


(“numberRecords”) on its own. A comparison only occurs when a data log is
created and its value is initialized with "0" and "sync" is set. "numberRecords"
and "sync" are retentive. As long as "sync" = TRUE, "numberRecords" is
synchronized with the real number of written data records in the data log. In
order to ensure this happens, you must delete the data log after program
modifications ("delete" = TRUE).

Recording and monitoring process data


Article ID: 64396156, V4.0, 06/2020 18
3 Function Mechanisms of this application example

Figure 3-4 shows the program sequence chart of the FB "DataLog1x00" for the
write process ("write" = TRUE).
Figure 3-4
© Siemens AG 2020 All rights reserved

The block is designed as a step chain.


At a positive edge at the input "write" a query will be issued whether the instruction
"DataLogClose" was carried out in the previous run-through (closed?). If this is the
case, a new data log with a corresponding name ("Num2Name") will be created
using the instruction "DataLogNewFile". Once it has been created successfully
(done), the data record counter will be reset (n:=0) and is thereby synchronized
(sync := TRUE).
Then, or when closed = FALSE, a query will be issued as to whether the maximum
number of data records was reached in the previous run (n = nMax?). If this is the
case, the data record counter will be reset (n:=0) and, if "clear" = TRUE, the data
log will be emptied with the instruction "DataLogClear".

Recording and monitoring process data


Article ID: 64396156, V4.0, 06/2020 19
3 Function Mechanisms of this application example

Then the data log will be written to with the current data record using the
"DataLogWrite" instruction. When writing is successful (done) the data record
counter will be incremented (n:=n+1) and queried whether the maximum number of
data records has been reached (n = nMax?). If so, this will be signaled (full
:=TRUE).
A query will then be issued whether the maximum number of new data logs has
been reached (m = mMax?). If this is not yet true, the current data log will be
closed using the instruction "DataLogClose", this will be registered (closed :=
TRUE) and the counter incremented for new data logs (m:=m+1).
Furthermore, in the event of an error message (error) for the DataLog instructions,
the following statuses will be stepped accordingly:
• In the event of non-existent data log ("Not exist"), jump to instruction
"DataLogCreate".
• In the event of data log not opened ("Not open"), jump to instruction
"DataLogOpen".
• In the event of existing data log ("Already exist"), also jump to instruction
"DataLogOpen".
When the data log is created successfully (done), the data record counter will be
reset (n:=0) using the instruction "DataLogCreate", and is thus synchronized (sync
:= TRUE).
All data logs with the name "<name>" to "<name>_<newFileMax>" will be deleted
using the input "delete" (= TRUE). The "delete" input has a higher priority than the
"write" input. Therefore "delete" must = FALSE in order to execute a write
© Siemens AG 2020 All rights reserved

command with "write".

Difference between FB "DataLog1200" and FB "DataLog1500"


For the S7-1500, the "DataLogOpen" and "DataLogNewFile" instructions also
contain the interface parameter "data" (pointer to the data structure of the data log).
In comparison to the S7-1200, this enables verification of data consistency when
both instructions are called. Corresponding status messages are output via
"subFunctionStatus". The functionality of the FB "DataLog1x00" is identical with the
S7-1200 and S7-1500, however.

In the application example, the FB "DataLog1x00" for data logging the temperature
is called twice in the cyclic OB "Main":
• with the instance DB "InstDataLogSameFile" for writing to the existing data log
(without prior emptying) in the event of an overflow: Using this data log, the
automatic upload is performed via the SIMATIC Automation Tool
(Table 2-1 no. 3).
• with the instance DB "InstDataLogNewFile" for creating/opening and writing to
a new data log (with prior emptying) in the event of an overflow: Upon reaching
the maximum number of data records, the current data log will be sent as an
email attachment while the new data log can continue being written to
(Table 2-1 no. 4).

3.2.1 FC "Num2Name"

The FC "Num2Name" takes the string "nameIn" and "number" and generates the
"nameOut" in the form "<nameIn>_<number>".
It is called in the FB "DataLog1x00" and specifies for "newFileMax" > 0 the name of
the new data log for the instructions "DataLogNewFile" and "DataLogOpen" and
"DataLogDelete".

Recording and monitoring process data


Article ID: 64396156, V4.0, 06/2020 20
3 Function Mechanisms of this application example

Figure 3-5: FC "Num2Name"


Num2Name

String nameIn nameOut String

USInt number

Table 3-2: Parameters of the FC "Num2Name"


Name P type Data type Description
nameIn IN String Name of the original data log
number IN USInt Number of the data log as attachment
nameOut OUT String Name of the new data log in the form "<nameIn>_<number>"

3.3 FB "TMAIL_C"
The FB "TMAIL_C" uses SMTP (Simple Mail Transfer Protocol) to send an email
over TCP/IP on the CPU's Industrial Ethernet connection.
"TMAIL_C" is executed asynchronously and the command extends over multiple
© Siemens AG 2020 All rights reserved

calls of "TMAIL_C". If you call "TMAIL_C", you must assign an instance.


In the application example, the FB "TMAIL_C" is called twice in the cyclic OB
"Main":
• with the instance DB "InstTmailcAlarm" for sending an alarm email when a
specific maximum temperature is exceeded
• with the instance DB "InstTmailcCsvTransfer" for sending an email with the
temperature data log as an attachment when the maximum number of data
records is reached
Figure 3-6 illustrates the call of the FB "TMAIL_C" with interconnection of the
parameter "ATTACHMENT" for sending the data log.
The system data type "TMail_FileReference" is passed at the parameter
"ATTACHMENT". It contains the path and the name of the file to be attached (see
"Description of TMAIL_C as of version V6.0" in \6\).

Recording and monitoring process data


Article ID: 64396156, V4.0, 06/2020 21
3 Function Mechanisms of this application example

Figure 3-6
© Siemens AG 2020 All rights reserved

The connection data, addressing and authentication for the mail server are passed
at the parameter "MAIL_ADDR_PARAM".
The email is sent via the integrated interface of the CPU by means of a secured
connection (SNMP over TSL) to an external email server.
The system data type "TMail_QDN_SEC" is used at the parameter
"MAIL_ADDR_PARAM".
Once activated, "TMAIL_C" logs in to the mail server (specified with the fully-
qualified domain name) with the access credentials (username and password) and
the X.509 V3 certificate loaded on the CPU (CA) for the mail server (with which the
TLS client validates the authentication from the TLS server); it then sends the email
request with the specified recipient address and the specified text (as well as
attachment).
Refer to application example \17\ for more information on the topic "Sending emails
over secured email connections".

Program details of block TMAIL_C


This application example uses the FB "TMAIL_C" in version 6.0.
You can find program details on the block "TMAIL_C" in the Online Help in TIA
Portal by selecting the block and pressing F1, or in the system manual for STEP 7
(TIA Portal) (\6\).

Recording and monitoring process data


Article ID: 64396156, V4.0, 06/2020 22
3 Function Mechanisms of this application example

3.4 SIMATIC Automation Tool


With the SIMATIC Automation Tool, you can perform commissioning and service
tasks on SIMATIC S7-1200, S7-1500, ET200, HMI, SITOP devices, SCALANCE
switches and SIMATIC RFID as well as MOBY Ident modules independently of TIA
Portal. The licensed tool provides an API (e.g. for automated use of the supported
operations with C#). These operations also include loading the CPU data log data
(saved to an inserted SIMATIC Memory Card).
Download no. 2 in Table 2-4 contains the console application
"UploadDataLog.exe". This was created in C# using Visual Studio 2015 and .NET
Framework V4.6.2.
The prerequisite for being able to run "UploadDataLog.exe" is an existing license
for the SIMATIC Automation Tool V3 (Table 2-3), which must be installed, along
with the installation of .NET Framework V4.6.2.
The file "UploadDataLog.exe" V1.4 makes it possible to upload DataLog files (also
over a router) when the following arguments are specified:
Table 3-3
No. Argument Description Format
1. Network card The application displays a list of available "0" to "n"
number network cards. Select the list number.
2. IP address IP address of CPU "xxx.xxx.xxx.xxx"
3. DataLog file DataLog file name "DataLog.csv" or "ALL" for
© Siemens AG 2020 All rights reserved

name (Case sensitive) all DataLog files


4. Destination Destination folder in which the DataLog file(s) e.g.: "c:\MyDataLogs"
folder will be stored (Must exist + Case sensitive!)
5. Password CPU password (if available): e.g.: "read" or omit if no
Password level "Full access" or "write-protected" password is assigned
(Case sensitive)
To upload the DataLog files, the application requires write-protected access to the
S7-1x00. When choosing a different access level as the lowest:
• "Full access incl. fail-safe (no protection)" for a failsafe CPU
• "Full access (no protection)" for a standard CPU
you must at least give the application the password of the next-lower access level
with write-protected access (chapter 4.3.2).
For example, the application may access an S7-1x00 with access level "HMI
access" using the passwords (if they exist) for the following access levels:
• "Read access"
• "Full access (no protection)"
• "Full access incl. fail-safe (no protection)" (only available for a failsafe
CPU)

Note The console application runs at the Windows Command Prompt "cmd.exe". The
sequence of the arguments is specified in Table 3-3. The arguments are
separated by spaces.

Recording and monitoring process data


Article ID: 64396156, V4.0, 06/2020 23
3 Function Mechanisms of this application example

Proceed as follows to ensure the file "UploadDataLog.exe" performs cleanly:


Table 3-4
No. Action
1. Extract the compressed file (Table 2-4 no. 2) on your computer.
2. Copy the console application, "UploadDataLog.exe", in it to the installation folder of
the SIMATIC Automation Tool V3.1 SP4.
(default: "c:\Program Files\Siemens\Automation\SimaticAutomationTool\bin\").
Administrator rights may be required for this.
3. Open the Command Prompt and navigate to the "UploadDataLog.exe" console
application folder:
"cd c:\Program Files\Siemens\Automation\SimaticAutomationTool\bin\"

4. Start the application "UploadDataLog.exe".


© Siemens AG 2020 All rights reserved

• The console application lists the available network adapters and displays the
error message "WRONG NUMBER OF ARGUMENTS !!!", since the application
requires that 4 or 5 arguments be passed.
• Remember the number of the network adapter to browse to.
Note: The network adapter with the "Auto" affix makes it possible to reach the CPU
for the network adapter setting DHCP.
5. Start the console application with the necessary arguments (see Table 3-3):
"UploadDataLog.exe 1 192.168.0.2 DataLog.csv c:\MyDataLogs read"

6. The "UploadDataLog.exe" console application runs as follows:


• List of found network adapters
• Output of the number of arguments:
arguments = 5
• Scan the selected network adapter: scan network card 1
• Insert the selected IP address:
insert device by IP address 192.168.0.2
• Search the selected IP address:
find IP address 192.168.0.2
• Check whether it is a CPU:
check if device is CPU
• Check whether CPU is password protected:
check if CPU is protected
• Check if remote access to DataLog files is permitted:
check if remote access on data logs is allowed
• Check if the "Data logs" ["Datenprotokolle"] folder exists:

Recording and monitoring process data


Article ID: 64396156, V4.0, 06/2020 24
3 Function Mechanisms of this application example

No. Action
check if folder ‚DataLogs‘ exists
• Display number of data logs found
1 data log files are found
• Check the found data logs with the searched file names:
check data log name 'DataLog.csv'
• Upload the selected DataLog file to the specified destination folder:
upload data log to destination c:\MyDataLogs
© Siemens AG 2020 All rights reserved

7. Open the destination folder and check whether the selected DataLog file exists.

Note If you receive an error message, please check the accessibility of the CPU - for
example via the ping command in the Command Prompt - and modify the
settings of the network adapter if you absolutely must.
A simultaneous online connection to the S7-1200, for example with STEP 7 (TIA
Portal), will prevent access to the data logs.

If you wish to modify the program code of the file "UploadDataLog.exe", you will
find a description of how to create a console application in Microsoft Visual Studio
in chapter 3.1 of the application example "Automated loading and archiving of the
CPU service data by means of the SIMATIC Automation Tool via the Application
Programming Interface (API)" (\12\).

Recording and monitoring process data


Article ID: 64396156, V4.0, 06/2020 25
3 Function Mechanisms of this application example

3.5 Remote access to the controller


Secure remote access to the controller is established via a VPN tunnel.
A virtual private network (VPN) is a data network that is used to transfer private
data through a public network (such as the internet). It thus enables secure
transmission over an unsecure network.
Use of a VPN tunnel is tied to a VPN-capable router on the controller side.
On the PC side, you only need appropriate VPN client software that will establish
the connection to the controller, as well as any internet connection.
This application example uses a wifi router with DSL internet access, and the wifi
network adapter of the PC.
In the internet, subscribers are usually assigned dynamic IP addresses.
However, a static IP address is required to find the VPN server on the internet (on
the CPU side).
The VPN connection described here is a client-server connection.
Please refer to appendix \10\ and the Siemens portfolio for an introduction to the
topic of "Secure remote access with VPN". The overview document explains the
possible constellations of an IP-based remote network with the requirements and
the links to in-depth configuration instructions.
For example, the application example "VPN tunnel between the TS Adapter IE
Advanced and Windows 7" is a good reference on secure access to an S7-1x00
over the internet and the demonstrated use cases.
© Siemens AG 2020 All rights reserved

Remote access to the controller via the internet is not necessarily required for
manual downloading of the recorded DataLog files. Local access is also sufficient
for demonstration purposes.
However, internet access is required to send emails via external providers.
For email sending, you must enable the port or protocol for outgoing connections
on the VPN server (router or TS Adapter IE Advanced):
• TCP port 465: SMTPS (Simple Mail Transfer Protocol over Secure Socket
Layer) or
• TCP port 587: MSA (Mail Submission Agent) with STARTTLS
• UDP port 123: NTP (Network Time Protocol)
The following protocols must be enabled for incoming connections on the VPN
server (router or TS Adapter IE Advanced):
• Simple Network Management Protocol (SNMP) for email sending
• Hyper Text Transfer Protocol over Secure Socket Layer (HTTPS) for retrieving
the CPU web server in an internet browser
• Internet Control Message Protocol (ICMP) to ping the CPU

Recording and monitoring process data


Article ID: 64396156, V4.0, 06/2020 26
4 Commissioning the application example

4 Commissioning the application example


4.1 Hardware customization
The application example has been implemented both with a CPU 1211C and
CPU 1511C-1 PN. If you use a different CPU you must change the corresponding
CPU in the project.
In the application example, the temperature curve is simulated using the block
"LGF_SinusCI" (see chapter 3.1.1). If you use an actual temperature sensor, you
may have to extend your hardware.
Both selected controllers have integrated analog inputs. You can find additional
modules in the hardware catalog in TIA Portal or in the TIA Selection Tool (\7\).

Hardware installation
The following figure shows the hardware setup of the application.
Figure 4-1
L1
N
PE
DC24V+

DC24V-

Remote Static public


adress IP
IP adress IP in the subnet of
© Siemens AG 2020 All rights reserved

Subnet mask the DSL router2


Router adress IP of the DSL TS Adapter IE
PM 1207 CPU 1211C
DNS server router2 Advanced

WAN
LAN IP adress 192.168.0.2
Subnet mask 255.255.255.0
IP adress 192.168.0.1
Router adress 192.168.0.1
Subnet mask 255.255.255.0
DNS server

DSL-Router2

CPU 1511C-1 PN

IP adress 192.168.0.3
Subnet mask 255.255.255.0
Router adress 192.168.0.1
DNS server
Wi-Fi DSL-Router1

ISDN
Remote
IP adress Win 10 Service PC
Subnet mask
Router adress
DHCP

Recording and monitoring process data


Article ID: 64396156, V4.0, 06/2020 27
4 Commissioning the application example

4.2 PG/PC system settings


The application example has been implemented with the Microsoft Windows 10
Enterprise operating system.
The following settings must be made in the operating system:

4.2.1 Regional settings

By default in English-speaking countries columns are divided by a comma


separator.
The following settings will allow you to open the CSV files in Microsoft Excel
directly and properly.
Table 4-1
No. Action
1. Open the "Region settings" in Windows.

2. • Select the regional format "English (United Kingdom)".


• Switch to "Change date formats".
© Siemens AG 2020 All rights reserved

3. Make the "Short date" appear in the format "dd.mm.yy".

Note Please refer to the S7-1200 system manual (\3\) for how to Import CSV format
data logs to non-USA/UK versions of Microsoft Excel.

Recording and monitoring process data


Article ID: 64396156, V4.0, 06/2020 28
4 Commissioning the application example

4.2.2 Task Scheduler

A task is created in the Windows Task Scheduler on the remote service PC to


automatically upload DataLog files. This will runs the console application
"UploadDataLog.exe" every 5 minutes. This will load the CSV file "DataLog" using
the API of the SIMATIC Automation Tool V3.1.4 and save it to the computer
(chapter 3.4).

Table 4-2
No. Action
1. Open the Windows Task Scheduler by clicking the Windows 10 icon and searching
for it.
© Siemens AG 2020 All rights reserved

2. The "Task Scheduler" overview window will open.


• In the upper right hand corner, click "Actions > Task Scheduler (Local) > Create
Basic Task…".

Recording and monitoring process data


Article ID: 64396156, V4.0, 06/2020 29
4 Commissioning the application example

No. Action
3. This will open the "Create Basic Task Wizard".
• Assign a name.
• Click on "Next >".

4. • Select the setting "Daily" under Trigger.


© Siemens AG 2020 All rights reserved

• Click on "Next >".

Recording and monitoring process data


Article ID: 64396156, V4.0, 06/2020 30
4 Commissioning the application example

No. Action
5. The current date is used as the start date.
• Input a start time.
• Click on "Next >".


© Siemens AG 2020 All rights reserved

6. As the action, select "Start a program".


• Click on "Next >".

Recording and monitoring process data


Article ID: 64396156, V4.0, 06/2020 31
4 Commissioning the application example

No. Action
7. Enter the following entries in the "Start a program" settings window:
• Program/script:
UploadDataLog.exe
• Adding arguments (optional):
1 192.168.0.2 DataLog.csv c:\MyDataLogs read
• Start in (optional):
c:\Program Files\Siemens\Automation\SimaticAutomationTool\bin\
Click on "Next >".
© Siemens AG 2020 All rights reserved

8. • Activate the option


Open the Properties dialog for this task when I click Finish.
• Click "Finish".

Recording and monitoring process data


Article ID: 64396156, V4.0, 06/2020 32
4 Commissioning the application example

No. Action
9. • In the "General" screen under "Security options", select the option "Run
whether user is logged on or not".
• Select the "Run with highest privileges" option.
• Under "Configure for:" select "Windows 10"
• Switch to the "Triggers" screen.
© Siemens AG 2020 All rights reserved

10. Select the created trigger entry and click on "Edit...".

Recording and monitoring process data


Article ID: 64396156, V4.0, 06/2020 33
4 Commissioning the application example

No. Action
11. • In "Advanced settings" activate the option "Repeat task every:"
• Select "5 minutes" as the interval.
• Select "for a duration of:" "1 day"
• Check the option "Stop all running tasks at end of repetition duration".
• Check "Stop task if it runs longer than:"
• Select "4 minutes" as the time.
• Accept the settings with "OK".
© Siemens AG 2020 All rights reserved

12. Switch to the "Conditions" screen.

Recording and monitoring process data


Article ID: 64396156, V4.0, 06/2020 34
4 Commissioning the application example

No. Action
13. • Under "Power", select the option "Wake the computer to run this task".
• Finish setting the properties of the scheduled task by clicking "OK".
© Siemens AG 2020 All rights reserved

14. Due to the security option "Run whether user is logged on or not" in step 9, you
must enter the user account information assigned to perform this task and confirm
with "OK".

15. You can check this function in the "Task Scheduler Library" view.
The created tasks are listed here.
Select the task "UploadDataLog" and press the action "Run" under "Selected Item".

Recording and monitoring process data


Article ID: 64396156, V4.0, 06/2020 35
4 Commissioning the application example

The console application "UploadDataLog.exe" will now run every 5 minutes and
loads the DataLog file "DataLog.csv" (3rd argument) via the network adapter "1"
(1st argument) from the CPU's SIMATIC Memory Card with IP address
"192.168.0.2" (2nd argument) and saves it in the folder "c:\MyDataLogs" (4th
argument). The password for write-protected access to the CPU is "read" (5th
argument).
© Siemens AG 2020 All rights reserved

Recording and monitoring process data


Article ID: 64396156, V4.0, 06/2020 36
4 Commissioning the application example

4.3 Modifying the project


4.3.1 TMAIL_C

In order to send the email, the FB "TMAIL_C" needs the email address of the
recipient and the access credentials to your email account, as well as the certificate
of the email provider (sender).
The example project was tested with a Gmail (equivalent to a Google Mail)
account.
The presets and certificate import have already been completed for this.
Table 4-3
No. Action
1. Select your controller and open the OB "Main" in STEP 7 (TIA Portal).
© Siemens AG 2020 All rights reserved

2. Open the data structure "tmailcAlarm" in the DB "Data".


At the "toS" parameter, enter the email address of the recipient of the alarm email
as a string.
Example: ’[email protected]
Please note that a comma must be entered between addresses if there are more
than one.

Note: Of course, you can also enter the email address of the sender in order to
receive the email generated by the FB "TMAIL_C" yourself.

Recording and monitoring process data


Article ID: 64396156, V4.0, 06/2020 37
4 Commissioning the application example

No. Action
3. Open the data structure "tmailcAlarm > mailAddrParam" in the DB "Data".
Enter the access credentials for your email account as starting value:
Sending of emails has been tested with a Gmail/Google Mail account. The data
structure "mailAddrParam" contains the presets for this.
You must enter the following starting values if you have a Gmail or Google Mail
account:
• At the "UserName" parameter, enter the access name of the email account as
a string.
e.g.: ’[email protected]
• At the "PassWord" parameter, enter the password of the email account as a
string.
e.g.: ’Password’
Enter the following parameters under "From":
• "LocalPartPlusAtSign" - the local part of the sender email account address
including the @ character
e.g.: ’sender@’
• "FullQualifiedDomainName" - the name of the email account domain name
e.g.: ’googlemail.com’
© Siemens AG 2020 All rights reserved

Note: If the email provider is different, you will also need the following data:
• FQDN (Fully Qualified Domain Name) of the email server, "MailServerQDN"
(line 15)
• TCP port of the email server, "RemotePort" (line 21)
• Reference to the previously imported X.509 V3 (CA) certificate of the email
server "TLSServerCertRef" (line 24)
Additional information on downloading and importing the necessary certificates can
be found in chapter 2.2 of the application example "Sending Emails to SMTP
Servers with an S7 CPU" \17\.
4. Repeat steps 2 and 3 in the data structure "tmailcCsvTransfer" in the DB "Data" for
the DataLog transfer.

Recording and monitoring process data


Article ID: 64396156, V4.0, 06/2020 38
4 Commissioning the application example

No. Action
5. Make the necessary settings in your Gmail or Google Mail account:
• Enable IMAP
• Access through less secure apps
A detailed description of this topic can be found in chapter 2.2.2 of the application
example "Sending Emails to SMTP Servers with an S7 CPU" (\17\).

4.3.2 CPU properties

The CPU Ethernet address and time of day properties must be individually
customized. In addition, the web server must be enabled so that the DataLog files
can be loaded via remote access.

Table 4-4
No. Action
1. Select the controller and right-click to open the "Properties...".
© Siemens AG 2020 All rights reserved

2. • Under "PROFINET interface > Ethernet addresses > IP protocol", enable the
option "Use router".
• Enter the IP address of your VPN-capable router (on the controller side).
• Adjust the IP address and the subnet mask to match your router network.

Recording and monitoring process data


Article ID: 64396156, V4.0, 06/2020 39
4 Commissioning the application example

No. Action
3. • Under "PROFINET interface > Time synchronization", select the option "Enable
time synchronization via NTP server".
• Enter at least one IP address of your reachable NTP server.
Note: NTP requires that port 123 be enabled for the UDP networking protocol.
The IP address of the Deutsche Telekom AG, Darmstadt NTP server "ntp1.sda" is
already filled in this project.
The correct CPU system time is required for certificate comparison.

4. • Activate the web server.


• Activate the option "Allow access only via HTTPS".
© Siemens AG 2020 All rights reserved

• Under "User management", open the settings for the access level of the user
"Everyone" with the button.
The "Everyone" user does not need a password for web server access. If you wish
to secure access with a password, you must "<Add new user>", assign a password
and make the following settings for the access level.

Recording and monitoring process data


Article ID: 64396156, V4.0, 06/2020 40
4 Commissioning the application example

No. Action
5. Enable the settings:
"The user is authorized to..."
• ...read watch tables
• ...read files
Apply the settings with the button.
© Siemens AG 2020 All rights reserved

6. One function of the preconfigured password protection is to prevent unauthorized


persons from reading sensitive access data to the email account over an online
connection.
• Open "Access level" under "Protection & Security".
• Enable the access level "HMI access".
• Select the access level "Full access (no protection)".
• Open the password assignment with the button.

Recording and monitoring process data


Article ID: 64396156, V4.0, 06/2020 41
4 Commissioning the application example

No. Action
7.
• Enter the password "full", confirm it and apply the settings with the button.
• Repeat steps 6 and 7 for the access level "Read access" with the password
"read".

8. • Open the "Certificate manager" under "Protection & Security".


• Enable the function "Use global security settings for certificate manager".
• Scroll down to "Certificates of the partner devices".
• Here you can find the certificate of the email server that is being used (see
Table 4-3, no. 3, row 24).
© Siemens AG 2020 All rights reserved

You can use "Add new" for other previously imported certificates (see \17\ chapter
2.2).
9. • Under "Advanced configuration", open "DNS configuration".
• Enter the DNS server address (see Figure 4-1).

10.
Click the button to apply the CPU properties.

Recording and monitoring process data


Article ID: 64396156, V4.0, 06/2020 42
4 Commissioning the application example

4.3.3 Downloading the project

Before remotely accessing the S7-1x00, the CPU interface must be parameterized
according to specification (see Figure 4-1).
To do this, load the project to the CPU via direct connection on site, as described
below:
Table 4-5
No. Action
1. • Save the project.
• Select the program folder of the S7-1x00 and transfer the program to the
controller with "Online > Download and reset PLC program".

2. • Select "PN/IE" as the type of PG/PC interface.


• Select your LAN card as PG/PC interface.
© Siemens AG 2020 All rights reserved

• Select "Show all compatible devices".


• Start the search with the button.

3. • Select your CPU from the list of target devices.


• Press the "Load" button.

Recording and monitoring process data


Article ID: 64396156, V4.0, 06/2020 43
4 Commissioning the application example

No. Action
4. Confirm the "Load preview" by clicking the "Load" button.

5. • You may need to enter the password "full" for full access.
• Confirm the entry with "OK".
© Siemens AG 2020 All rights reserved

6. • Activate the option "Start module" in "Load results".


• Press the "Finish" button to complete the loading process.

Note Data logs are stored persistently ("non-volatile") in the load memory of the
controller, thus making them secured against power failure and program
changes.
You can delete the data logs as follows:
• With the "DataLogDelete" instruction (as in FB "DataLog1x00")
• Via the enabled function in the web server
• With the SIMATIC Automation Tool
• Via direct access to the SIMATIC Memory Card using a card reader
• Through online access to the SIMATIC Memory Card via TIA Portal:
Format the SIMATIC Memory Card and/or reset CPU to factory settings

Recording and monitoring process data


Article ID: 64396156, V4.0, 06/2020 44
4 Commissioning the application example

4.3.4 Changing the recorded data

If you modify the recorded data ("data") of the FB "DataLog1x00", they will only be
transferred to the CSV file after the data log file has successfully been generated
again with "DataLogCreate".
If you leave the name of the data log ("name") unchanged, the FB "DataLog1x00"
will try to write to the existing data log with the original data structure.
You can successfully re-generate the data log file by deleting the existing data
log(s) with the "delete" input.
Proceed as follows to do this:
Table 4-6
No. Action
1. • Open the data block "Data".
• Press the "Monitor all" button.
• Change the tag "delete" (here shown with the example "dataLogNewFile") to
TRUE by double-clicking.
© Siemens AG 2020 All rights reserved

2. The data logs ("NewFile" and "NewFile_1") are now deleted.


You can also check this using the web server:
https://192.168.0.2/Portal/Portal.mwsl?PriNav=DataLogs
• Press "Go offline".

Recording and monitoring process data


Article ID: 64396156, V4.0, 06/2020 45
4 Commissioning the application example

No. Action
3. • Open the structure "dataLogNewFile".
• Add a new tag to the "data" structure, for example.

4. • Open OB1 "Main".


• Open Network 7 by calling the FB "DataLog1x00" with the instance DB
"InstDataLogNewFile"
• Change the "HEADER" according to the modified recorded data.
Note:
The new tags to be recorded must have their values generated before the FB
"DataLog1x00" is called.
© Siemens AG 2020 All rights reserved

5. • Then download the modified project to the CPU (see chapter 4.3.3).
The modified data log will be re-generated at a positive edge at the "write" input
("Data".write).

Recording and monitoring process data


Article ID: 64396156, V4.0, 06/2020 46
4 Commissioning the application example

4.4 Internet browser settings (Google Chrome)


For secure access to the web server, the certificate of your S7-1x00 CPU must be
installed on the remote service PC as follows:
Table 4-7
No. Action
1. • Start Google Chrome.
• Enter the secured connection to the CPU's web server:
here: https://192.168.0.2
If a "Your connection is not private" message appears, click "Advanced".
© Siemens AG 2020 All rights reserved

2. The "advanced information" will be displayed.


• Click "Proceed to 192.168.0.x (unsafe)".

3. The intro for the web server will be shown.


• Click "download certificate".
The certificate "MiniWebCA_Cer.crt" will be downloaded.
• Open the dialog and click "Open".

Recording and monitoring process data


Article ID: 64396156, V4.0, 06/2020 47
4 Commissioning the application example

No. Action
4. The certificate is shown.
• Click the "Install certificate..." to start the Certificate Import Wizard.

5. • Select "Local Machine" as save location and press "Next" to proceed.


© Siemens AG 2020 All rights reserved

6. • Approve the changes with "Yes".

Recording and monitoring process data


Article ID: 64396156, V4.0, 06/2020 48
4 Commissioning the application example

No. Action
7. • Select "Place all certificates in the following store".
• Click the "Browse" button.
• Select "Trusted Root Certification Authorities" as certificate store.
• Click "OK" to confirm your selection, then press "Next".
© Siemens AG 2020 All rights reserved

8. • Click "Finish" to import the certificate.

9. • Click "OK" to close all windows once the certificate has successfully imported.

You must then restart Google Chrome so that the certificate will be recognized
when the web server is retrieved.

Recording and monitoring process data


Article ID: 64396156, V4.0, 06/2020 49
5 Operating the application example

5 Operating the application example


5.1 Overview
The functions of the application example are divided between
• Remote maintenance
• Manual download of the DataLog file
• Automatic download of the DataLog file
• Alarm generation by sending an email
• Data log sending as email attachment

5.2 Remote maintenance


The VPN tunnel from the PC service must be established in order to gain access to
the controller.
Therefore, you can communicate with the controller exactly as you would with a
direct LAN connection via STEP 7 (requirement: project available).
The example of an online connection via the watch table demonstrates access to
the CPU via STEP 7.
© Siemens AG 2020 All rights reserved

Table 5-1
No. Action
1. Establish the VPN connection.

2. Enter your connection data and establish the connection.

3. The connection setup is shown.

Recording and monitoring process data


Article ID: 64396156, V4.0, 06/2020 50
5 Operating the application example

No. Action
4. • Open the watch table "WatchTable" in STEP 7 (TIA Portal).

5. • Click the "Monitor all" button.


The watch table "WatchTable" shows the most important supply parameters of the
application example:
• Temperature display ("//Temperature")
• FB "DataLog1x00" with IDB "InstDataLogSameFile" ("// DataLog - SameFile")
• FB "TMAIL_C" with IDB "InstTmailcAlarm" ("// TMAIL_C - Alarm")
© Siemens AG 2020 All rights reserved

• FB "DataLog1x00" with IDB "InstDataLogNewFile" ("// DataLog - NewFile")


• FB "TMAIL_C" with IDB "InstTmailcCsvTransfer" ("// TMAIL_C - CsvTransfer")

Recording and monitoring process data


Article ID: 64396156, V4.0, 06/2020 51
5 Operating the application example

5.3 Manual upload of the DataLog file


Manual uploading of the DataLog file through Google Chrome from the service PC
will be demonstrated.
Table 5-2
No. Action
1. • Start Internet Explorer.
• For the address, enter the IP address of the CPU:
here: https://192.168.0.2
• Click on "ENTER".

Note: If you then receive a message "There is a problem with this website's security
certificate.", then download the Siemens security certificate as described in
chapter 4.4.
© Siemens AG 2020 All rights reserved

2. Open "Data Logs".

3. You will then see a list of all existing DataLog files with file size and time stamp of
most recent access.
• Click on the name of the file you want (here: "DataLog.csv").

Recording and monitoring process data


Article ID: 64396156, V4.0, 06/2020 52
5 Operating the application example

No. Action
4. Using the display window, you have the ability to open the CSV file or save it.
• Click "Open" (2x).

5. Thanks to the region settings made earlier (see chapter 4.2.1), the CSV file will be
shown in Microsoft Excel properly divided into columns for
• Data record number "Record"
© Siemens AG 2020 All rights reserved

• Date "Date"
• Time stamp "UTC Time"
• Temperature "Temperature"
.

5.4 Automatic upload of the DataLog file


The automatic upload is demonstrated with the Windows Task Scheduler on the
local PC station (see section 4.2.2). Here the file "UploadDataLog.exe" is run every
5 minutes and loads the file "DataLog.csv" from the flash memory (SMC) of the
CPU according to the specified arguments and saves it on the PG in the folder
"C:\MyDataLogs". In the process, "UploadDataLog.exe" accesses the API of the
SIMATIC Automation Tool V3.1.4.

Recording and monitoring process data


Article ID: 64396156, V4.0, 06/2020 53
5 Operating the application example

Table 5-3
No. Action
1. • Open the Windows Task Scheduler program.
2. The task "UploadDataLog" task created in chapter 4.2.2 is listed in the "Task
Scheduler Library" under "Task Scheduler (Local)".
• If this task is disabled (see column "Status"), select the task and enable it via
"Actions > Selected item".

3. When the status indicates "Ready", the task is performed every 5 minutes.
The security option "Run whether user is logged on or not" (Table 4-2 step 9)
© Siemens AG 2020 All rights reserved

executes the task in the background without a console window appearing.

4. • Open the destination folder "C:\MyDataLogs".


In this case the loaded file "DataLog.csv" is saved every five minutes.
Newly saved files are incremented with name extension.
In this way, no data will be overwritten.

Recording and monitoring process data


Article ID: 64396156, V4.0, 06/2020 54
5 Operating the application example

5.5 Alarm generation by sending an email


The alarms are generated by the FB "TMAIL_C" (with the instance DB
"InstTmailcAlarm").
When the maximum cooling temperature of -20 °C is exceeded, the S7-1x00
functions as an email client and sends a send request to the email provider over a
secure connection; the email provider then carries out the send request.
Table 5-4
No. Action
1. Every minute, the simulated cooling temperature exceeds the maximum
specification of -20 °C and issues the command via the "TMAIL_C" block to send an
email to the pre-defined recipient.
• Open the inbox of the recipient to check whether the email has been received.
© Siemens AG 2020 All rights reserved

2. If the alarm email was not successfully received, please check the last status
messages of the "TMAIL_C" block (with the instance DB "InstTmailcAlarm").
• To do this, open the watch table "WatchTable".
Under "TMAIL_C - Alarm" you will find the time stamp for the last successful
("done") or faulty ("error") runs of the FB "TMAIL_C", as well as the returned status
("status") and SFB_STATUS ("sfbStatus") in the event of an error.
Refer to the description of the "TMAIL_C" block for an interpretation (\6\).

Recording and monitoring process data


Article ID: 64396156, V4.0, 06/2020 55
5 Operating the application example

5.6 Data log sending as email attachment


The data log is also sent by the FB "TMAIL_C" (with the instance DB
"InstTmailcCsvTransfer") as an attachment via the parameter "ATTACHMENT".
Once the maximum number of temperature logging data records has been reached
(through the FB "DataLog1x00" with the instance DB "InstDataLogNewFile"), the
current CSV file will be sent to a predefined recipient as an email attachment.
Table 5-5
No. Action
1. Depending on the internet connection and the size of the data log, the email may
send with some delay. For this reason, the data log sending is shown using the
example of data logging with new generation in the event of an overflow. Thus,
when the maximum number of data records is reached, the current data log will be
sent while the newly-created data log can be written to. The data logs "NewFile"
and "NewFile_1" are sent in alternating order as an attachment via the FB
"TMAIL_C".
• Open the inbox of the recipient to check whether the email has been received.
© Siemens AG 2020 All rights reserved

2. • Open the email attachment.


The data log has been fully received (without overwritten data records).

Recording and monitoring process data


Article ID: 64396156, V4.0, 06/2020 56
6 Appendix

6 Appendix
6.1 Service and support
Industry Online Support
Do you have any questions or need assistance?
Siemens Industry Online Support offers round the clock access to our entire
service and support know-how and portfolio.
The Industry Online Support is the central address for information about our
products, solutions and services.
Product information, manuals, downloads, FAQs, application examples and videos
– all information is accessible with just a few mouse clicks:
support.industry.siemens.com

Technical Support
The Technical Support of Siemens Industry provides you fast and competent
support regarding all technical queries with numerous tailor-made offers
– ranging from basic support to individual support contracts. Please send queries
to Technical Support via Web form:
www.siemens.com/industry/supportrequest
© Siemens AG 2020 All rights reserved

SITRAIN – Digital Industry Academy


We support you with our globally available training courses for industry with
practical experience, innovative learning methods and a concept that’s tailored to
the customer’s specific needs.
For more information on our offered trainings and courses, as well as their
locations and dates, refer to our web page:
www.siemens.com/sitrain

Service offer
Our range of services includes the following:
• Plant data services
• Spare parts services
• Repair services
• On-site and maintenance services
• Retrofitting and modernization services
• Service programs and contracts
You can find detailed information on our range of services in the service catalog
web page:
support.industry.siemens.com/cs/sc

Industry Online Support app


You will receive optimum support wherever you are with the "Siemens Industry
Online Support" app. The app is available for iOS and Android:
support.industry.siemens.com/cs/ww/en/sc/2067

Recording and monitoring process data


Article ID: 64396156, V4.0, 06/2020 57
6 Appendix

6.2 Links and literature


Table 6-1
No. Subject
\1\ Siemens Industry Online Support
https://support.industry.siemens.com
\2\ Link to the article page of the application example
https://support.industry.siemens.com/cs/ww/en/view/64396156
\3\ System manual, "SIMATIC S7-1200 Automation system"
https://support.industry.siemens.com/cs/ww/en/view/109772940
\4\ Where do you find the latest operating system updates (firmware) for SIMATIC S7-
1200 controllers?
https://support.industry.siemens.com/cs/ww/en/view/77430184
\5\ Firmware update S7-1500 CPUs incl. Displays and ET 200 CPUs (ET 200SP, ET
200pro)
https://support.industry.siemens.com/cs/ww/en/view/109478459
\6\ SIMATIC STEP 7 Basic/Professional V16 and SIMATIC WinCC V16
https://support.industry.siemens.com/cs/ww/en/view/109773506
\7\ TIA Selection Tool – quick, easy, smart
https://support.industry.siemens.com/cs/ww/en/view/109767888
\8\ Updates for STEP 7 V16, S7-PLCSIM V16 and WinCC V16
© Siemens AG 2020 All rights reserved

https://support.industry.siemens.com/cs/ww/en/view/109775861
\10\ Overview document: Secure remote access with VPN
https://support.industry.siemens.com/cs/ww/en/view/26662448
\11\ Why is the "Certificate error" message shown in the address line when downloading
the web page of an S7-300/400/1200 CPU over "https://..."?
https://support.industry.siemens.com/cs/ww/en/view/63314183
\12\ Automated loading and archiving of the CPU service data by means of the SIMATIC
Automation Tool via the Application Programming Interface (API)
https://support.industry.siemens.com/cs/ww/en/view/109760829
\13\ How do you calculate the service life of a memory card of the S7-1500/S7-1200 and
ET 200?
https://support.industry.siemens.com/cs/ww/en/view/109482591
\14\ Sending and Receiving SMS Messages via a SCALANCE M Router
https://support.industry.siemens.com/cs/ww/en/view/54361177
\15\ Signaling and Switching via SMS with S7-1200 and CP 1242-7 GPRS V2 (Set 32)
https://support.industry.siemens.com/cs/ww/en/view/58638283
\16\ SIMATIC Automation Tool - the tool for support during commissioning, service and
maintenance of SIMATIC devices
https://support.industry.siemens.com/cs/ww/en/view/98161300
\17\ Sending Emails to SMTP Servers with an S7 CPU
https://support.industry.siemens.com/cs/ww/en/view/46817803
\18\ Library with general functions (LGF) for SIMATIC STEP 7 (TIA Portal) and SIMATIC
S7-1200 / S7-1500
https://support.industry.siemens.com/cs/ww/en/view/109479728
\19\ SIMATIC Automation Tool V3.1 SP4 User manual
https://support.industry.siemens.com/cs/ww/en/view/109774222

Recording and monitoring process data


Article ID: 64396156, V4.0, 06/2020 58
6 Appendix

6.3 Change documentation


Table 6-2
Version Date Change
V1.0 01/2013 First version
V2.0 10/2017 Updated to STEP 7 V14
V2.0.1 12/2017 Addition to the chapter
Changing the recorded data
V3.0 07/2019 Update, TIA Portal V15.1
V4.0 06/2020 Update, TIA Portal V16
© Siemens AG 2020 All rights reserved

Recording and monitoring process data


Article ID: 64396156, V4.0, 06/2020 59

You might also like