Escolar Documentos
Profissional Documentos
Cultura Documentos
OPC-DP-Slave
The Application Examples are not binding and do not claim to be complete
regarding the circuits shown, equipping and any eventuality. They do not
represent customer-specific solutions. They are only intended to provide
support for typical applications. You are responsible in ensuring that the
described products are correctly used. These Application Examples do not
relieve you of the responsibility in safely and professionally using, installing,
operating and servicing equipment. When using these Application
Examples, you recognize that Siemens cannot be made liable for any
damage/claims beyond the liability clause described above. We reserve the
right to make changes to these Application Examples at any time without
prior notice. If there are any deviations between the recommendations
provided in these Application Examples and other Siemens publications -
e.g. Catalogs - then the contents of the other documents have priority.
csweb@ad.siemens.de
OPC-DP-Slave
Foreword
Objectives of the application
The international OPC standard is an optimized interface for accessing the
process data from a Windows application.
The application on hand shows how a PC can be used as PROFIBUS DP-
Slave for provision of user date while the advantages of a PC can be used
for parallel visualizing in an application at the same time.
Ein PC kann als PROFIBUS DP-Slave eingesetzt werden, um z.B. Daten
einer PC Messkarte oder Rezeptdaten aus einer Datenbank einem
PROFIBUS DP-Master zur Verfügung zu stellen.
In this application, particular emphasis is placed on maximum performance
and minimum resource consumption.
Delimitation
This Getting Started does not contain any description of Visual Studio
.NET, of C++, of the UML notation or any basics on Microsoft COM.
OPC-DP-Slave
Part Description
Application Description Provides a general overview of the contents. You will
learn about the components used (standard
hardware and software components and the
specially created software).
Function principles and Discusses the detailed function processes of the
program structures involved hardware and software components, the
solution structures, and where sensible the concrete
implementation of this application.
This part is necessary if you want to learn about the
interaction of the solution components, for example
in order to use them as the basis for own
development.
Copyright © Siemens AG 2005 All rights reserved
21040390_OPC_DPSlave_DOKU_v10_e
Structure, Configuration This part leads you step by step through the
and Operation of the structure, important configuration steps,
Application commissioning and operation of the application.
Appendix Here you find further information, such as
bibliography, glossary etc..
OPC-DP-Slave
Table of Contents
Application Description ............................................................................................... 7
1 Automation Task............................................................................................. 7
1.1 Overview........................................................................................................... 7
1.2 Requirements ................................................................................................... 8
2 Automation Solution .................................................................................... 10
2.1 Overview of complete solution........................................................................ 10
2.2 Description of the core functionality................................................................ 10
2.3 Required hardware and software components ............................................... 12
2.4 Basic Performance Data................................................................................. 14
2.5 Alternative solutions........................................................................................ 15
Function Principles and Program Structures .......................................................... 18
3 General Function Mechanisms.................................................................... 18
Copyright © Siemens AG 2005 All rights reserved
OPC-DP-Slave
OPC DP Slave
Application Description
Content
Here an overview of this application is given. You will learn about the
components used (standard hardware and software components and the
specially created software).
The basic performance data show how powerful this application is.
1 Automation Task
Here you will find information on …
the automation task discussed in the documentation on hand.
Copyright © Siemens AG 2005 All rights reserved
21040390_OPC_DPSlave_DOKU_v10_e
1.1 Overview
Introduction
The PC is gaining ever increasing importance in the field of automation.
Being easily expandable with PCI plug-in cards, more and more tasks can
be solved with the PC. A special measuring card in a PC, for example, can
provide measured values for a controller. In this example, the PC works as
PROFIBUS DP Slave.
OPC DP Slave
1.2 Requirements
OPC DP Slave
OPC DP Slave
2 Automation Solution
Here you will find information on …
the solution selected for the automation task.
Display
The following figure displays the most important components of the
solution:
Figure 2-1
Copyright © Siemens AG 2005 All rights reserved
21040390_OPC_DPSlave_DOKU_v10_e
OPC DP Slave
OPC DP Slave
Display
The following figure displays the most important components of the
solution:
Figure 2-2
Copyright © Siemens AG 2005 All rights reserved
Setup
21040390_OPC_DPSlave_DOKU_v10_e
Control functionality
The following functionality for data transfer is executed cyclically:
• Simulation of two measured values.
• Writing measured values via the OPC server to the inputs of the slave.
The SIMATIC S7station fulfills the following functionalities:
• Copying the slave data into a data block.
• Generating an LED chaser with a frequency depending on the value
specified in the slave.
OPC DP Slave
OPC DP Slave
Table 2-4
Component Note
21040390_OPC_DPSlave_STEP7_v10.zip This zip file contains the STEP 7
project (incl Hardware
configuration for PC station and
S7-300).
21040390_OPC_DPSlave_CODE_v10.zip This zip-file contains the
executable files for the OPC
client as well as the Visual C++
project.
21040390_OPC_DPSlave_DOKU_v10_d/e.pdf This document
data transfer with simulation of the measured values and writing the
21040390_OPC_DPSlave_DOKU_v10_e
Note The measurement is only to show the relationship between the different
languages. The absolute cycle time cannot be guaranteed on a PC.
Measured data
The following table shows the cycle times of the data transmission with the
various programming languages, the Outproc OPC server and the
configuration from the example.
Table 2-5
Programming language Average cycle time
C++ 230 μs
C# 320 μs
Visual Basic V6.0 670 μs
OPC DP Slave
with • Restriction to 122 bytes input data and 122 bytes output data.
CP 5611 or
CP 5511
OPC DP Slave
Table 2-6
Decision criteria Inproc OPC Server Outproc OPC Server
Speed ++ +
Number of connected clients 1 n
Client and server on different computers No Yes
Visualization application + ++
Softnet CP5611 / CP5511 Yes Yes
Average cycle time of data transmission in 145 μs 230 μs
the C++ example without pause times.
OPC DP Slave
Note
A PROFIBUS DP Slave can provide a maximum of 244 bytes of input
data and 244 bytes of output data. This is the maximum data amount that
can be exchanged between PC and SIMATIC S7 station.
Copyright © Siemens AG 2005 All rights reserved
21040390_OPC_DPSlave_DOKU_v10_e
OPC DP Slave
Content
Discusses the detailed function processes of the involved hardware and
software components, the solution structures, and where sensible the
concrete implementation of this application.
Read this part if you want to know how the individual solution components
interact.
General information
When dividing the PROFIBUS nodes, it is generally distinguished between
active and passive stations. The network access corresponds to the "Token
bus" method for active and the ”Master–Slave” method for passive stations
established in the EN 50170, Volume 2. The access method is independent
of the used transfer medium (two-wire line, fiber optics and plastic fibers)
and depending on the components used, it can be operated with
transmission speeds of 9.6 KBit/s up to 12MBits/s. A total of 126 nodes
(including Master) can be operated at one PROFIBUS. The bus segment
lengths vary between 1km and 100m depending on the transfer speed and
are if necessary connected or expanded with repeaters.
PROFIBUS network configurations are distinguished between single and
multi-master according to the number of active stations operated at a
PROFIBUS network. Furthermore it is distinguished between class 1 and
class 2 or "non-DP“ masters (e.g. FMS) according to the functionality of this
station. Mixed configuration is also possible on the same physical line.
OPC DP Slave
tools. Furthermore there are three additional interrupt types: Status, update
and a manufacturer specific interrupt.
DPV2 is the last development stage and defines additional functionality,
particularly for drives and axis control e.g. isochronous slave operation,
slave to slave cross-communication, any kind of up and download of data,
as well as clock synchronization.
PROFIBUS Slave
DP slaves of different manufactures are marked according to the functions
(DPV0 to DPV2) they support. Slaves, which support the basic functionality
are also referred to as DP standard slaves, and are described by a
standardized file (so-called GSD file). This enables uniform configuration of
slaves from different manufacturers. Many Siemens Slaves have special
functions exceeding the PROFIBUS standard, and which can only be used
in conjunction with S7 masters (the master is an S7-300 or S7-400). If the
PC cards CP 5611, CP 5613/14 are used as master, S7 slaves can only be
used as standard slaves, which makes special functions unavailable.
OPC DP Slave
Overview
The OPC Foundation (an interest grouping of well-known manufacturers for
the definition of standard interfaces) has in recent years defined a number
of software interfaces, in order to standardize the information flow from
process level to management level. Four different OPC specifications have
evolved according to the different requirements within an industrial
application. Data Access (DA), Alarm&Events (A&E), Historical Data
Access (HDA) and Data eXchange (DX). Access to process data has been
described in the DO specification; A&E describes an interface for event
based information including acknowledgement; HAD describes functions for
archived data and DX defines a server to server cross-communication.
This example deals exclusively with the OPC Data Access 2.05a interface.
Detailed documentation available on the SIMATIC NET CD-Rom. Further
information is available at www.opcfoundation.org.
What is OPC
OPC is a collection of software interfaces for data exchange between PC
applications and process devices. This software interface has been defined
according to the rules of Microsoft COM (Component Object Model) and
can therefore easily be integrated into Microsoft operating systems. COM
or DCOM (distributed COM) provides the functionality fo the inter process
communication and organizes the information exchange between
applications even beyond computer boundaries (DCOM). An OPC client
(COM client) can exchange information with an OPC server (COM Server)
with it, using mechanisms of the Microsoft operating system.
The OPC server provides process information of a device at its interface.
The OPC client starts the server and can access the offered data.
OPC DP Slave
Note If the client is located on a different computer than the server and
accesses the data "remotely", this is referred to as a DCOM connection.
If a client connects with an Inproc OPC server, the OPC server DLL is
21040390_OPC_DPSlave_DOKU_v10_e
loaded into the process of the client (In Process). This is the fastest variant,
as for calls, no process boundaries need to be overcome. For a connection
to an Outproc OPC server, the server will be started by COM in a separate
process. The communication between both processes, however, runs via
COM mechanisms. In this second variant, OPC client and OPC server can
be started on separate computers. The process or computer boundary is
illustrated in figure 3-2 as broken line.
The OPC server is started with a name (ProgID). This ProgID is for the
PROFIBUS DP Inproc OPC server “OPC.SIMATICNET.DP“. The ProgID
of the Outproc Servers is “OPC.SIMATICNET“.
Note The PROFIBUS DP Inproc server can only be loaded into one OPC client
process. If the OPC server is to be used by several OPC clients, or if the
OPC client is to access the OPC server remotely, the Outproc OPC
server must be used.
OPC DP Slave
Variants
The following figure illustrates the different variants with Inproc and Outproc
OPC server and OPC clients which are using the custom or automation
interface.
Protocol layer and driver layer have been simplified. The architecture is
explained in greater detail in the following chapter.
Figure 3-2
Copyright © Siemens AG 2005 All rights reserved
21040390_OPC_DPSlave_DOKU_v10_e
Overview
For each protocol supported by Siemens, the SIMATIC NET OPC server
family offers an Outproc OPC server particularly suitable for visualization
applications. Supported are the S7 protocol via Ethernet and PROFIBUS,
Send/Receive, PROFIBUS DP-Master, DP-Slave, FDL, FMS and SNMP.
Additionally, an Inproc OPC server for fast control applications is offered for
PROFIBUS DP Master.
OPC DP Slave
This explains the basics of OPC Data Access (DA) necessary for the
example.
OPC DP Slave
1
2
3
Copyright © Siemens AG 2005 All rights reserved
21040390_OPC_DPSlave_DOKU_v10_e
Structure of ItemID
The ItemID (e.g. DP:[CP 5611]SlaveM00_IB0) is composed of the protocol
ID, the connection name, slave, module number and I/O address.
DP:[<connection name>]Slave M<number>_<I/O address>
The address space is only defined by the configuration of the OPC server.
The OPC client has no influence on this address space.
OPC DP Slave
The OPC client can only access OPCServer objects which it has created
itself. It cannot access objects of other OPC clients. This also applies to the
groups described below.
OPC Item
Apart form the process value, an OPC item also has further properties.
Aside from the value, this is also the quality of the value, the time stamp of
the value, the data type of the item and the access privileges. On top of
these properties, which each item must have, further information on the
process value can be available via additional properties such as unit of the
value or value range.
OPC DP Slave
The properties value, quality and time stamp are provided when reading the
process value. Further properties can be polled via an interface of the
server object.
Note The address space of the server is defined by the configuration and
cannot be changed by the OPC client.
The server and group objects are created and managed by the OPC
client in the OPC server. These objects are only visible for an OPC client
and have no impact on the address space.
OPC DP Slave
cache is not affecting the data exchange between OPC server and device.
21040390_OPC_DPSlave_DOKU_v10_e
In this example the process image of the inputs are read from the device. In
this example, this is not a problem, as the device for storage is the CP5613,
in which the process image of the slaves has been stored. This makes the
access to the data very fast, and the latest values for the process image of
the controlling process are always available.
Group calls
All methods at group objects affecting the items, are group calls, i.e., one
call can add for example 1000 items to the group or read 500 items within
the group. This can help minimize the number of calls to the OPC server.
Processing data within the OPC server is optimized, particularly writing and
reading from the device. In this case the OPC server can better optimize
OPC DP Slave
number and size of the data packages to the device than reading or writing
the values individually.
Copyright © Siemens AG 2005 All rights reserved
21040390_OPC_DPSlave_DOKU_v10_e
OPC DP Slave
The OPC client application shows two different application options of OPC
and its realization in a C++ application.
• One application is visualizing process values via OPC Data Access.
Here it is illustrated which OPC DA functionality is required for display
and writing of process values, and how they are used in C++.
• The main application is the provision of I/O user data in form of a DP
slave for a SIMATIC S7 station as DP master. It is to demonstrate the
performant and cost-effective incorporation of a PC into a SIMATIC
Copyright © Siemens AG 2005 All rights reserved
OPC DP Slave
The data provided by the PC can origin from an intermediate storage, e.g.
from a measuring card in the PC or the OPC client process. In this example
such data is simulated and cyclically written into a separate thread into the
OPC server.
In this part of the example it is shown how an own thread for the data
transmission is started, and how the OPC server is ideally initialized for
this.
After initializing the OPC server, the data transfer is executed cyclically and
the values are written to the OPC server.
The functionality to the data transfer shows exemplary how values can be
set. The following measured values are simulated for this:
• Measured value for input Real 8 is simulated as ramp function.
• Measured value for input Real 12 is simulated as sinus function.
Note The values provided by the simulation function can be replaced by any
user data.
OPC DP Slave
Note In the slave inputs are written and outputs are read as the names refer to
the view of the master.
Table 4-1
Visualizing Transfer
Data
ItemID Name Data OPC PAA PAE
Type
User interface Change Write Read Write
DP:[CP 5611]SlaveSlvState STRING Slave State X
DP:[CP STRING Slave Config X
5611]SlaveMiscReadSlvParCfgData Data
DP:[CP 5611]&devicestate() STRING Device State X X
Copyright © Siemens AG 2005 All rights reserved
21040390_OPC_DPSlave_DOKU_v10_e
OPC DP Slave
ItemID column
The item ID is made up of:
• DP for the protocol,
• CP 5611 as connection name,
• M00 to M01 for the Slave module,
• I for input and Q for output, REAL and X for the data types Real and
Bool and the byte address in the input are or output area respectively.
Visualizing column
The visualizing column specifies in which element of the user interface the
value of the item is displayed and which OPC functionalities are used. The
name of the user interface elements does not refer to the slave modules.
Copyright © Siemens AG 2005 All rights reserved
numbered.
• Data Change – the OPC group for visualizing is active and all value
changes are reported from the OPC server to the OPC client..
• OPC Write – These output values can be written from the surface.
Transfer column
The Transfer column specifies which items in the thread are used for data
transmission.
• In this example, no outputs (PIQ - Process Image Outputs) are read
from the OPC server However, the functionality exists and may be used
on demand.
Note This may become necessary when the DP master writes control data into
the DP slave, which in return must set its PIQ.
• The OPC items for the PII (process image inputs) or the inputs
respectively are written via an inactive group.
Note The result of this is that – as specified in 3.4.1 – certain process variable
are depicted twice in different groups on different OPC items. This makes
the different application purposes apparent.
OPC DP Slave
4.2.1 Overview
The following figure shows the function blocks in the OPC client and the
interaction with the objects in the OPC server.
Figure 4-2
Copyright © Siemens AG 2005 All rights reserved
21040390_OPC_DPSlave_DOKU_v10_e
No. Description
1 When connecting the user interface with the OPC server, an OPC server object and
an active OPCGroup object is created in the server, and a callback connection
established. The accesses to the OPC server are encapsuled in the client with an
OPC management.
2 In the active group, the cache is cyclically updated with values from the driver of the
CP5611. If the values have changed, they are sent to the OPC client via the callback
connection.
3 If specified values are written in the user interface, then the CP5611 is written to via
the OPC management.
4 Connecting with the OPC server generates a separate thread in which a separate
connection with the OPC server is established with an inactive group. After this
initialization, the measured data are simulated cyclically and written to the memory of
the inputs.
5 The memory of the inputs is written to the device (CP 5611) via the OPC
management and the group in the server.
OPC DP Slave
reading the values from the CP 5611. If the value of an OPC Item
21040390_OPC_DPSlave_DOKU_v10_e
changes within the UpdateRate, the changed values are sent to the
user interface via the Callback connection.
Two cycle times can be set within the application. The setting is made via
the ServerDefines.h file in the source code.
OPC DP Slave
Subject to fluctuation
Cycle time
Fixed time
This chapter explains the static structure of the OPC client using an UML
class diagram. The dynamic sequences are explained in chapter 7 using
sequence diagrams.
The dynamic sequences are explained in chapter 5 using sequence
diagrams.
The following class diagram shows the classes used in the OPC client and
their relations. The following pages explain the individual classes, whereby
only the most important tasks and methods are explained. For a complete
list, please refer to the well commented source code.
OPC DP Slave
Figure 4-4
Copyright © Siemens AG 2005 All rights reserved
21040390_OPC_DPSlave_DOKU_v10_e
OPC DP Slave
Overview
The following table gives an overview of the C++ classes and classifies
them according to task and reusability. The classes have been
implemented with support of the C++ class library MFC (Microsoft
Foundation Classes).
The class names correspond to the file names of the files which contain the
source code for the implementation.
Table 4-3
Class Task Reusability
CUserInterface User interface Generated individually for this application.
COPCItemMgt User interface Generally usable, however, must be adapted.
CDataCopy Data transfer Allgemein für Datentransfer verwendbar.
CMemoryMapSlave Data transfer Modifications necessary for size of the process
image.
CThread Data transfer Usable as basis for separate thread.
Copyright © Siemens AG 2005 All rights reserved
Class CUserInterface
• This class implements the functionality of the user interface.
• CUserinterface is derived from the MFC class CDialog as well as the
CDataCallback interface. The data changes are reported to the user
interface via CdataCallback.
• The OnBtnClick methods are called by clicking the respective buttons in
the user interface.
Table 4-4
Method Functionality
OnBtnConnectClick Setup of connection to OPC server and activating the Callback
connection. An instance of COPCServerMgt and COPCGroupMgt is
created respectively.
Starting the data transfer. This creates an instance of the CdataCopy
class and the thread for executing the control functionality in the
object is started.
OnBtnDisconnectClick Terminating the data transfer.
Disconnecting from the OPC server.
OnBtnWriteAIClick Manual writing of input values.
OnBtnWriteDIClick
DataChange Receiving the value changes from the OPC server and writing the
values into the user interface elements.
OPC DP Slave
Class COPCItemMgt
This class manages all information on an OPC item required in the user
interface. This information consists of Server Handle, ItemID, ControlID,
value and data type of the item. The Server Handle is provided by the
server at AddItems and is required for all calls at the group such as Read,
Write and RemoveItems. ControlID writes a new value into the respective
element of the user interface.
Note The CUserInterface contains a list of the OPCItemMgt objects and saves
all information on the items. The index of this list is the client handle of
the item, which in AddItems is transmitted to the OPC server and is
provided by the OPC server at OnDataChange.
Any amount of information can be added without changing the access
mechanism.
Class COPCServerMgt
Copyright © Siemens AG 2005 All rights reserved
simplified access to the COM object via C++ methods with MFC data types.
Table 4-5
Method Functionality
ConnectOPCServer Setting up a connection to the OPC server by transfer of ProgID.
DisconnectOPCServer Disconnecting from the OPC server.
AddGroup Generating a group. AddGroup requires previously generating and
transmitting an OPCGroupMgt object.
RemoveGroup Removing a group. Requires deleting the OPCGroupMgt object prior
to the call.
Class COPCGroupMgt
The COPCGroupMgt encapsules the OPC object OPCGroup and simplifies
access to the COM object.
Table 4-6
Method Functionality
AddItems Hinzufügen von Items zur Gruppe.
RemoveItems Removing items from the group.
Read Reading values, quality and time stamp of the items in the group.
Write Writing new values to the items in the group.
ConnectCallback Activating the Callback. A pointer needs to be transmitted to the
IDataCallback interface. It is required for initializing the Callback
object OPCDataCallback.
DisconnectCallback Deactivating the Callback.
OPC DP Slave
Class COPCDataCallback
This class implements the OPC interface IOPCDataCallback. Realizing the
COM functionality is derived from the ATL (Active Template Libary) class
CComObjectRoot. The OPC server sends the Callbacks to the OPC client
via IOPCDataCallback interface.
Table 4-7
Method Functionality
Initialize Initializes the object with a pointer to the CDataChange interface in
this example implemented by CUserInterface.
OnDataChange Is called by the OPC server if the values of the items within the group
have changed. Forwards the call to the user interface.
Class CDataCallback
This interface class has only an abstract DataChange method which must
be implemented by the derived class. In this example this method is
implemented by CUserInterface.
Copyright © Siemens AG 2005 All rights reserved
21040390_OPC_DPSlave_DOKU_v10_e
Class CThread
CThread manages a thread an enables starting and stopping this thread.
Table 4-8
Method Functionality
StartThread Starting a new thread.
ThreadEnter Is called at the beginning of the new thread. Can be overwritten by the
derived class.
DoWork This abstract method must be implemented in the derived class and is
the starting point for the functionality to be executed in the thread.
ThreadLeave Is called at the end of the thread. Can be overwritten by the derived
class.
StopThread Stops the thread. An event is sent to the thread for it.
OPC DP Slave
Class CDataCopy
Class CDataCopy is derived from CThread and implements the data
transfer and the simulation of the measured values. Both functionalities are
executed cyclically in the separate thread.
Table 4-9
Method Functionality
ThreadEnter Overwrites the method of the base class. In this method the OPC
connection is initialized.
DoWork In this method the data transfer is executed in a loop until the thread is
terminated.
ReadMemoryMap In this method the output image is read from the OPC server and
stored in MemoryMap.
WriteMemoryMap Here the input image is taken from the MemoryMap and written into
the OPC server.
SimulateData In this method, the simulation of the measured values is implemented
Copyright © Siemens AG 2005 All rights reserved
ThreadLeave Overwrites the method of the base class. In this method the OPC
connection is terminated.
Note In the data transfer, no values are read off the OPC server.
If values read from the OPC server are to be used in data processing,
ReadMemoryMap must also be called in DoWork.
See also chapter 6.1.
Class CMemoryMapSlave
CMemoryMapSlave manages the image of the inputs and the outputs of
the slave during a cycle.
Table 4-10
Method Functionality
WriteOutput This method enables writing data, read by the OPC sever, into the
MemoryMap.
ReadInput This method enables reading the simulated values from MemoryMap,
in order to write them into the OPC server.
GetOut This method enables accessing the individual input variables in the
simulation.
SetIn This method enables accessing the individual output variables in the
simulation.
OPC DP Slave
OPC DP Slave
Explanation
Table 5-1
No. Description
1 Clicking "Connect“ calls the OnBtnConnectClick method at the UserInterface object. In
this method, the connection to the OPC server is established and initialized.
2 In OnBtnConnectClick an instance of the COPCServerMgt class is created. This object
OPCServerMgtUI manages the connection to the OPC server. For establishing the
connection, ConnectOPCServer is called at this object.
3 Creating an instance of the COPCGroupMgt class in which the group is managed. The
OPCGroupMgtUI object is transferred in the AddGroup method to the OPCServerMgtUI
object, where from this object the properties of the group are taken for the AddGroup call
to the OPC server. After the AddGroup at the OPC server the OPCGroupMgtUI object is
initialized with the return values of the OPC server.
4 For including the items into the group, the necessary item information is filled into lists in
the BuildItemArrays method. This information consists of ItemID, desired data type, client
handle and ID of the user interface element. With these lists AddItems is called at the
OPCGroupMgtUI group management.
Copyright © Siemens AG 2005 All rights reserved
5 After adding the item the list of the OPCItemMgt management objects for the items is
21040390_OPC_DPSlave_DOKU_v10_e
created. Thereby, the OPCItemMgt objects are initialized with the information from the
BuildItemArrays and the server handles delivered by the OPC server. The index of the list
corresponds to the client handles transmitted to the OPC Server at AddItems.
6 Structure of the Callback connection to the OPC server. The OPC server sends data
changes to the OPC client via this connection. At ConnectCallback a pointer of the
CDataCallback type is transmitted to the instance of CUserInterface. In ConnectCallback
an instance of COPCDataCallback is generated. With this object the Callback connection
to the OPC server is subsequently initialized.
7 After generating an instance of the CdataCopz class, SartThread is called at this instance.
An own thread is started in which the measured data are cyclically written into the OPC
server.
Details see sequence diagram "Starting the data transfer“ in chapter 5.2.
OPC DP Slave
OnDataChange Callback
The OnDataChange Callback is called by the OPC server, as soon as the
value of one or several items has changed within the update time of the
Copyright © Siemens AG 2005 All rights reserved
Figure 5-3
Explanation
Table 5-2
No. Description
1 The OPC server calls the OnDataChange method at the Callback object
OPCDataCallback. Here the transmitted data are packed into MFC lists and passed on
to the UserInterface object via the DataChange method.
2 In UserInterface the changed values are processed in a loop. The ID of the user
interface element to which the value is to be written is thereby determined via the client
handle. The client handle is the index of the list of the OPCItemMgt objects. With the ID
read from OPCItemMgt the value is written into the user interface element with the
SetDlgItemText method. The new value is also written in OPCItemMgt via SetValue.
OPC DP Slave
1
2
3
Copyright © Siemens AG 2005 All rights reserved
4
21040390_OPC_DPSlave_DOKU_v10_e
OPC DP Slave
Explanation
Table 5-3
No. Instructions
1 Clicking "Connect“ calls the OnBtnConnectClick method at the UserInterface object
(see sequence diagram "Establish connection to the OPC Server“ in chapter 5.1).
In this method an instance of the CDataCopy class is generated and the StartThread
method called at the CDataCopy object.
2 The statistical method Run and the object pointer of DataCopy are transmitted to the
new thread. This calls the statistical method run in the new thread in which the
ThreadMain method can then be called at the DataCopy object via the object pointer.
This functionality for starting the thread with a method of the object has been
implemented in the CThread base class.
3 ThreadEnter is then first called in the ThreadMain method. The method can be
overwritten from the derived class in order to perform initializations. Here the connection
to the OPC server is established in the ThreadEnter method.
4 For connecting with the OPC a new instance of the COPCServerMgt class is generated
and the connection established via ConnectOPCServer. Subsequently an instance is
Copyright © Siemens AG 2005 All rights reserved
AddGroup call. In this method, the properties of the group are read and AddGroup is
then called at the OPC server with these parameters. The OPCGroupMgt object is then
initialized with the return value of AddGroup.
5 After adding the group the items for the process image are then added. The server
handles delivered by the OPC server are stored in a list.
6 Creating and initializing an instance of the CMemoryMapSlave class for managing the
process image.
7 Calling the DoWork method in which the actual functionality of the thread is processed.
Here the data transfer is executed in a loop until the application is terminated.
Processing the data transfer in a loop is illustrated in the following sequence diagram.
OPC DP Slave
2
Simulation
measured values
Copyright © Siemens AG 2005 All rights reserved
21040390_OPC_DPSlave_DOKU_v10_e
3 Writing
inputs
Explanation
Table 5-4
Nr. Aktion
1 The DoWork method is called after starting the thread. (See previous sequence diagram).
In this method the data transfer is executed in a loop until the thread is terminated.
2 In the SimulateData method, the measured values are simulated. The access to the
process image is thereby made via the SetInX method for the inputs. Thereby each data
type has its own Set And Get method. GetOutBool for example enables accessing
individual output bits or SetInFloat accessing an individual word. In the example
implementation, both measured values are simulated with a ramp function and a sinus
function and are written to the respective input value.
3 At the end of the cycle, the image of the inputs is written via the WriteMemoryMap
method. The values of the outputs are read from the MemoryMapSlave object with the
ReadInputs method and written to the OPC server via the OPCGroupMgt object.
Note The pause time at the end of a cycle (at the end of the while loop) is
realized by the Windows system call MsgWaitForMultipleObjects.
OPC DP Slave
• The error flag is checked for changes after each cycle run.
At every change of the error flag a message with the new status is sent to
the user interface.
OPC DP Slave
interface.
21040390_OPC_DPSlave_DOKU_v10_e
3 Analog Input / Output ItemIDs of the analog input and output items.
4 Bit Input / Output ItemIDs of the binary input and output items.
5 Simulation Function OPC Server ProgID, cycle time of simulation function
and ItemIDs of the input and output variables for the
process image.
OPC DP Slave
Application Wizard.
4 Copy the files The files can be taken from the delivered sample
opcda.h, project or be obtained directly from the website of the
opcda_i.c, OPC Foundation (www.opcfoundation.org).
opccomn.h,
opccomn_i.c,
opcerror.h
into the project directory.
OPC DP Slave
files (*.c).
21040390_OPC_DPSlave_DOKU_v10_e
Note The OPC interface can be used project wide in every Code file which
contains the reference #include “stdafx.h“.
OPC DP Slave
If the OPC classes from the example for encapsulating the OPC interface
are being used, the following steps are necessary.
Table 6-4
Nr. Aktion Anmerkung
1 Copy the following files into the OPCServerMgt.cpp, OPCServerMgt.h,
project directory: OPCGroupMgt.cpp, OPCGroupMgt.h,
OPCDataCallback.cpp, OPCDataCallback.h,
DataCallback.h.
2 Add copied files to the project. Procedure see no.5 and no.6 in Table 6-3.
#include <afxtempl.h>
3 Open the stdafx.h file via the typedef CArray<VARIANT, VARIANT&> CVARIANTArray;
Solution Explorer with a double-
Copyright © Siemens AG 2005 All rights reserved
5
Click C++ Æ ATL as category
on the Add Class dialog, and
select Add ATL Support To
MFC as template.
Pressing the Open button adds
the STL Support to the project.
OPC DP Slave
Content
This part leads you step by step through the structure, important
configuration steps, commissioning and operation of the application.
Hardware configuration
The hardware components are available in chapter .
For the hardware setup please proceed according to the following table:
Table 7-1
No. Focus Instructions
1 PC station Install the PCI plug-in card CP 5611 into the PC station according to
the attached manual /6/.
2 SIMATIC S7 Set up the controlling according to the figure in chapter 2.1.
station
3 PROFIBUS Connect the PC station with the SIMATIC S7 station analog to the
figure in chapter 2.1.
OPC DP Slave
Software
The software components are available in chapter .
Commissioning the example requires the following components from
SIMATIC NET CD V6.2:
• SIMATIC NET PC products
• SIMATIC NCM PC/S7 (not together with STEP 7)
Note SIMATIC NCM PC/S7 needs only be installed if no STEP 7 has been
installed on the PC.
Note During the installation of Visual Studio .Net the safety settings of the
21040390_OPC_DPSlave_DOKU_v10_e
OPC DP Slave
Note The STEP 7 project delivered with this example contains the completely
configured SIMATIC S7 station with control program. This project can
only be used without adjustment if the hardware is identical with the
configuration.
Manager.
3 Select station SIMATIC 315-2DP
and load station into controller.
The access point S7ONLINE
used by STEP 7 must have been
switched for loading the S7
station.
OPC DP Slave
Note The project file (XDB) delivered with this example contains the completely
configured PC station. This file can only be used without adjustment if the
hardware is identical with the configuration.
The configuration for deviating hardware is available in chapter 8.2.
Table 7-3
No. Instructions Note
1 Open the Station Manager
by double-clicking the icon in
the task bar.
3 Select the XDB file The XCB file is available in the XDBs sub-directory of
the extracted ZIP-file.
4 After importing the XDB file the
PC station has been configured.
The user interface and the source code of the application are delivered as
ZIP file.
For installation of the OPC client extract the
21040390_OPC_DPSlave_CODE_v10.zip file in to any directory.
OPC DP Slave
8 Configuration
Here you will find information on …
the configuration steps necessary if the hardware deviates from the
hardware used in the example.
Configured mode.
OPC DP Slave
Computername).
21040390_OPC_DPSlave_DOKU_v10_e
OPC DP Slave
connecting as DP Slave is in
this case the OPC Server.
The Station
Configurator shows the
current state of the SIMATIC
PC Station.
Starting with the icon in
the taskbar.
The diagnostic message in the
Station Configurator
indicates incorrect loading.
OPC DP Slave
OPC DP Slave
OPC DP Slave
been connected.
OPC DP Slave
The OPC Scout is a Standard OPC Client, contained in the delivery scope
of SIMATIC NET and can be used as Test client. The correct function of the
OPC-DP server is verified below.
Table 8-4
No. Instructions Note
1 Starting the OPC Scout. Start Æ SIMATIC Æ SIMATIC NET ÆPROFIBUS Æ
CP5613_CP5614 Æ OPC Scout
2 Connecting with the OPC During the connecting process, the OPC server is started
server OPC.SIMATICNet (this also starts the DP slave) and only then is the slave
with double-click. ready to answer to the configuration telegram. The bus
error LED of the master goes off it is switched from STOP
to RUN and re-initializes the PROFIBUS.
3 Creating a group. At least one group must be created. The OPC Scout
Copyright © Siemens AG 2005 All rights reserved
5 Displaying items and system The values of the items are now displayed in a list.
variables. In addition to the configured modules, the slave has the
so-called system variables.
Note When terminating the OPC client (here the OPC Scout) the OPC server
is also terminated. In the example configuration there will be no active DP
master at the PROFIBUS, therefore, as the DP master the S7 CPU
indicates a system/bus error . If no respective block has been
programmed (OB82) to processes this state, the control goes to stop
mode.
OPC DP Slave
OPC DP Slave
6
1
5 7
2 4
Copyright © Siemens AG 2005 All rights reserved
21040390_OPC_DPSlave_DOKU_v10_e
OPC DP Slave
10 Literature
This list is by no means exhaustive and only gives a selection of
appropriate sources. After SIMATIC NET product installation the manuals
are still in the documentation directory on the target computer at: Start Æ
SIMATIC Æ Documentation Æ [Language]
You can find the product support in the internet under:
http://support.automation.siemens.com
(There enter the entry ID into the search field).
Table 10-1
Topic Title
1 OPC Custom Interface, Interface description OPC Data Access 2.05a
On the documentation CD-Rom of SIMATICNET specification
Copyright © Siemens AG 2005 All rights reserved
www.opcfoundation.org
2 Manual about standards, topologies and devices as SIMATIC NET PROFIBUS-
well as installation guidelines. networks
On the documentation CD-Rom of SIMATICNET
In product support under the entry ID: 1172302
3 Description or information on: Commissioning of
• General information on the PC tools SIMATIC NET PC stations
– instruction and quick
• Functions of NCM PC
start for SIMATIC NCM PC
Installed by SIMATIC NET, see: Start Æ SIMATIC Æ / STEP 7 from version
Documentation Æ [Language] V5.2 and up.
In product support under the entry ID: 13542666
4 Manual for industrial communication on PG/PC with SIMATIC NET – Industrial
SIMATIC NET. Communication with
Installed by SIMATIC NET, see: Start Æ SIMATIC Æ PG/PC
Documentation Æ [Language]
In product support under the entry ID: 2044387
5