OPCclient RCW Doku v2 1 PDF
OPCclient RCW Doku v2 1 PDF
http://support.automation.siemens.com/WW/view/de/21043779
The Application Examples are not binding and do not claim to be complete with
regard to configuration, equipment or any contingencies. The Application
Examples do not represent customer-specific solutions; they are only intended to
provide support for typical applications. You are responsible for ensuring that the
described products are used correctly. These Application Examples do not
relieve you of the responsibility of safely and professionally using, installing,
operating and servicing equipment. When using these Application Examples, you
recognize that we cannot be made liable for any damage/claims beyond the
liability clause described. We reserve the right to make changes to these
Application Examples at any time and without prior notice. If there are any
deviations between the recommendations provided in this Application Example
and other Siemens publications e.g. catalogs the contents of the other
documents have priority.
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 will be excluded. Such an exclusion will 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 a condition which goes to the root of the contract
(wesentliche Vertragspflichten). The compensation for damages due to a breach
of a fundamental contractual obligation is, however, limited to the foreseeable
damage, typical for the type of contract, except in the event of intent or gross
negligence or injury to life, body or health. The above provisions do not imply a
change in the burden of proof to your disadvantage.
Any form of duplication or distribution of these Application Examples or excerpts
hereof is prohibited without the expressed consent of Siemens Industry Sector.
Security
information
Siemens provides products and solutions with industrial security functions that
support the secure operation of plants, solutions, machines, equipment and/or
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 productspecific newsletter. For more information, visit
http://support.automation.siemens.com.
(D)COM OPC-Client
Entry ID:21043779, V2.1,
08/2014
Table of Contents
Table of Contents
Warranty and Liability ................................................................................................. 2
1
Task ..................................................................................................................... 4
1.1
1.2
Solution............................................................................................................... 6
2.1
2.2
2.3
2.4
3.3
3.4
3.5
3.5.1
3.5.2
3.5.3
3.6
Basics ............................................................................................................... 12
3.1
3.2
Overview............................................................................................... 4
Requirements ....................................................................................... 5
Overview............................................................................................. 61
Using the block services..................................................................... 63
Glossary ........................................................................................................... 64
10
History............................................................................................................... 66
(D)COM OPC-Client
Entry ID:21043779, V2.1,
08/2014
1 Task
Task
1.1
Overview
Introduction
This application example shows the coupling of a production process to a
Windows-based PC with a data exchange via OPC. With this principle of operation,
for example, separate, specialized user interfaces and process visualization or data
acquisition can be realized.
Applications on the PC
Visualization
Data acquisition
Monitoring
Control system
Operating
DB
Connection
Visualization
other
applications
OPC Client
OPC server
Process
Logic
Data
PLC
I/O
PLC
I/O
(D)COM OPC-Client
Entry ID:21043779, V2.1,
08/2014
1 Task
1.2
Requirements
Connection to the process data via Industrial Ethernet as well as the SIMATIC
NET OPC Server V8.x.
(D)COM OPC-Client
Entry ID:21043779, V2.1,
08/2014
2 Solution
Solution
2.1
Solution overview
Schematic layout
The following scheme shows the most important components of the solution:
Figure 2-1
PG/PC station
STEP 7 V13
SIMATIC NET CD V12
MS Visual Studio 2010
OPC simple client
Industrial Ethernet
0 station
S7-1200 station
15-2 PN/DP
CPU 1214C
S7 station
The controller side consists of two S7 stations: a CPU 315-2 PN/DP and an S71214C
PC station
A PC station is connected via a standard Ethernet network card to a S7-300
controller and a S7-1200. On the PC station the SIMATIC NET OPC server and the
OPC client is running. A very simply designed client (Simple OPC Client) shows
you all basic functions for getting started.
The functionality of these sample clients will be explained in the next section.
Advantages
This application offers the following advantages:
(D)COM OPC-Client
Entry ID:21043779, V2.1,
08/2014
2 Solution
Delimitation
This application does not contain a complete description of the following topics:
".NET" Framework
C#
OPC specification
2.2
Figure 2-2
.NET Framework V3.5 SP1
.NET Windows application
GUI using OPC Client functions
Application
simplified .NET interface
Assemblies
In scope of delivery of
SIMATIC NET DVD 2011
.NET Interface
SIMATIC NET
OPC DA server
Logic / Simulation
CPU
PLC
IE Softnet S7
OPC server
S7 protocol
CP
Ethernet NIC
PG/PC
PC/PG
A C# OPC client has been realized on the PC/PG for visualizing.
For connecting to the process, the OPC client uses the OPC Runtime Callable
Wrapper (abbr.: RCW) that is automatically installed together with the SIMATIC
NET OPC server.
The SIMATIC NET OPC server establishes the connection to the controller via the
SIMATIC NET SOFTNET-S7 connection.
(D)COM OPC-Client
Entry ID:21043779, V2.1,
08/2014
2 Solution
Control
The controller provides the data to be visualized.
For this purpose, a simple S7 program for simulating various data types is
implemented.
C# OPC client
Action
User interface
Monitoring values.
Reading/writing values.
Reading/writing block.
Note
The actions are performed via the operator elements of the user interface.
(D)COM OPC-Client
Entry ID:21043779, V2.1,
08/2014
2 Solution
2.3
No.
Article number
PS307 5A
6ES7307-1EA00-0AA0
6ES7315-2EH14-0AB0
S7-1200 PM 1207
6EP1332-1SH71
6ES7 214-1AE30-0XB0
Standard switch
Depending on product
Note
or a comparable
S7-300 CPU
or a comparable
S7-1200 CPU.
Component
No.
Article number
Note
Power PG
6ES7751-0EA31-0LB3
or similar PC/PG
Depending on product
Integrated in Power
PG
No.
Article number
Note
STEP 7 Professional
V13
6ES7822-4AA03-0YA5
WinCC Professional
6AV2103-0DA00-0AM0
SIMATIC NET IE
SOFTNET-S7 (V12)
6GK1704-1LW12-0AA0
6GK1704-1CW12-0AA0
Express Edition
Standard Edition
Professional Edition
Free download at
Installed by SIMATIC NET
http://www.microsoft.com/
(D)COM OPC-Client
Entry ID:21043779, V2.1,
08/2014
2 Solution
Sample files and projects
The following list includes all files and projects that are used in this example.
Table 2-5
Component
2.4
Note
21043779_OPCClient_RCW_CODE.zip
21043779_OPCClient_RCW_DOKU_V2_1_e.pdf
This document
Alternative solutions
Description
Custom interface
Automation interface
Simple implementation
Error handling
Performance
Parallelity
VBA (MSOffice)
VB V6.0
VC++
(with RCW)
Custom interface
(D)COM OPC-Client
Entry ID:21043779, V2.1,
08/2014
10
2 Solution
Automation interface
(*)
Simple implementation
++
++
+ (**)
++
Error handling
++
++
Performance
++
Parallelity
++
Deciding criteria
Description
OPC UA
Is a combined function
(read/write/alarms/methods/objects/types) with expanded
functions required?
Security
Platforms
Is the application only to communicate with Windowsbased systems (no Linux, Android, iOS)?
Functionality, flexibility
OPC Connector
OPCClient.API
OPCDa.RCW
OPCUa.RCW
COM DA Interface
COM AE Interface
OPC UA Interface
(*)
(*)
Security
- (**)
- (**)
- (**)
++
Platforms
Functionality, flexibility
++
+++
- (***)
- (***)
Other manufacturer
(***) classic OPC DA and OPC UA parallel, limited to SimaticNET OPC server
(D)COM OPC-Client
Entry ID:21043779, V2.1,
08/2014
11
3 Basics
Basics
3.1
Introduction
This section only briefly discusses the application model of the OPC DA interface.
A detailed description of the object model is available in the OPC DA specification
of the OPC foundation.
OPC Client
The OPC client tells the OPC server that it wants to have access to certain tags by
the OPC client creating references to the respective interfaces.
Further interfaces available via the IOPCGroupStateMgt group(s) interface enable
read and write access to these tags. The following access methods are possible:
Note
OPC server
The OPC server is the central communication unit between an OPC client and the
respective controller.
Via COM/DCOM mechanisms, it provides standardized interfaces towards the
OPC client which allow each COM-capable application to access tags of any
controller.
In this application, the DataAccess interfaces for generating the logic connections
between OPC items and process tags are decisive.
The OPC server is connected to the respective controller via the implementation of
the communication protocols.
Connection between OPC server and controller
The values of the tags are read out via the connections configured in the OPC
server using the respective protocol blocks. In this example, the S7 protocol is
used that contains two principle transmission mechanisms, the tag services and
the block services. The connections are configured in the TIA portal (see chapter
5.2).
(D)COM OPC-Client
Entry ID:21043779, V2.1,
08/2014
12
3 Basics
Reading tags from the controller
You can read out and update the tags in two different ways:
Table 3-1
Service
Description
Tag service
For tag services, one or several process tags are specified by means
of absolute or symbolic addressing. Thereby, the tags to be monitored
can be polled cyclically from the OPC server (Polling, see
Glossary). Nothing has to be programmed in the controller here. The
communication is performed via system-internal processes.
Block service
In this application tag services and block services (only S7-300) are used.
The absolute addressing only differs from the symbolic addressing by the
ITEM_ID.
The tag and block services on the OPC client side are only differentiated by its
ITEM_ID.
(D)COM OPC-Client
Entry ID:21043779, V2.1,
08/2014
13
3 Basics
3.2
Figure 3-1
The red arrows show the call direction, the blue arrows the resulting data flow.
Data is exchanged between the OPC server and the controller using an
Industrial Ethernet card and the internal interface of a PN-CPU or a CP343-1.
Data exchange between OPC client and OPC server occurs as inter-process
communication (here: COM).
"Cache" refers to a temporary buffer which the OPC server generates for a
particular group. It contains a local image of the process tags defined for this
group (which in return are managed by the group as OPC items).
(D)COM OPC-Client
Entry ID:21043779, V2.1,
08/2014
14
3 Basics
Explanation of the processes
The following table explains the respective calls and data flows. In the process, the
following consequences are pointed out:
Table 3-2
No.
Action
Remarks
The value of the OPC item is read with the value currently located in
the CACHE.
Updating the
CACHE
The OPC server updates the entire CACHE with the values from the
DEVICE after the time period defined with the
requestedUpdateRate.
Note:
OnDataChange Event
The OPC client starts an asynchronous read job via the OPC group.
The OPC server reads the requested process tags from the process
image of the S7-CPU and delivers them to the OPC client via the
OnReadComplete event. It then writes the read values to its CACHE
Note:
The value of the OPC item is read with the value currently located in
the process image of the S7-CPU.
Note:
(D)COM OPC-Client
Entry ID:21043779, V2.1,
08/2014
15
3 Basics
6
Synchronous or
asynchronous write job
Operation
DEVICE
CACHE
Note
Synchronous reading
Asynchronous reading
Synchronous writing
Asynchronous writing
Monitoring (event
controlled)
Note
Apart from read and write jobs, further methods are also available (such as e.g.
IOPCAsyncIO2::Refresh) which, however, were not used in this application.
For further information see OPC Specification of the OPC Foundation.
(D)COM OPC-Client
Entry ID:21043779, V2.1,
08/2014
16
3 Basics
Comparison of application cases
The following table contains a comparison of different application cases and shows
the recommended procedure:
Table 3-4
Operation
Read
Cyclic/
Acyclic
Data volume
DataChange
mechanism
Sync
Async
Cyclic
monitoring
Large
Small
Large
Small
Large
Small
Acyclic
Write
Acyclic
Large data volumes in the range of several kilobytes should be read or written
with the block services, e.g. BSEND/BRCV. Here, the SIMATIC works as active
communication partner.
Note
(D)COM OPC-Client
Entry ID:21043779, V2.1,
08/2014
17
3 Basics
3.3
The following figure illustrates this option with two different groups. Process tag 1 is
mapped to two OPC items, which are stored in two groups. This makes it possible
to achieve different ways of behavior for a process tag in an OPC client.
Figure 3-2
(D)COM OPC-Client
Entry ID:21043779, V2.1,
08/2014
18
3 Basics
3.4
Handle types
Two handle types are distinguished. This differentiation ensures that the OPC
client as well as the OPC server can identify the respective OPC items.
Table 3-5
Type
Description
Client handles
These handles are created by the client and are used for identification
of an OPC item within the OPC client. When creating the items
(AddItems) the client tells the server its client handles.
Server handles
These handles are created by the server and are used for
identification of an OPC item within the OPC server. When creating
the items (AddItems) the server gives the client back its server
handles.
Server handles
If the call direction is from OPC client to OPC server (e.g. write), the OPC client
must transfer the respective server handles to the OPC server.
Example: write into the OPC item!
Figure 3-3
Client handles
If the call direction is from OPC server to OPC client (e.g. OnDataChange), the
OPC client will receive the respective client handles from the OPC server.
Example: The OPC items in the CACHE have changed. The OnDataChange
event is triggered.
(D)COM OPC-Client
Entry ID:21043779, V2.1,
08/2014
19
3 Basics
Figure 3-4
(D)COM OPC-Client
Entry ID:21043779, V2.1,
08/2014
20
3 Basics
3.5
3.5.1
Overview
Figure 3-5
API
The previous programming model of the Windows world builds on an Application
Programmers Interface (API). The API provides a lot of C functionalities for
accessing the operating system resources and functionalities.
Programming languages and libraries
Using various programming languages with partially extensive libraries
(VBRuntime, Microsoft Foundation Classes, Active Template Library) it was
possible to implement Windows programs. The libraries respectively encapsulated
a part of the API functions.
(D)COM OPC-Client
Entry ID:21043779, V2.1,
08/2014
21
3 Basics
Interacting of the languages with COM
In order for the developed program components to be able to work with each other,
Component Object Model (COM) by Microsoft was introduced. Using standardized
interface definitions made it possible to establish a "connecting glue" between the
individual components. The concept of Distributed Component Object Model
(DCOM) was developed in order to expand the cross-language and crosscomponent interaction to a cross-computer interaction.
Note
3.5.2
Overview
Figure 3-6
API
The basis of the model is Win32 API like in the previous Microsoft programming
world.
CLR
Based on the API, follows the Common Language Runtime (CLR). It constitutes a
runtime environment whose model is comparable with a Java Virtual Machine. It
compiles Just In Time (JIT) a type of byte code in X86 code (depending on the
respective processor architecture); Microsoft speaks of IL code (Intermediate
Language).
Intermediate Language, Garbage Collector and unmanaged Code
The advantage of the IL code is the fact that it is independent of the platform. It is
also possible, for example, to execute this code on Linux (Unix) systems, if a CLR
has been implemented there (see \6\).
The CLR does not only perform the JIT compiling of the IL code, but also the entire
memory management. Similar to Java, a Garbage Collector (GC) was developed,
who releases un-referenced memory areas within the CLR after an unspecified
time. Code that is subjected to the access of the Garbage Collector is also referred
to as managed Code.
(D)COM OPC-Client
Entry ID:21043779, V2.1,
08/2014
22
3 Basics
In order for it to be possible in certain cases to still control the release of memory
areas manually, the developed code can be declared as "unmanaged". This
enables protecting certain code areas or entire programs explicitly from the access
of the Garbage Collector.
Base classes
Regarding the libraries of partly varying extend of the old world, Microsoft has now
implemented a uniform base class library which can be accessed independently
from the .NET programming language.
Integrator Visual Studio .NET
Visual Studio .NET (VS .NET) takes on the task of combining the different .NET
languages with each other.
This enables realizing .NET components in different languages. Interactions
between .NET components are easily possible with Visual Studio .NET.
Easy-to-handle integration options therefore make a faster development within the
.NET components possible.
3.5.3
Overview
Siemens AG 2014 All rights reserved
Runtime Callable Wrapper (RCW) and the relationship with the COM component
Installing a COM component generated for the previous Windows world within a
.Net application, requires a "wrapper", a type of case which encapsulates all
interface definitions for the .NET application.
This is necessary as the previous interface definitions located in so-called IDL files
(Interface Definition Language, see Glossary) are no longer supported by .NET.
This wrapper is also referred to as Runtime Callable Wrapper (RCW).
For COM components offering the automation interface, Visual Studio can
generate these wrappers automatically.
However, for COM components providing the custom interface, such wrappers
must be generated manually.
For the Custom Interfaces (e.g. OPC DA 2 / 3) defined by the OPC Foundation, the
wrappers were created manually by the OPC Foundation and provided for general
use. These .NET OPC RCWs are, for example, installed with the SIMATIC NET CD.
(D)COM OPC-Client
Entry ID:21043779, V2.1,
08/2014
23
3 Basics
Note
The differences between automation and custom interface are not discussed
here in greater detail. This requires secondary literature /2/.
Direction
Description
.NET to COM
In .NET, all tags are objects. Due to the fact that generally speaking,
COM servers do not synchronize with COM clients, transfer values
should be protected from the access of the Garbage Collector ("pinning"
of objects).
COM to .NET
Note
(D)COM OPC-Client
Entry ID:21043779, V2.1,
08/2014
24
3 Basics
3.6
Basics on S7 communication
The classic OPC server (COM/DCOM) is available for all other protocols such as
DP, FDL, SR or SNMP. On the SIMATIC NET CD V8.0 there is additionally an
OPC UA server. The OPC UA server is not a part of this description.
Figure 3-8
OPC Client
S7:[S7Connection1]BRCV,1,D0,1024
OPC server
S7 protocol
S7 tag services
S7 block services
List
of addresses
to be written
List
of addresses
to be read
PUT
SIMATIC
S7-1200
(D)COM OPC-Client
Entry ID:21043779, V2.1,
08/2014
GET
SIMATIC
S7-300
SendBuffer<RID>
RcvBuffer<RID>
Data
(max. 384Kbytes)
Data
(max. 384Kbytes)
BSEND
SIMATIC
S7-400
BRCV
25
3 Basics
Tag services
A S7 controller replies to requests via tag services, for this purpose only a
unilaterally configured connection is necessary. Each S7 controller is a so called
S7 server and answers PUT/GET requests without the need of any
implementation in the control program of the PLC. All data areas of the controller
can be directly accessed (I, Q, M, DB, etc.). This communication service is very
flexible and, above all, easy to use.
ItemIds for tag services
S7:[<connectionname>]DB<no>,{<type>}<address>{,<quantity>}
Example: S7:[S7 connection_3]DB10,W20
A tag of the word type (16bit no signs), which is located in data block 10 and which
starts at the byte offset address 20 (meaning it consists of bytes 20 and 21). This
tag is retrieved with Put/Get via the connection called S7 connection_3, meaning
from the S7 controller which is hidden behind this connection.
Symbolic ItemIDs
Apart from the direct addressing, there is the option of symbolic addressing. For
this purpose, the address space is generated from STEP7 (TIA Portal). For all
symbolic identifiers of the data points in the S7 controllers which are connected
with an OPC server via a S7 connection, a symbol export can be triggered. The
thus generated symbols file with the ending ATI is introduced to the OPC server via
download from STEP7 or via XDB import. The ATI file (Advanced Tag Information)
contains an image of the symbolic name for the direct addresses.
Note
All symbols are eventually retrieved via PUT/GET from the controllers. Symbols
which represent a BSEND or BRCV tag cannot be generated by STEP7.
Block services
For the exchange of large data volumes the more effective block service is
available. On a bilaterally configured connection, large data volumes (up to
64kbytes) can be exchanged. Communication is based on the exchange of data
buffers. However, the respective system function blocks (BSEND/BRECV) have to
be called in the control program for this purpose. The OPC server provides the
respective counterparts to the PC if the corresponding OPC items have been
created.
Structure of ItemIds for block services
S7:[<connectionname>]BRCV,<RID>{,{<type>}<address>{,<quantity>}}
(D)COM OPC-Client
Entry ID:21043779, V2.1,
08/2014
26
3 Basics
The entire block is sent with ID 1 to the communication partner who has to provide
a BRECV with ID 1 and a minimum length of 1024 bytes to be able to receive the
data.
Note
Also read the notes in the SIMATIC NET manual regarding the subject of blockoriented services (see \7\).
(D)COM OPC-Client
Entry ID:21043779, V2.1,
08/2014
27
General overview
Figure 4-1
Application
Simple Client
4
.NET Windows application
User interface of the simple client
simplified .NET interface
Assemblies
In scope of delivery of
SIMATIC NET DVD 2011
.NET Interface
SIMATIC NET
OPC DA server
Logic / Simulation
CPU
PLC
IE Softnet S7
OPC server
S7 protocol
CP
Ethernet NIC
PG/PC
Table 4-1
No.
Module
1.
2.
OpcRcw.Da
3.
4.
Simple Client
(D)COM OPC-Client
Entry ID:21043779, V2.1,
08/2014
28
Server
Connection
Subscription
Management
Read
Write
Callback
Object
OPC Group
Description
When establishing the connection the server object is created in the local or
remote OPC server.
Once the connection has been established, the Client API creates an inactive
group that is used for reading and writing of items.
An OPC group object is created in the server via the COM DA interface.
(D)COM OPC-Client
Entry ID:21043779, V2.1,
08/2014
29
4.1
Figure 4-3
COM DA ClientAPI
Server
+Connect()
+Disconnect()
+Read()
+Write()
+Browse()
+GetProperties()
+CreateSubscription()
+DeleteSubscription()
Subscription
+AddItem()
+RemoveItem()
IOPCDataCallback
uses
uses
uses
uses
uses
IOPCSyncIO
IOPCServer
IOPCItemMgt
. . . . other OPC Interfaces
Local (COM) or
Remote (DCOM)
OpcRcw.Da.dll
OpcRcw.Comn.dll
OPC Server
Server class
The Server wrapper class described in the table below encapsulates the
functionality for the access to the OPC server. Moreover, it simplifies the use of
those OPC interfaces which are need by the client application, with the exception
of interfaces for the adding and deleting of items in the subscription.
The class is implemented in the OpcDaServer.cs file in the COMDAClientApi
project.
(D)COM OPC-Client
Entry ID:21043779, V2.1,
08/2014
30
Functionality
Connect
Disconnect
Releases all references to the COM object and deletes all groups.
Browse
Read
Write
CreateSubscription
DeleteSubscription
Subscription class
The Subscription wrapper class described in the table below, encapsulates the
use of an OPCGroup for the value exchange between server and client.
The class is implemented in the OpcDaSubscription.cs file in the COMDAClientAPI
project.
Table 4-4
Method
Functionality
AddItem
RemoveItem
(D)COM OPC-Client
Entry ID:21043779, V2.1,
08/2014
31
4.2
1
9
4
Table 4-5
No.
Description
1.
The server URL can be specified in the text box for the Server URL. The URL is made up of the
computer name and the server ProgID:
opcda://<computername>/ProgID.
For example, for a local SIMATIC NET server://localhost/Opc.SimaticNET.
2.
In the text boxes for the ItemIDs the OPC ItemID is specified. This ID is unique in the address
space of the server.
3.
Via the connect and disconnect buttons, the connection to the OPC server can be established or
disconnected.
4.
Via the monitor button, the subscription is created and the two items are added to a group. From
now on data changes are reported from the server to the client and displayed in the two text
boxes next to the button. Errors are each shown instead of values.
The button changes the text to Stop after creating the subscription. Via this button the
subscription can then also be deleted again.
5.
The Read button reads the values of the two tags with the indicated ItemIDs and displays them
in the text boxes next to the button.
Reading in the direction of the server is performed synchronous via the IOPCSyncIO::Read()
OPC method.
6.
The Write button writes the value from the text box next to the button on the tag which was
identified by the ItemID.
For writing, the text is sent from the text field to the server as a value.
The server automatically converts the values to the suitable data type of the item.
Writing in the direction of the server is performed synchronous via the IOPCSyncIO::Write()
OPC method.
(D)COM OPC-Client
Entry ID:21043779, V2.1,
08/2014
32
Description
7.
In the Block Read group, data can be received which is actively sent by the S7 with the
BSEND block service. This can be, for example, used for the sending of result data from the S7
to a PC application.
8.
In the Block Write group, data blocks can be sent to the S7 which are there received by the
BRECV block service. Two blocks with different contents can be sent. This can be used, for
example, for the download of recipe data for the S7.
9.
The block services are only available for the S7-300. When switching to S7-1200, the reading
and writing of blocks on the interface will be disabled.
Function
Description
btnConnect_Click
In this function the connection to the OPC server is established via the
Server::Connect() function of the client API. The URL string from the
corresponding text box is transferred.
btnDisconnect_Click
btnRead_Click
In this function the values for the two items are read via the
Server::Read() function. The result is written into the respective text
box. If there is an error when reading or if the quality is bad (i.e. no
value can be delivered by the server), an error code is written into the
text box.
btnMonitor_Click
OnDataChange
btnWrite_Click
The function calls the Server::Write() and writes the current text as
value to the item.
(D)COM OPC-Client
Entry ID:21043779, V2.1,
08/2014
33
Description
btnMonitorBlock_Click
btnWriteBlock1_Click
btnWriteBlock2_Click
Further details are contained in the source code of this application as comment.
Note
(D)COM OPC-Client
Entry ID:21043779, V2.1,
08/2014
34
4.3
S7 program
Overview
The S7 program is essentially divided in two parts. First of all, the dynamic data for
the tag services is simulated, afterwards the send data is simulated and the block
services are called in FB 100.
Note
The block services are only available in the S7-300; the S7-1200 solely
communicates via S7 tag services.
Figure 4-5
OB1
FC10
change data
FC11
change data
FC13
change data
FC14
FB100
DB51
change data
FB12
FB13
DB50
DB112
send block
receive block
DB113
(D)COM OPC-Client
Entry ID:21043779, V2.1,
08/2014
35
Remarks
Cyclic Main
initially, a variable timer is set here, whose interval is used to call
the other program functions. The rate of change of data can be set
via DB10 byte 0.
FC10
ChangeDateAndTime
increments a date value as well as the time in DB51.
FC11
ChangeSimpleTypes
increments the data of DB51. 8bit types are incremented with +1,
16bit types with +100 and 32bit types with +1000.
FC13
ChangeString
increments a string of length 10 in DB51.
DB10
SimulationConfiguration
contains global tags for the configuration of data simulation.
DB50
StaticDataTypes
contains simple data types which were given symbolic names. The
values are pre-initialized with maximum end value range.
DB51
DynamicDataTypes
contains simple data types which were given symbolic names. The
values are incremented with the functions FC10 to FC12 according
to their value ranges.
SFC21
FILL
auxiliary function to fill data areas with values, storage initialization.
OB1
(D)COM OPC-Client
Entry ID:21043779, V2.1,
08/2014
36
Block
Remarks
OB1
Cyclic Main
Call of the send block (SFB12) for BSEND and of the receive
block (SFB13) for BRCV via function block 100.
For S7-300, FB12 and FB13 from the library are used since
S7 300 communicates via loadable FBs and not via system
functions.
FC14
ChangeSendData
Increments a byte which will then be copied to the entire send
buffer
FB100
+ DB100 (Instance
DB)
InvokeBSENDandBRCV
Calls the real communication blocks and supplies its
parameters.
DB112
SendData
Data block with 4096 bytes length which will be transferred to
the send block.
DB113
ReceiveData
data block with 4096 bytes length which will be transferred to the
receive block.
SFB12
+ DB12 (Instance
DB)
BSEND
The send block transfers the send buffer to the communication
processor (CP), which will then send it according to RID and
connectionID to the communication partner.
FB12
SFB13
+ DB13 (Instance
DB)
BRCV
The receive block picks up the data package last received from
the communication processor (CP) according to RID and
connectionID and files it in the receive buffer.
FB13
SFC21
FILL
Auxiliary function to fill data areas with values, storage
initialization.
The program logic sends or receives data blocks and supplies the respective
parameters via the FB100. When larger data packages are sent, a multiple call of
the BSEND or BRCV block is necessary. This multiple call is performed by FB100.
(D)COM OPC-Client
Entry ID:21043779, V2.1,
08/2014
37
If the send and receive block is called cyclically, a high communication load may
be generated and there is furthermore the danger that the data buffers are
overwritten before they are processed by the counterpart. This is why the
program logic should contain a flow control to ensure data consistency. For this
purpose the parameters DONE (ready) and NDR (new data received) are to be
used.
Note
(D)COM OPC-Client
Entry ID:21043779, V2.1,
08/2014
38
Introduction
In the sections below, we show you the steps to configure the PC station and the
OPC server in STEP7 V11. You only need to read this chapter if you are interested
in the details. The configuration has already been completed in the delivered
STEP7 project.
5.1
Table 5-1
No.
Action
Open your STEP7 V11 project and go to the project view.
(D)COM OPC-Client
Entry ID:21043779, V2.1,
08/2014
39
No.
Action
A SIMATIC PC station is created where a SIMATIC NET OPC server is configured on index 1.
Enable the creation of the XDB file (Generate XDB file). The storage of the XDB file by the system
can be set under XDB file path.
(D)COM OPC-Client
Entry ID:21043779, V2.1,
08/2014
40
Action
(D)COM OPC-Client
Entry ID:21043779, V2.1,
08/2014
41
Enable the symbolic display of the OPC tags. When using symbols, you can configure whether you
want to use All or Configured symbols. Often you do not want to make all symbols available via
the OPC server (e.g. internal tags or contents of instance data blocks).
Action
(D)COM OPC-Client
Entry ID:21043779, V2.1,
08/2014
42
If you only want to access a symbolic selection of process tags, select the Configured option.
Select the symbolically addressable tags via the Configuring... button.
Action
Note:
If no symbols are displayed, the S7 connection configuration is missing. Only when a S7 connection
was configured for the respective SIMATIC by the OPC server, will symbols be displayed.
This will be shown in the next chapter.
(D)COM OPC-Client
Entry ID:21043779, V2.1,
08/2014
43
5.2
Table 5-2
Action
Open the object properties of the network card. If no IE network has been configured yet, generate
a new one with Add new subnet and apply the standard parameters.
No.
Note:
(D)COM OPC-Client
Entry ID:21043779, V2.1,
08/2014
44
No.
Action
Open the network view. Connect all nodes with the same IE network.
Select the OPC server. Add new connection in the context menu.
(D)COM OPC-Client
Entry ID:21043779, V2.1,
08/2014
45
Action
Select the type of connection (S7 connection) and the connection partner as well as the physical
access point (blue) that is supported by both partners.
Assign a name for the S7 connection.
(D)COM OPC-Client
Entry ID:21043779, V2.1,
08/2014
46
No.
Action
The connection with CPU 315-2 PN/DP was configured both ways here.
(D)COM OPC-Client
Entry ID:21043779, V2.1,
08/2014
47
No.
Action
The OPC server should always establish the connection actively and maintain it permanently. The
OPC server should furthermore respond instantly if a connection failure is detected.
10
Perform the same steps in the same way for the S7 connection for S7-1200.
11
(D)COM OPC-Client
Entry ID:21043779, V2.1,
08/2014
48
5.3
Table 5-3
No.
Action
(D)COM OPC-Client
Entry ID:21043779, V2.1,
08/2014
49
No.
Action
If one of the settings does not correspond with the displayed images, perform the preceding
configurations again.
Close the configuration dialog box.
(D)COM OPC-Client
Entry ID:21043779, V2.1,
08/2014
50
6.1
Table 6-1
No.
Focus
Action
Control
S7-300 station
Control
S7-1200 station
PG/PC station
Industrial Ethernet
Note
Instead of using a hub or a switch you can also use a cross cable for a direct
connection.
Always observe the installation guidelines for SIMATIC S7.
(D)COM OPC-Client
Entry ID:21043779, V2.1,
08/2014
51
Notes
Module
IP address
PG/PC
192.168.172.1
Control
CP 343-1
192.168.172.2
Control
CPU 1214 C
192.168.172.4
Note
Please ensure, that the network card has the fixed IP address 192.168.172.1 (it
can be set via the network settings and the TCP/IP properties) if you want to use
the project included in delivery.
(D)COM OPC-Client
Entry ID:21043779, V2.1,
08/2014
52
6.2
No.
Action
Confirm by opening.
(D)COM OPC-Client
Entry ID:21043779, V2.1,
08/2014
Remarks
Unzip the project in a path in which you have the
read and write permissions.
\OPCSample\OPCSample.ap11
53
Action
Remarks
Note
Only execute these steps if you want to change the IP address of your PC
station.
Table 6-4
No.
Action/Remark
1.
2.
Go to the project view, select the SIMATIC PC station in the project view and open the Device
view.
(D)COM OPC-Client
Entry ID:21043779, V2.1,
08/2014
54
No.
Action/Remark
3.
Select your network card in the PC station and select the Properties tab in the bottom window.
You can change the IP address under Ethernet addresses -> IP protocol.
Note: In this case an IE General network card was used.
4.
In the context menu of the SIMATIC PC station you can find Configure PC station online.
Changes on the configuration of the PC station require the station to be reloaded.
5.
(D)COM OPC-Client
Entry ID:21043779, V2.1,
08/2014
55
6.3
Introduction
Alternatively to loading a PC station via the TIA portal (see chap Fehler!
Verweisquelle konnte nicht gefunden werden.), it can also be configured via the
station configuration editor and the XDB file. The XDB file already exists in the TIA
project included.
Setting the IP address
The Ethernet network card has to be switched to the configured operation. For this
purpose the PC station has to be configured.
Note
Please ensure, that the network card has the fixed IP address 192.168.172.1 (it
can be set via the network settings and the TCP/IP properties) if you want to use
the project included in delivery.
Table 6-5
Siemens AG 2014 All rights reserved
No.
1
Action
Remarks
(D)COM OPC-Client
Entry ID:21043779, V2.1,
08/2014
56
Action
Remarks
(D)COM OPC-Client
Entry ID:21043779, V2.1,
08/2014
57
Remarks
No.
(D)COM OPC-Client
Entry ID:21043779, V2.1,
08/2014
58
6.4
NOTICE
If you are using an older operating system then Windows 7 SP1 and if
SimaticNET PC Software V8.x was not installed on it, you have to
install .NET-Framework 3.5 +SP1 first.
Information on this matter can be found on the Microsoft Internet pages (see \5\).
No.
Action
Remarks
1.
Extract the
21043779_OPCClient_RCW_CODE.zip file
2.
3.
Files included
The archive file contains the MS Visual Studio Solution file and the source code as
well as pre-compiled binary files for x86 systems. In the subfolder is the executable
file (EXE) as well as the required assemblies.
Directory: \OpcClientDA_V2\bin
Table 6-7
File
Belongs to...
DAClient.exe
Main application
OpcCRcw.Comn.dll
OPC RC Wrapper
OpcRcw.Da.dll
OPC RC Wrapper
ClientAPI.dll
(D)COM OPC-Client
Entry ID:21043779, V2.1,
08/2014
59
6.5
Action
Remarks
Unzip the project in a path in which you have the read and write
permissions.
(D)COM OPC-Client
Entry ID:21043779, V2.1,
08/2014
60
7.1
Overview
The first part for operating the application shows how data of S7 tags are
monitored, read and written via direct or symbolic addressing.
Table 7-1
No.
Action
Start the
simple client
Establish
connection to
server
Select type of
controller.
The use of block services in this application is only possible with controllers of the
S7-300 family. When selecting S7-1200 the interface elements for block services
are disabled.
(D)COM OPC-Client
Entry ID:21043779, V2.1,
Remarks
08/2014
61
Remarks
Monitoring of
data
For the monitoring of data changes, reading, and writing, two tags can be
indicated. As the Item ID, the symbolic name is either specified in the OPC server
or addressed directly (e.g. S7:[con1]MB100).
Via the Monitor button, monitoring can be switched on. The reported data
changes are displayed in the text boxes next to the button. If monitoring is
enabled, the button changes the text to Stop.
Reading and
writing
For reading and writing, the same ItemIDs are used as for monitoring. By
pressing the Read button the two tags are read. Via the two Write buttons the
tags can be written individually.
No.
(D)COM OPC-Client
Entry ID:21043779, V2.1,
08/2014
62
7.2
No.
Action
Remarks
1.
2.
For receiving from the S7, Monitor Block has to be enabled. As soon
as monitoring is enabled, the button changes the text to Stop.
In the Block Read Result text field, the data of the read block is
displayed as HEX code.
3.
Sending of data to S7
(D)COM OPC-Client
Entry ID:21043779, V2.1,
08/2014
63
8 Glossary
Glossary
COM / DCOM
COM (Component Object Model): Software model for communication between
components, based on a standardized interface.
DCOM: Software model for communicating beyond computer boundaries based on
COM.
Event handler
An event handler processes occurring events or Windows messages.
Exception
An exception is referred to as an exceptional situation.
It can be generated either by the operating system (e.g. division by zero) or by the
user program.
Exception handler
(D)COM OPC-Client
Entry ID:21043779, V2.1,
08/2014
64
9 Related Literature
Wrapper
The term wrapper normally refers to a class group which encapsulates other
class groups for data conversion or easier handling. It can be considered an
envelope enclosing the wrapped classes, covering them from the outside.
Related Literature
9.1
Bibliographic references
This list is not complete and only represents a selection of relevant literature.
Table 9-1
Topic
Title
/1/
STEP7
SIMATIC S7-300/400
/2/
STEP7
SIMATIC S7-300/400
/3/
STEP7
SIMATIC S7-300
/4/
STEP7
SIMATIC S7-400
/5/
STEP7
SIMATIC S7-1200
(D)COM OPC-Client
Entry ID:21043779, V2.1,
08/2014
65
10 History
9.2
Title
\1\
OPC
\2\
.NET
\3\
Siemens Industry
Online Support
http://support.automation.siemens.com
\4\
Link to this
document
http://support.automation.siemens.com/WW/view/en/21043779
\5\
Visual Studio
http://www.microsoft.com
\6\
Cross-platform
ILs
http://www.mono-project.com/
\7\
SIMATIC NET
Industrial
communication
Volume 2
http://support.automation.siemens.com/WW/view/en/61630140
10
History
Table 10-1
Version
Date
V1.0
05/2005
First version
V2.0
12/2012
V2.1
06/2014
Migration to
- STEP7 V13
- Visual Studio 2010
(D)COM OPC-Client
Entry ID:21043779, V2.1,
08/2014
Modifications
66