OPC UA Methods For The SIMATIC S7-1500 OPC UA Server
OPC UA Methods For The SIMATIC S7-1500 OPC UA Server
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 2019 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.
Table of contents
Legal information ..................................................................................................... 2
1 Introduction .................................................................................................... 4
1.1 Overview ........................................................................................... 4
1.2 Mode of operation.............................................................................. 5
1.3 Components used ............................................................................. 5
2 Engineering .................................................................................................... 6
2.1 Creation of OPC UA methods ............................................................ 6
2.1.1 Explanation of the system function blocks .......................................... 6
2.1.2 Preparation ........................................................................................ 8
2.1.3 Creation of the basic framework......................................................... 8
2.1.4 Programming the functionality .......................................................... 11
2.1.5 Call in the user program................................................................... 13
2.2 Explanations to the example project................................................. 14
2.2.1 Call structure ................................................................................... 14
2.2.2 Commissioning the example project................................................. 15
2.2.3 Operation of the example project ..................................................... 16
3 Useful information ........................................................................................ 20
3.1 Allowed data types as interface parameters ..................................... 20
3.2 OPC UA Status Codes..................................................................... 20
© Siemens AG 2019 All rights reserved
4 Appendix....................................................................................................... 21
4.1 Service and Support ........................................................................ 21
4.2 Links and Literature ......................................................................... 22
4.3 Change documentation .................................................................... 22
1 Introduction
1.1 Overview
For standardized, communication of an S7 control system that applies to all
platforms and manufacturers, Siemens offers you the communication protocol
OPC UA.
As of firmware version V2.5 and TIA Portal V15, the SIMATIC S7-1500 control
system can also offer OPC UA methods for the clients via its integrated OPC UA
server. With this addition to the functions, you not only have the option of reading
or writing OPC UA variables of the control system, you can now also start complex
functional sequences via OPC UA. This enables almost complete M2M
communication via OPC UA, for the networking of plants or for the control of plants
from an ERP / MES level.
In this application example, we explain how to program an S7 function block so that
it can be called up as an OPC UA method on the server of an S7-1500.
Figure 1-1 Pictorial schematic
S7-1500
© Siemens AG 2019 All rights reserved
OPC UA method
This application example was created with the following hardware and software
components:
Table 1-1
Component Numbe Article number Note
r
SIMATIC S7-1500 1 6ES7 513-1AL01-0AB0 Firmware V2.5 or later
CPU 1513-1 PN
STEP 7 Professional 1 6ES7822-1AA05-0YA5 TIA Portal V15.1 or later
2 Engineering
2.1 Creation of OPC UA methods
In this chapter, we explain the procedure and basis for creating an OPC UA
method. The system function blocks "OPC_UA_ServerMethodPre" and
"OPC_UA_ServerMethodPost", which implement the OPC UA method, are the
central component of an OPC UA method.
The creation of OPC UA methods requires calling the system function blocks
"OPC_UA_ServerMethodPre" and "OPC_UA_ServerMethodPost". Call these
system functions in an S7 function block to implement the functionality of the S7
function block as an OPC UA method. You will find the system function blocks in
the instruction list of the TIA Portal under "Communication> OPC UA> OPC UA
Server" ("Communication> OPC UA> OPC UA server").
Functional sequence
When calling an OPC UA method, the input parameters are transferred to the
system function "OPC_UA_ServerMethodPre". The system function then provides
these in the user program. Additionally, an interface parameter on the function
© Siemens AG 2019 All rights reserved
block indicates that the method was called by an OPC UA client. Run your custom
function code after the parameter is set.
After processing the function code, you must transfer the output parameters and
the status code to the "OPC_UA_ServerMethodPost" system function and also set
an interface parameter to indicate to the function that the code has been executed.
This system function then transmits the output parameters and the status code to
the OPC UA client.
Figure 2-1 Sequence of functions
Call
Individual
OPC UA method
Function code
Table 2-1
Name Data Description
type
UAMethod_ Version Input parameters of the method; Transferred by the
InParameters client.
Done Bool True if the system function was called up successfully.
Busy Bool True if the system function is in progress.
Error Bool True if an error occurred while calling up the system
function.
Status DWord Cause of the error, see TIA Help ("F1").
© Siemens AG 2019 All rights reserved
Table 2-2
Name Data Description
type
UAMethod_Result DWord OPC UA status code; Will be transfered to the client.
UAMethod_Finished Bool Set to True when function code is complete; The
method is hereby terminated.
UAMethod_Out Version Output parameter of the method; transfered to the
parameters client.
Done Bool True if the system function was called up successfully.
Busy Bool True if the system function is in progress.
Error Bool True if an error occurred while calling up the system
function.
Status Status Cause of the error, see TIA Help ("F1").
2.1.2 Preparation
You must make the following preparations to create a functional OPC UA method
for a SIMATIC S7-1500:
• Create a STEP 7 V15.1 project.
• Configure a SIMATIC S7-1500 with firmware 2.5 or higher.
• Activate the OPC UA server of the S7-1500 so that the methods can be
accessed via OPC UA. For instructions, see the appendix at \4\.
• Create a block of the "function block" type. The programming language used in
the module is irrelevant. This example uses the scripting language "SCL".
• (Optional) Import the XML file "OpcUaMethodStatusCodes.xml" provided with
this entry to use standardized OPC UA status codes. Instructions on this can
be found in the chapter 3.2 OPC UA Status Codes.
To create OPC UA methods, always create a basic framework in the module that is
mandatory for the function of the method.
Perform steps 1 through 4 of the following procedure for each OPC UA method.
Follow steps 5 through 8 only if your method requires input or output parameters.
Proceed as follows:
© Siemens AG 2019 All rights reserved
4. Assign suitable variables to the block interfaces of the pre- and post-function.
© Siemens AG 2019 All rights reserved
5. To define input parameters for the OPC UA method, create a variable with the
name "UAMethod_InParameters" of the data type "Struct" or UDT in the static
area of the block. Within the structure you define the individual transfer
parameters (example: "myInt1" and "myInt2" of the data type "Int").
Note The name of the variable must be "UAMethod_InParameters" to display the input
parameters of the method.
7. To define output parameters for the OPC UA method, create a variable with
the name "UAMethod_OutParameters" of the data type "Struct" or UDT in the
static area of the block. Within the structure, you define the individual transfer
parameters (example: "myIntResult" of the data type "DInt").
9. Make sure that the "Accessible from HMI / OPC UA" check boxes are set in the
declaration of the pre- and post-function as well as in the input and output
parameters.
The following instructions explain the basic procedure for programming the function
of the OPC UA method:
1. Create a basic framework as described in chapter 2.1.3 Creation of the basic
framework.
2. Create an IF query on the variable of the "UAMethod_Called" interface of the
pre-function. If the function is to be run through for several cycles, define the
variable as "Static". If processing is possible in just one cycle, define the
variable as "Temp". Program the functionality of the method within this IF loop
so that the code is only executed when the method is called by a client.
© Siemens AG 2019 All rights reserved
3. Program the functionality. In this example, the two input parameters "myInt1"
and "myInt2" are added together and the result is assigned to the output
parameter "myIntResult".
Note You can use the input and output interface of the function block for the
functionality in order to interact with the rest of the user program.
5. You have created your OPC UA method. Call the function block in the user
program so that the method appears in the OPC UA address space of your
SIMATIC S7-1500. Please note the explanations on this in chapter
2.1.5 Call in the user program.
The following figure shows you the call hierarchy of the blocks of the example
project:
Figure 2-3
OpcMethod InstOpc
Main Allowed MethodAllow
DataTypes edDataTypes
InstOpc
OpcMethod
Method
BubbleSort BubbleSort
InstOpc
OpcMethod
MethodSet
SetPlcTime PlcTime
© Siemens AG 2019 All rights reserved
OpcMethod InstOpc
State MethodState
Machine Machine
All S7 function blocks are called directly in the OB1 cycle of the user program.
Here, the instance data blocks of the individual function blocks implement the OPC
UA methods.
The following methods can be called by an OPC UA client in this example:
• "OpcMethodAllowedDataTypes":
This method contains all permitted data types as input parameters of the
method. During execution, the transferred values are provided as output
parameters of the method.
• "OpcMethodBubbleSort":
This method offers an array of type "Int" as input parameter. The transferred
values are sorted by value size and the result is provided as an output
parameter.
• "OpcMethodSetPlcTime":
You can use this method to set the PLC time.
• "OpcMethodStateMachine"
This method contains a step sequence that is started when the method is
called. The method has no input or output parameters. While the step
sequence is being processed, you receive a negative response when calling
again.
To test the OPC UA methods of the sample project, you can use any OPC UA
client that controls the method functionality. This example uses the “UaExpert” tool
from Unified Automation. The free download can be found in the appendix (\5\).
4. Enter the IP address of the PLC in the text field of the dialog that appears and
then confirm with "OK".
5. Select an end point ("None" in this example) and then confirm with "OK".
6. Select the selected endpoint in the project navigation and click on the "Connect
Server" button.
7. Confirm the certificate of the PLC. For this purpose, activate the checkbox
"Accept the server certificate for this session" and confirm with "Continue".
Alternatively, you can permanently accept the certificate by clicking the "Trust
Server Certificate" button.
© Siemens AG 2019 All rights reserved
Call methods
Once you have established a connection to the server of the PLC, you can call up
the methods created in advance:
1. In the “Address Space” area, navigate to “Root> Objects> DeviceSet>
SamplePlcOpcUaMethods> DataBlockInstance”. Within the objects of the
block instances, you will find the OPC UA methods created in advance.
© Siemens AG 2019 All rights reserved
3. In the dialog that appears, enter an input parameter of the method (in the
example: The PLC time) and then click on "Call" to execute the method.
4. After the successful execution of the method, you will receive a message in the
dialog. In case of a faulty execution, the error code will be displayed there. If
the method has output parameters, these are also displayed in the dialog.
© Siemens AG 2019 All rights reserved
3 Useful information
In this chapter, we provide you with valuable information regarding the
implementation of OPC UA methods on an S7-PLC.
ULINT UInt64
REAL Float
LREAL Double
LDT DateTime
WSTRING String
Note You can declare a maximum of 20 input and output parameters. A structure or
array is interpreted as just one parameter here.
4 Appendix
4.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 2019 All rights reserved
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