WINCC Runtime Professional S7-Graph Overview and PLC Code Viewer
WINCC Runtime Professional S7-Graph Overview and PLC Code Viewer
https://support.industry.siemens.com/cs/ww/en/109477133
Warranty and Liability
We do not accept any liability for the information contained in this document.
Any claims against us – based on whatever legal reason – resulting from the use of
the examples, information, programs, engineering and performance data etc.,
described in this Application Example shall be excluded. Such an exclusion shall
not apply in the case of mandatory liability, e.g. under the German Product Liability
Act (“Produkthaftungsgesetz”), in case of intent, gross negligence, or injury of life,
body or health, guarantee for the quality of a product, fraudulent concealment of a
deficiency or breach of fundamental contractual obligations (“wesentliche
Siemens AG 2015 All rights reserved
Security Siemens provides products and solutions with industrial security functions that
informa- support the secure operation of plants, solutions, machines, equipment and/or
tion networks. They are important components in a holistic industrial security
concept. With this in mind, Siemens’ products and solutions undergo continuous
development. Siemens recommends strongly that you regularly check for
product updates.
For the secure operation of Siemens products and solutions, it is necessary to
take suitable preventive action (e.g. cell protection concept) and integrate each
component into a holistic, state-of-the-art industrial security concept. Third-party
products that may be in use should also be considered. For more information
about industrial security, visit http://www.siemens.com/industrialsecurity.
To stay informed about product updates as they occur, sign up for a product-
specific newsletter. For more information, visit
https://support.industry.siemens.com.
Table of Contents
Warranty and Liability ................................................................................................. 2
1 Task ..................................................................................................................... 4
2 Solution............................................................................................................... 5
2.1 Setup .................................................................................................... 5
2.2 Hardware and software components ................................................... 6
2.2.1 Validity .................................................................................................. 6
2.2.2 Components used ................................................................................ 6
3 Mode of Operation ............................................................................................. 7
3.1 Diagnostics of faults with PLC Code Viewer and STEP 7 ................... 7
4 Basics ................................................................................................................. 8
4.1 Using function libraries ......................................................................... 8
5 Configuration and Settings............................................................................... 9
5.1 STEP 7 program ................................................................................... 9
5.2 HMI object configuration..................................................................... 10
5.3 Configuring the S7 GRAPH overview ................................................ 11
5.4 Configuring C scripts .......................................................................... 13
5.5 Display in the PLC Code Viewer ........................................................ 14
Siemens AG 2015 All rights reserved
1 Task
Description of the automation task
During operation, faults can occur in the production plant. To diagnose and rectify
them as quickly as possible, you access specific blocks of the CPU with your
SCADA system. You can open and view it directly from runtime or in the
engineering system.
2 Solution
2.1 Setup
Schematic layout
Figure 2-1
PROFINET IE
Siemens AG 2015 All rights reserved
Description
The PLC Code Viewer and the TIA Engineering Framework can be used for quick
and easy diagnostics. The code of individual blocks can be displayed in the
programming languages LAD, FBD and S7-Graph with various C-Script functions
in the HMI to enable you to diagnose faults in the control center.
For further information on system diagnostics with S7-1500 and TIA Portal, refer to
the following entry ID: 68011497.
Assumed knowledge
Software components
Table 2-1
Component Qty Article number Note
WinCC Runtime 1 6AV2105-....3-0
Professional V13
SP1
WinCC Engineering 1 6AV210-....3-0
V13 SP1
Siemens AG 2015 All rights reserved
STEP 7 1 6ES7822-1..03
Professional V13
SP1
Table 2-2
Component Note
109477133_PLC_Code_Viewer_Doku_en.pdf This document
109477133_PLC_Code_Viewer_Code.zip Project
3 Mode of Operation
3.1 Diagnostics of faults with PLC Code Viewer and
STEP 7
Figure 3-1
PROFINET IE
Siemens AG 2015 All rights reserved
Note You can find the currently supported blocks in the TIA Portal under Visualize
processes Creating pictures Display and control objects Objects PLC
Code Viewer.
4 Basics
4.1 Using function libraries
Every WinCC application (user administration, recipes, messages, etc.) provides its
own API function which is stored in one or several DLLs. A DLL (Dynamic Link
Library) is a function library which loads dynamically. The functions available in a
DLL are stored in the respective header file.
#pragma code("kopapi.dll")
#include "kopapi.h"
#pragma code()
Siemens AG 2015 All rights reserved
S7_Graph InstanceDB_FB1
Simu_Zylin1 InstanceDB_FB2
FB2 DB2
Simu_Zylin2 InstanceDB_FB6
FB6 DB8
Siemens AG 2015 All rights reserved
UDT_DB
DB5
Simu_Error
FC1
Table 5-1
No. Description
1. OB1
The blocks listed in the program structure are called with OB1.
2. FB1
FB1 contains the S7-GRAPH sequence for the embossing machine.
3. FB2
FB2 contains the program for simulating pressure cylinder 1.
4. FB6
FB6 contains the program for simulating pressure cylinder 2.
5. DB5
DB5 contains the UDT data structure.
6. FC1
FC1 monitors pressure cylinder faults.
7. DB1, DB2, DB8
Instance data blocks for the assigned function blocks.
- OpenViewerIECPLByFCCall()
- OpenViewerIECPByAssignment()
2. Script diagnostics
3. S7-GRAPH overview
This object serves to display the current program status for selected steps
in the PLC sequence chain. Faults during program run are displayed
directly in the respective step.
Note The PLC Code Viewer as well as the S7-GRAPH overview provide a fault event.
With this event, you can react to faults with VB script or C-Script.
Table 5-3
No. Action
1. Create an S7 GRAPH block with sequence chain and open it.
2. Open the Edit menu and activate the “Internal parameters visible/accessible from
HNMI” checkbox.
Siemens AG 2015 All rights reserved
3. Open the HMI screen in which you have inserted the S7-GRAPH overview..
4. In the controller properties, select a variable of the S7 GRAPH block as “Assigned
S7-GraphDB tag”.
Note With the object PLC Code Viewer, you can call up a step from a sequence chain
and display it. For this, configure a C-Script for a click event and add the function
OpenViewerS7GraphByBlock(). Further information on the
OpenViewerS7GraphByBlock() function is available in chapter 5.5.4.
Note With a VB script, you can change the displayed step sequence in the S7-GRAPH
overview during runtime.
- OpenTIAPortalIECPLByAssignment
- OpenTIAPortalIECPLByCall
- OpenTIAPortalProject
- OpenTIAPortalS7GraphByBlock
- OpenViewerIECPLByAssignment
- OpenViewerIECPLByCall
- OpenViewerIECPLByFCCall
- OpenViewerS7GraphByBlock
Siemens AG 2015 All rights reserved
2. Open an HMI screen and create 8 buttons for calling up the scripts.
3. Call the appropriate C function at the “Click” event of the respective button.
Fixed parameters
Table 5-5
Parameter Function
dwFlags Bit field where the individual values are connected with OR.
DwFlags should be 0 as a default.
Siemens AG 2015 All rights reserved
IpszCpuName S7-CPU name. The name is identical with the station name
that is displayed in the TIA Portal project navigation.
Parameter Function
IpdmError Indicator for the data of the extended error message in the
CMN_ERROR structure. In case of an error, the system will
write error information in this structure.
Structure layout
dwError1 … dwError5
Contains information about what error event has occurred.
szErrorText
Buffer for text description of the error cause.
Siemens AG 2015 All rights reserved
Description
This function shows the pre-connection of a network input of a standard block in
the PLC Code Viewer for the PLC languages LAD and FBD considering the UDT
instance.
Declaration
The following parameters must be added in addition to the fixed parameters in
chapter 5.5.
Table 5-6
Parameter Function
IpszContainingBlock Name of the block to be opened and displayed or name of the
instance of an FB.
The following can be used as names:
- Name of a single instance DB
- Name of a multi instance in an instance DB
- Name of an FC
IpszCalledBlock Name of the local or global instance called up in the code
Siemens AG 2015 All rights reserved
#pragma code("kopapi.dll")
#include "kopapi.h"
#pragma code()
BOOL result;
CMN_ERROR error;
DWORD dwFlags = 0;
char* serverPrefix = "";
char* screenName = "Bild_1";
char* objectName = "PLCCodeAnzeige";
char* cpuName = "PLC_1";
char* containingBlock = "Simu_Zylin1";
if(!result)
{
printf("OpenViewerIECPLByFCCall failed: err1=%ld, err2=%ld, ""
err3=%ld, err4=%ld, err5=%ld, text=\"%s\"\r\n", result,
error.dwError1, error.dwError2, error.dwError3, error.dwError4,
error.dwError5, error.szErrorText);
}
Figure 5-2
Siemens AG 2015 All rights reserved
Description
This function shows the pre-connection of a network input of a standard block in
the PLC Code Viewer in the PLC languages LAD and FBD.
Declaration
The following parameters must be added in addition to the fixed parameters in
chapter 5.5.
Table 5-7
Parameter Function
IpszContainingBlock Name of the block to be opened and displayed or name of the
instance of an FB.
The following can be used as names:
- Name of a single instance DB
- Name of a multi instance in an instance DB
- Name of an FC
IpszCalledBlock Name of the local or global instance called up in the code
block relating to IpszContainingBlock.
Siemens AG 2015 All rights reserved
This example describes how to display the pre-connection of a UDT instance and
the “air cylinder on” input pin within the function block “Simu_Zylin1”.
#pragma code("kopapi.dll")
#include "kopapi.h"
#pragma code()
BOOL result;
CMN_ERROR error;
DWORD dwFlags = 0;
char* serverPrefix = "";
char* screenName = "Bild_1";
char* objectName = "PLCCodeAnzeige";
char* cpuName = "PLC_1";
char* containingBlock = "Simu_Zylin1";
char* calledBlock = "Simu_Zylin2_DB";
char* pinName = "air cylinder on";
if(!result)
{
printf("OpenViewerIECPLByCall failed: err1=%ld, err2=%ld, err3=%ld,
err4=%ld, err5=%ld, text=\"%s\"\r\n", result, error.dwError1,
error.dwError2, error.dwError3, error.dwError4, error.dwError5,
error.szErrorText);
}
Figure 5-3
Siemens AG 2015 All rights reserved
Description
This function shows the assignment of an operand and its pre-connection in the
PLC Code Viewer in the PLC languages LAD and FBD.
Declaration
The following parameters must be added in addition to the fixed parameters in
chapter 5.5.
Table 5-8
Parameter Function
IpszContainingBlock Name of the block to be opened and displayed or name of the
instance of an FB.
The following can be used as names:
- Name of a single instance DB
- Name of a multi instance in an instance DB
- Name of an FC
IpszOperand Name of a local or global operand that is used for assignment.
Siemens AG 2015 All rights reserved
This example describes how to display the “Start” operand within the function block
“Simu_Zylin1”.
#pragma code("kopapi.dll")
#include "kopapi.h"
#pragma code()
BOOL result;
CMN_ERROR error;
DWORD dwFlags = 0;
char* serverPrefix = "";
char* screenName = "Bild_1";
char* objectName = "PLCCodeAnzeige";
char* cpuName = "PLC_1";
char* containingBlock = "Simu_Zylin1";
char* operand = "Start";
if(!result)
{
printf("OpenViewerIECPLByAssignment failed: err1=%ld, err2=%ld,
err3=%ld, err4=%ld, err5=%ld, text=\"%s\"\r\n", result,
Figure 5-4
Siemens AG 2015 All rights reserved
Description
This function displays a called up step from a sequence chain in the PLC language
S7-GRAPH in the PLC Code Viewer.
Declaration
The following parameters must be added in addition to the fixed parameters in
chapter 5.5.
Table 5-9
Parameter Function
IpszBlock Instance name of the S7-GRAPH block to be displayed.
dwStepNumber Number of the step to be displayed. With dwStepNumber = 0,
the active step is searched automatically.
#pragma code("kopapi.dll")
#include "kopapi.h"
#pragma code()
BOOL result;
CMN_ERROR error;
DWORD dwFlags = 0;
char* serverPrefix = "";
char* screenName = "Bild_1";
char* objectName = "PLCCodeAnzeige";
char* cpuName = "PLC_1";
char* instanceDBName = "S7_Graph_DB";
DWORD stepNumber = 0;
if(!result)
{
printf("OpenViewerS7GraphByBlock failed: err1=%ld, err2=%ld,
err3=%ld, err4=%ld, err5=%ld, text=\"%s\"\r\n", result,
error.dwError1, error.dwError2, error.dwError3, error.dwError4,
error.dwError5, error.szErrorText);
}
Figure 5-5
Siemens AG 2015 All rights reserved
Fixed parameters
Table 5-10
Parameter Function
dwFlags Bit field where the individual values are connected with OR.
DwFlags should be 0 as a default.
dwFlags. For example, you can set that after opening the
block, TIA Portal will not go into online mode.
Example:
“C:\\Users\\WinCC\\Documents\\...\\PLC Code Viewer.ap13“
Structure layout
dwError1 … dwError5
Parameter Function
Contains information about what error event has occurred.
szErrorText
Buffer for text description of the error cause.
Siemens AG 2015 All rights reserved
Description
This function allows you to start TIA Portal and open a project.
This example describes how to open TIA Portal from Runtime Professional.
#pragma code("KOPAPI.dll")
#include "kopapi.h"
#pragma code()
BOOL result;
CMN_ERROR error;
DWORD dwFlags = 0;
char* TiaPortalProject = " C:\\Users\\WinCC\\PLCCodeAnzeige.ap13";
char* ErrorTag = "Fehler";
if(!result)
{
printf("OpenTIAPortalProject failed: err1=%ld, err2=%ld, ""
err3=%ld, err4=%ld, err5=%ld, text=\"%s\"\r\n", result,
error.dwError1, error.dwError2, error.dwError3, error.dwError4,
error.dwError5, error.szErrorText);
}
Figure 5-6
Description
This function is used for the languages LAD and FBD and shows the pre-
connection of a network input of a standard block.
Declaration
The following parameters must be added in addition to the fixed parameters in
chapter 5.6.
Table 5-11
Parameter Function
IpszCpuName S7-CPU name. The name is identical with the station name
that is displayed in the TIA Portal project navigation.
IpszContainingBlock Name of the block to be opened and displayed or name of the
instance of an FB.
The following can be used as names:
- Name of a single instance DB
- Name of a multi instance in an instance DB
- Name of an FC or OB
Siemens AG 2015 All rights reserved
This example describes how to display the pre-connection of the “Error1” input pin
in TIA Portal from the “Simu_Error“ function.
#pragma code("KOPAPI.dll")
#include "kopapi.h"
#pragma code()
BOOL result;
CMN_ERROR error;
DWORD dwFlags = 0;
char* TiaPortalProject = " C:\\Users\\WinCC\\PLCCodeAnzeige.ap13";
char* CpuName = "PLC_1";
char* ContainingBlock = "Main";
char* CalledBlock = "Simu_Error";
char* Pin = "Error1";
char* pErrorTag = "Error";
Figure 5-1
Siemens AG 2015 All rights reserved
Description
This function is used for the languages LAD and FBD and shows the assignment to
an operand and its pre-connection.
Declaration
The following parameters must be added in addition to the fixed parameters in
chapter 5.6.
Table 5-12
Parameter Function
IpszCpuName S7-CPU name. The name is identical with the station name
that is displayed in the TIA Portal project navigation.
IpszContainingBlock Name of the block to be opened and displayed or name of the
instance of an FB.
The following can be used as names:
- Name of a single instance DB
- Name of a multi instance in an instance DB
- Name of an FC or OB
Siemens AG 2015 All rights reserved
This example describes how to display the pre-connection of the “Start” operand in
TIA Portal from the “Main” organization block.
#pragma code("kopapi.dll")
#include "kopapi.h"
#pragma code()
BOOL result;
CMN_ERROR error;
DWORD dwFlags = 0;
char* TiaPortalProject = " C:\\Users\\WinCC\\PLCCodeAnzeige.ap13";
char* CpuName = "PLC_1";
char* ContainingBlock = "Main";
char* Operand = " Start";
char* ErrorTag = "Error";
Figure 5-7
Siemens AG 2015 All rights reserved
Description
This function is used for program blocks in S7-GRAPH and shows a step in a
sequence chain.
Declaration
Table 5-13
Parameter Function
IpszCpuName S7-CPU name. The name is identical with the station name
that is displayed in the TIA Portal project navigation.
IpszBlock Instance name of the S7-GRAPH block to be displayed.
dwStepNumber Number of the step to be displayed. With dwStepNumber = 0,
the active step is activated automatically.
Siemens AG 2015 All rights reserved
This example describes how to display the S7-GRAPH step sequence “S7_Graph”
in TIA Portal.
#pragma code("KOPAPI.dll")
#include "kopapi.h"
#pragma code()
BOOL result;
CMN_ERROR error;
DWORD dwFlags = 0;
char* TiaPortalProject = " C:\\Users\\WinCC\\PLCCodeAnzeige.ap13";
char* CpuName = "PLC_1";
char* Block = "S7_Graph_DB"
DWORD stepNumber = 0;
char* ErrorTag = "Error";
Figure 5-8
Siemens AG 2015 All rights reserved
2
3
Table 6-2
No. Action
1. Press the round button for activating the step sequence for the simulated
embossing machine.
2. Enter the path of the TIA Portal project in the I/O field. The path is required for
the following functions: OpenTIAPortalProject, OpenTIAPortalIECPLByCall,
OpenTIAPortalIECPLbyAssignment and OpenTIAPortalS7GraphByBlock.
3. Press the buttons to call up the commands for the PLC Code Viewer and TIA
Portal.
Siemens AG 2015 All rights reserved
8 History
Table 8-1
Version Date Modifications
V1.0 07/2015 First version
V2.0 11/2015 Update example program
Siemens AG 2015 All rights reserved