Professional Documents
Culture Documents
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 2017 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 ................................................................................ 4
1.3 Components used ................................................................................ 5
2 Commissioning and operation ......................................................................... 6
2.1 Configuring the OPC UA server of the S7-1500 .................................. 6
2.2 Installing the OPC UA Client Library .................................................... 6
2.3 Operation .............................................................................................. 8
2.3.1 Description of the user interface and operating the sheets .................. 8
3 Creating the OPC UA Excel Client ................................................................. 14
4 OPC UA Client Library ..................................................................................... 15
5 Worth knowing ................................................................................................. 17
5.1 Certificate handling in the example program...................................... 17
5.2 Information about the license model of the software ......................... 17
6 Appendix .......................................................................................................... 18
6.1 Service & support ............................................................................... 18
© Siemens AG 2017 All rights reserved
1 Introduction
1.1 Overview
As of firmware V2.0 of SIMATIC S7-1500 an integrated OPC UA Server has been
added to the control system. This enables an additional option of direct process
data exchange of the SIMATIC S7-1500 with a wide variety of other systems that
support OPC UA.
In this application example, you can find the OPC UA Client Library with which you
can create your own OPC UA client applications in Excel VBA to interchange data
between Excel and the SIMATIC S7-1500.
Assumed knowledge
The following basic knowledge is required by the user:
• Basics of programming in C#/.NET and Excel VBA
• Basics of configuring in the TIA Portal
• Basics of OPC
The "OPC UA Client Library" is a "Dynamic Link Library" (DLL) that can be
integrated into Microsoft Excel in order to program OPC UA client functions in
Excel via VBA OPC.
The library internally uses the C# class “UAClientHelperAPI”. This class
summarizes the most important functions of the underlying .NET stack of the OPC
Foundation. The OPC UA Excel Client communicates with the OPC UA server of a
SIMATIC S7-1500.
The SIMATIC S7-1500 OPC UA server is planned and configured via the TIA
Portal. Client and server are connected via Ethernet and communicate through
OPC UA via TCP/IP.
For more information, please refer to the entry \3\.
Figure 1-1
Industrial Ethernet
OPC UA
UAClientHelperAPI
NOTE Not all data types can be interpreted by the "OPC UA Client Library". Adapt the
source code if necessary.
6. Register the library on your system. Enter the following string into the
command line interface
C:\Windows\Microsoft.NET\Framework\v4.0.30319\regasm
C:\109748892_OPC_UA_ClientLibrary_CODE_V2_1\OPC_UA_ExcelClient\
Application\Opc.Ua.ExcelClient.dll /tlb /codebase
and acknowledge with Enter.
7. After the successful registration, you can use the library in Excel.
© Siemens AG 2017 All rights reserved
NOTE The above instructions are valid for Microsoft Office 32-bit. If you have Microsoft
Office x64 installed, use the following string for "regasm":
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\RegAsm.exe <Pfad zu
Opc.Ua.ExcelClient.dll> /tlb /codebase
2.3 Operation
The following step-by-step instructions show you how you can commission the
application example and how you can operate it.
The following prerequisites apply:
• The OPC UA Client Library has been registered on your system.
• An OPC UA Server is activated and connected to your PC/PG.
• The worksheet "109748892_OPC_UA_ClientLibrary_Sample_V2_1.xlsm" has
been downloaded and opened.
The user interface of the “OPC UA Excel Client” example client is divided in four
sheets: “Connect”, “ReadWrite”, “Subscribe”, “Method” and "ReadStructUdt".
Connect
The following figure shows the “Connect” interface:
Figure 2-1
© Siemens AG 2017 All rights reserved
1 2
The following table describes the functions of the interface of the previous figure:
Table 2-1
No. Description
1. Text field to enter an OPC UA server URL.
2. Button to search OPC UA endpoints with the URL (1).
3. List of the OPC UA endpoints found.
4. Settings for user authentication.
5. Button to establish a connection to a selected endpoint of the list (3) and
disconnection.
ReadWrite
The following figure shows the “Read/Write” interface:
Figure 2-2
1 2 3
4 5 6
9 10
© Siemens AG 2017 All rights reserved
7 8
11 12
13 14
The following table describes the functions of the interface of the previous figure:
Table 2-2
No. Description
1. Button to read an entered node ID from (2).
2. Text field to enter a node ID to be read.
3. Text field to output the value of the read node ID from (2).
4. Button to write an entered node ID from (5).
5. Text field to enter a node ID to be written.
6. Text field to enter the value of the node ID to be written from (5).
7. Button to register an entered node ID from (9).
8. Button to cancel a registration of an entered node ID from (9).
9. Text field to enter a node ID to be registered.
10. Text field to output a registered node ID.
11. Button to read a registered node ID.
12. Text field to output the value of the read, registered node ID from text field.
13. Button to write a registered node ID.
14. Text field to enter the value of the registered node ID to be written.
The following steps describe how to write a variable from the server:
1. Enter the Node Id of a variable to be written in the field "Node Id" (5).
2. Enter the value to be written in the field "Value to write" (6).
3. Click on the "Write" button (4) to write the variable.
The following steps describe how to register a server variable and how to read and
write the registered variable:
1. Enter the Node Id of a server variable to be registered in the Node Id field (9).
2. Click on the "Register" button (7). You will get back the handle of the registered
variable in the field "Registered Node Id" (10).
3. Click on the "Read" button (11) to read the registered variable. The read result
can be found in the "Read value" field (12).
4. Enter the value to be written in the "Value to write" field (14).
5. Click on the "Write" button (13) to write the variable.
© Siemens AG 2017 All rights reserved
"Subscribe"
The following figure shows the “Subscribe” interface:
Figure 2-3
1 2
4
© Siemens AG 2017 All rights reserved
The following table describes the functions of the interface of the previous figure:
Table 2-3
No. Description
1. Button to start a subscription on an OPC UA server and to create a
MonitoredItem via the node ID from text field (3).
2. Button to end a subscription and to delete the MonitoredItem.
3. Text field to enter a node ID that is added to the subscription as MonitoredItem.
4. Text field to output the value of the MonitoredItem of the subscription with time
stamp and status.
Method
The following figure shows the “Method” interface:
Abbildung 2-4
1 2
3 4
5 6
The following table describes the functions of the interface of the previous figure:
Tabelle 2-4
© Siemens AG 2017 All rights reserved
Nr. Beschreibung
1. Button to retrieve the input and output parameters.
2. Button to call the method.
3. Enter the node ID of the parent object in which the method is located.
4. Enter the node ID of the method.
5. List of the input parameters of the method (enter the values of the input
parameters in the "Value" column).
6. List of the output parameters of the method.
ReadStructUdt
The following figure shows the “ReadStrucUdt” interface:
Figure 2-5
3
© Siemens AG 2017 All rights reserved
The following table describes the functions of the interface of the previous figure:
Tabelle 2-5
Nr. Beschreibung
1. Button to read an entered node ID from (2).
2. Text field to enter a node ID to be read.
3. Text field to output the value of the struct/UDT with variable names and data
types.
The following step-by-step instructions show you how to create your own OPC UA
Excel Client.
1. Start Excel with a new file.
2. In the "Developer" menu, select the Microsoft Basic Editor.
© Siemens AG 2017 All rights reserved
4. You can now use the OPC UA Client Library in your client. Please refer to VBA
implementation of the Microsoft Basic Editor in the delivered example sheet for
further information.
OpcUaClient
This class represents an OPC UA client.
Table 4-1
Method Description
OpcUaSubscription
This class represents a subscription. The subscription is created and returned by
the OpcUaClient in the Subscribe(...) method. The subscription is needed in the
AddMonitoredItem(…) method and in the RemoveSubscription(…) method.
OpcUaMonitoredItem
This class represents a MonitoredItem. The MonitoredItem is created and returned
by the OpcUaClient in the AddMonitoredItem(...) method. The MonitoredItem is
needed in the RemoveMonitoredItem(...) for its removal.
OpcUaEndpoint
This class represents an endpoint of an OPC UA server. In the GetEndpoints
method, the OpcUaClient provides all endpoints for the supplied URL of the OPC
UA server. The endpoint is required in the Connect(...) method to establish a
connection.
© Siemens AG 2017 All rights reserved
5 Worth knowing
5.1 Certificate handling in the example program
The client certificate of the sample program is created the first time it is started and
stored in the Windows certificate store. The certificate is required for encrypted and
signed connections and has the name "UA Client 1500". The certificate is self-
signed by the application.
The certificate store can be found under "Start > Run > mmc > Enter > File >
Add/Remove Snap-In > Certificates > Add > Select My Account > OK" in the "My
Certificates" folder.
To re-create the certificate, delete it from the store and then restart the application.
Hinweis The sample client automatically accepts all server certificates unchecked for
each session but does not save them.
Hinweis Before you start developing your own application, check out the appropriate
licensing models based on your membership of the OPC Foundation.
6 Appendix
6.1 Service & 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 2017 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