Upload
awanish-upadhyay
View
231
Download
0
Embed Size (px)
Citation preview
8/12/2019 Distributed Automation With the PC
1/65
Application for Communication
Distributed Automation with the PC
The SIMATIC NET OPC Server as PROFIBUS DP
Slave
Program Example in C++
8/12/2019 Distributed Automation With the PC
2/65
Warranty, Liability and Support
OPC-DP-Slave
V 1.0 Issue Feb.16th.2005 2/65
CopyrightS
iemensAG2
005Allrightsreserved
21040390_O
PC_
DPSlave_
DOKU_
v10_
e
Warranty, Liability and Support
We do not accept any liability for the information contained in thisdocument.
Any claims against us - based on whatever legal reason - resulting from theuse of the examples, information, programs, engineering and performancedata etc., described in this document shall be excluded. Such an exclusionshall not apply in the case of mandatory liability, e.g. under the GermanProduct Liability Act (Produkthaftungsgesetz), in case of intent, grossnegligence, or injury of life, body or health, guarantee for the quality of aproduct, fraudulent concealment of a deficiency or breach of a condition
which goes to the root of the contract (wesentliche Vertragspflichten).However, claims arising from a breach of a condition which goes to the rootof the contract shall be limited to the foreseeable damage which is intrinsicto the contract, unless caused by intent or gross negligence or based onmandatory liability for injury of life, body or health. The above provisionsdoes not imply a change in the burden of proof to your detriment.
The Application Examples are not binding and do not claim to be completeregarding the circuits shown, equipping and any eventuality. They do notrepresent customer-specific solutions. They are only intended to providesupport for typical applications. You are responsible in ensuring that thedescribed 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 ApplicationExamples, you recognize that Siemens cannot be made liable for anydamage/claims beyond the liability clause described above. We reserve theright to make changes to these Application Examples at any time withoutprior notice. If there are any deviations between the recommendationsprovided in these Application Examples and other Siemens publications -e.g. Catalogs - then the contents of the other documents have priority.
Copyright 2004 Siemens A&D. It is not permissible to transfer orcopy these Application Examples or excerpts of them without firsthaving prior authorization from Siemens A&D in writing.
For questions about this document please use the followinge-mail-address:
mailto:[email protected]:[email protected]8/12/2019 Distributed Automation With the PC
3/65
Foreword
OPC-DP-Slave
V 1.0 Issue Feb.16th.2005 3/65
CopyrightS
iemensAG2
005Allrightsreserved
21040390_O
PC_
DPSlave_
DOKU_
v10_
e
Foreword
Objectives of the application
The international OPC standard is an optimized interface for accessing theprocess 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 usedfor parallel visualizing in an application at the same time.
Ein PC kann als PROFIBUS DP-Slave eingesetzt werden, um z.B. Dateneiner PC Messkarte oder Rezeptdaten aus einer Datenbank einemPROFIBUS DP-Master zur Verfgung zu stellen.
In this application, particular emphasis is placed on maximum performanceand minimum resource consumption.
Main contents of this application
The following teaching materials are provided with this application:
Configuration of a PC station with OPC server.
Configuration of the OPC server as PROFIBUS DP Slave.
Background information on PROFIBUS DP and OPC Data Access 2.05.
Using the OPC Data Access Custom interface in a C++ application withVisual Studio .NET as development environment.
Realizing a data transfer in C++ on the PC:
Providing user data in a PROFIBUS DP Slave for a SIMATIC S7-station.
Writing the process image via OPC Data Access.
Reusable framework for providing user data on the PROFIBUS.
Realization of a visualization task with OPC and C++:
Monitoring the process variables via OPC Data Access.
Optimal OPC calls for minimum communication load.
Reusable OPC classes.
Realization of the data transfer and the visualization tasks in anapplication without negative mutual effects.
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.
8/12/2019 Distributed Automation With the PC
4/65
Foreword
OPC-DP-Slave
V 1.0 Issue Feb.16th.2005 4/65
CopyrightS
iemensAG2
005Allrightsreserved
21040390_O
PC_
DPSlave_
DOKU_
v10_
e
Structure of the document
The documentation of this application is divided into the following mainparts.
Part Description
Application Description Provides a general overview of the contents. You willlearn about the components used (standardhardware and software components and thespecially created software).
Function principles andprogram structures
Discusses the detailed function processes of theinvolved hardware and software components, the
solution structures, and where sensible the concreteimplementation of this application.
This part is necessary if you want to learn about theinteraction of the solution components, for examplein order to use them as the basis for owndevelopment.
Structure, Configurationand Operation of theApplication
This part leads you step by step through thestructure, important configuration steps,commissioning and operation of the application.
Appendix Here you find further information, such asbibliography, glossary etc..
Reference for Automation and Drives Service & Support
This entry originates from the internet application portal of the A&D Serviceand Support. The following link takes you directly to the download page ofthis document.
http://support.automation.siemens.com/WW/view/en/21040390
http://support.automation.siemens.com/WW/view/en/21040390http://support.automation.siemens.com/WW/view/en/210403908/12/2019 Distributed Automation With the PC
5/65
8/12/2019 Distributed Automation With the PC
6/65
Table of Contents
OPC-DP-Slave
V 1.0 Issue Feb.16th.2005 6/65
CopyrightS
iemensAG2
005Allrightsreserved
21040390_O
PC_
DPSlave_
DOKU_
v10_
e
8.3 Configuring the SIMATIC S7 station............................................................... 598.4 Testing with OPC Scout.................................................................................. 629 Operating the Application............................................................................ 63Appendix and List o f Further Li terature ................................................................... 6510 Literature ....................................................................................................... 65
8/12/2019 Distributed Automation With the PC
7/65
8/12/2019 Distributed Automation With the PC
8/65
Application Description
Automation Task
OPC DP Slave
V 1.0 Issue Feb.16th.2005 8/65
CopyrightS
iemensAG2
005A
llrightsreserved
21040390_O
PC_
DPSlave_
DOKU_
v10_
e
1.2 Requirements
Requirements for the automation task
The following requirements exist regarding PC based automation.
Integrated solution on a device.
Performant and inexpensive connection of a PC as distributed I/O.
Individually generated, slim and optimized visualization via aPROFIBUS DP Slave.
Apart from these requirements which are realized in this Getting Started,there are also further advantages which are useful during the realization on
the PC: Interaction with other PC applications such as data bases.
Load reduction for data traffic on the PROFIBUS by collecting and pre-processing data of different origin.
Simple integration into the company IT.
Requirements to data transfer:
Providing measured data from the memory of the PC in the PROFIBUSDP Slave for transfer to a SIMATIC S7-station.
Data transfer must not be affected by the operator actions at the userinterface.
Simulation of the measured data by means of an encapsulated function,in order to facilitate exchangeability.
Requirements for the visualization user interface:
Visualization of slave data
Writing entered values to the inputs. This enables manual writing ofuser data to the DP master.
Display of specific DP variables and diagnostic information.
Writing the DP slave status. Changing the status to offline is meant totrigger an error OB in the controller
The user interface must be operable despite of the data transfer.
Requirements to the cont rol program in the SIMATIC S7 station
Copying the user data from the slave into a data block.
Realizing an LED chaser with the frequency based on the valuespecified in the slave.
8/12/2019 Distributed Automation With the PC
9/65
Application Description
Automation Task
OPC DP Slave
V 1.0 Issue Feb.16th.2005 9/65
CopyrightS
iemensAG2
005A
llrightsreserved
21040390_O
PC_
DPSlave_
DOKU_
v10_
e
Requirements to the development environment and programming language:
Application of C++,
Development with Microsoft Visual Studio .NET.
Requirements for connecting the application to the process:
Connection via PROFIBUS DP as well as the SIMATIC NET OPCserver
Operating the OPC server as PROFIBUS DP slave.
Using the OPC Data Access Custom Interface V2.05.
Reading and writing of process variables.
Monitoring of process variables.
Reading and writing PROFIBUS DP specific variables and diagnosticinformation.
The main focus of this example is using the OPC server as PROFIBUS DPslave. The PC is integrated as distributed I/O in a DP master system.
8/12/2019 Distributed Automation With the PC
10/65
Application Description
Automation Solution
OPC DP Slave
V 1.0 Issue Feb.16th.2005 10/65
CopyrightS
iemensAG2
005A
llrightsreserved
21040390_O
PC_
DPSlave_
DOKU_
v10_
e
2 Automation Solution
Here you will find information on
the solution selected for the automation task.
2.1 Overview of complete solution
Display
The following figure displays the most important components of thesolution:
Figure 2-1
2.2 Descript ion of the core functionality
User interface of the OPC Client
Figure 2-2
8/12/2019 Distributed Automation With the PC
11/65
Application Description
Automation Solution
OPC DP Slave
V 1.0 Issue Feb.16th.2005 11/65
CopyrightS
iemensAG2
005A
llrightsreserved
21040390_O
PC_
DPSlave_
DOKU_
v10_
e
Functionality o f the user interface
The user interface of this application has the following functions:
Connecting to and disconnection from the OPC server and starting thedata transfer.
Displaying slave specific data and diagnostic information.
Writing the Slave State
Displaying the three slave modules.
Writing two default values and 8 bit. A default value is the frequency ofthe LED chaser in the controller.
8/12/2019 Distributed Automation With the PC
12/65
8/12/2019 Distributed Automation With the PC
13/65
Application Description
Automation Solution
OPC DP Slave
V 1.0 Issue Feb.16th.2005 13/65
CopyrightS
iemensAG2
005A
llrightsreserved
21040390_O
PC_
DPSlave_
DOKU_
v10_
e
The given FAQs are available on the A&D Support Homepage at
http://support.automation.siemens.com(Please enter the ID into the searchbox).
Table 2-1
Component No. MLFB / Order number Note
Industrial PC
SIMATIC Rack PC IL 40 S
1 6AG4 011-1CA21-0KX0 Configurator: seeFAQ ID 17128155
Communicationsprocessor
CP5611 for PROFIBUS,PCI CARD
1 6GK1 561-1AA00 In notebooks, aCP5511 can beused alternatively.
Hardware components of the SIMATIC S7 station
The DP master used is a SIMATIC S7 300 station, whose modules used forthis example are listed below.
Table 2-2
Component No. MLFB / Order number Note
PS307 5A 1 6ES7 307-1EA00-0AA0
CPU315-2 DP 1 6ES7 315-2AG10-0AB0 S7 CPU
SM374 1 6ES7 374-2XH01-0AA0 Simulation moduledigital 8x IO
Software components of the SIMATIC PC station
The SIMATIC PC station requires software components which are listed inthe following table. STEP 7 can also be operated on a separate PC (so-called Engineering Station).
Table 2-3
Component No. MLFB / Order number Note
STEP 7 V5.3 1 6ES7 810-4CC07-0YA5 For configuration ofthe DP master.
PROFIBUS SOFTNET-DP-Slave V6.2
1 6GK1 704-5SW62-3AA0 For using aCP 5611.
Microsoft Visual Studio.NET 2003 Professional
1 Order via youradministrator of theMicrosoft Homepage
(Optional) Only ifchanges at theexample code arenecessary.
Example files and projects
The following list contains all files and projects used in this example.
http://support.automation.siemens.com/http://support.automation.siemens.com/WW/view/DE/17128155http://www.microsoft.com/http://www.microsoft.com/http://support.automation.siemens.com/WW/view/DE/17128155http://support.automation.siemens.com/8/12/2019 Distributed Automation With the PC
14/65
Application Description
Automation Solution
OPC DP Slave
V 1.0 Issue Feb.16th.2005 14/65
CopyrightS
iemensAG2
005A
llrightsreserved
21040390_O
PC_
DPSlave_
DOKU_
v10_
e
Table 2-4
Component Note
21040390_OPC_DPSlave_STEP7_v10.zip This zip file contains the STEP 7project (incl Hardwareconfiguration for PC station andS7-300).
21040390_OPC_DPSlave_CODE_v10.zip This zip-file contains theexecutable files for the OPCclient as well as the Visual C++project.
21040390_OPC_DPSlave_DOKU_v10_d/e.pdf This document
2.4 Basic Performance Data
Frame condit ions for measured values
The times given in this chapter were measured on a PC with Pentium 4processor with 2.4 GHz. The given times always relate to a cycle of thedata transfer with simulation of the measured values and writing themeasured values to the inputs of the slave via OPC.
The "average cycle time" was determined from a total time of 1000 cycleruns. The variation range was not determined.
The pause time between the cycles were set to 0ms during measurement,
which corresponds to a processor load of 100%.See also chapter on cycle times.
Note The measurement is only to show the relationship between the differentlanguages. 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 theconfiguration from the example.
Table 2-5
Programming language Average cyc le time
C++ 230 s
C# 320 s
Visual Basic V6.0 670 s
8/12/2019 Distributed Automation With the PC
15/65
Application Description
Automation Solution
OPC DP Slave
V 1.0 Issue Feb.16th.2005 15/65
CopyrightS
iemensAG2
005A
llrightsreserved
21040390_O
PC_
DPSlave_
DOKU_
v10_
e
2.5 Alternative solutions
Here you will find information on
the existing alternatives for solving the automation task, and whichcharacteristics the alternatives have.
The solution realized in this example is respectively shaded in green.
Comparison Hardnet and Softnet -S7
Table 2-1
Component Description
Hardnet with
CP 5613
The CP 5613 cannot be operated as a PROFIBUS Slave.
Hardnet withCP 5614
Less CPU load, as the main functions are executed in the hardware.
The CP 5614 has two PROFIBUS interfaces and can simultaneously beoperated as master and slave.
244 bytes input data and 244 bytes output data.
SOFTNET-S7withCP 5611 orCP 5511
Favorable solution if the PC is to work as PROFIBUS slave only.
Restriction to 122 bytes input data and 122 bytes output data.
Direct comparison of programming languages
Table 2-2
Component Description
Visual BasicV6.0
The advantage of Visual Basic applications is simple handling of theOPC interface via the automation interface, and the quick applicationgeneration especially with the user interfaces.
The disadvantage of Visual Basic is the lower performance due to theVisual Basic runtime and the additional software layer with OPCAutomation DLL. Furthermore, several functionalities cannot beexecuted parallel, which reduces the performance of the control andvisualization task.
.NET langua-
ges C# andVisual Basic
Using the new Microsoft .NET platform enables quick and modern
application development. All advantages of .NET can be used. However, for accessing the OPC the performance is restricted due to
the .NET runtime and the application of an intermediate layer (RuntimeCallable Wrapper, RCW)
C++ The realization with C++ enables reaching the highest performance.Direct access to the interface of the OPC server is possible.Furthermore, any number of functionalities can be executed parallel.
The disadvantage of C++ is the higher expense for the implementationespecially for complex user interfaces.
8/12/2019 Distributed Automation With the PC
16/65
Application Description
Automation Solution
OPC DP Slave
V 1.0 Issue Feb.16th.2005 16/65
CopyrightS
iemensAG2
005A
llrightsreserved
21040390_O
PC_
DPSlave_
DOKU_
v10_
e
Direct comparison Inproc / Outproc OPC Server for solut ion estimation
The following points must be considered when selecting the OPC serverbetween In Process (OPC.SIMATICNET.DP) and Out of Process(OPC.SIMATICNET) (Detailed description in chapter 3.2):
Table 2-3
Component Description
Inproc OPCServer
Faster calls from OPC client to server as there is no process boundarybetween client and server.
The Inproc OPC server can only be loaded within a process, i.e. only aclient can connect to this server.
Outproc OPC
Server
The Outproc OPC server can be accessed from several applications.
Remote access to the Outproc OPC server possible.
Decision cri teria for selecting an Iproc / Outproc OPC server
The following table gives you an overview of the relevant features of anInproc and Outproc OPC server.
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 inthe C++ example without pause times.
145 s 230 s
Appl ication cases and restrict ions for a PC as PROFIBUS DP slave
Table 2-4
Appl ication case Descript ion
Provision of userdata for a SIMATICS7 station.
Measured data for specific PC measuring cards.
Pre-processing of measured values. Gateway for other bus systems.
Provision of recipes for example from a database.
Swapping out of complex calculations from a SIMATIC S7 stationto a PC.
Visualization via aPROFIBUS DPslave
Used analog to SIMATIC OperatorPanels or TouchPanels asPROFIBUS Slave.
Visualization of data which the master has copied into the outputarea.
Writing default values into the input area.
8/12/2019 Distributed Automation With the PC
17/65
Application Description
Automation Solution
OPC DP Slave
V 1.0 Issue Feb.16th.2005 17/65
CopyrightS
iemensAG2
005A
llrightsreserved
21040390_O
PC_
DPSlave_
DOKU_
v10_
e
NoteA 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 thatcan be exchanged between PC and SIMATIC S7 station.
8/12/2019 Distributed Automation With the PC
18/65
Function Principles and Program Structures
General Function Mechanisms
OPC DP Slave
V 1.0 Issue Feb.16th.2005 18/65
CopyrightS
iemensAG2
005A
llrightsreserved
21040390_O
PC_
DPSlave_
DOKU_
v10_
e
Function Principles and Program Structures
Content
Discusses the detailed function processes of the involved hardware andsoftware components, the solution structures, and where sensible theconcrete implementation of this application.
Read this part if you want to know how the individual solution componentsinteract.
3 General Function Mechanisms
Here you will find information on
the general function mechanisms applying regarding PROFIBUS and OPC.
3.1 Basics on PROFIBUS DP
PROFIBUS is the international standard for connecting I/O devices in thecell and process level. Some related terms are explained below.
Continuous information is available in the SIMATIC NET /2/ manual and atwww.profibus.com.
General information
When dividing the PROFIBUS nodes, it is generally distinguished betweenactive and passive stations. The network access corresponds to the "Tokenbus" method for active and the MasterSlave method for passive stationsestablished in the EN 50170, Volume 2. The access method is independentof the used transfer medium (two-wire line, fiber optics and plastic fibers)and depending on the components used, it can be operated withtransmission 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 segmentlengths 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 andmulti-master according to the number of active stations operated at aPROFIBUS network. Furthermore it is distinguished between class 1 andclass 2 or "non-DP masters (e.g. FMS) according to the functionality of thisstation. Mixed configuration is also possible on the same physical line.
http://www.profibus.com/http://www.profibus.com/8/12/2019 Distributed Automation With the PC
19/65
Function Principles and Program Structures
General Function Mechanisms
OPC DP Slave
V 1.0 Issue Feb.16th.2005 19/65
CopyrightS
iemensAG2
005A
llrightsreserved
21040390_O
PC_
DPSlave_
DOKU_
v10_
e
PROFIBUS Class 1 Master
The active stations of class 1 are PROFIBUS DP masters cyclically pollingtheir respectively assigned slaves and are also simply referred to as DPmaster. Several DP masters may be present at one bus (token passing),however, each master has to process a number of exclusively assignedslaves (a so-called master system). Which slaves are part of a mastersystem is defined in the configuration (type, address, data volume) and isverified by the master in the startup phase. In the course of time, the DPspecification has been expanded step by step and there are now threemain versions with different functionality.
DPV0 describes the underlying basic functionality, the cyclic datacommunication between a master and its slave, as well as station, module
and channel-specific diagnosis and four interrupt types e.g. diagnosis andprocess interrupt, or pulling and stretching of slaves.
DPV1 is an expansion of the DPV0 and describes acyclic services e.g. forparameter assignment, status display and interrupt control. DPV1 servicesof intelligent field devices are processed parallel to the cyclic datacommunication. This enables accessing stations online using engineeringtools. Furthermore there are three additional interrupt types: Status, updateand 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 Class 2 Master
Active stations of the class 2 type are typically stations fulfilling engineering,diagnostics or configuration tasks. During the commissioning phase theyare connected for maintenance or diagnostics purposes and can configuredevices, evaluate measured values or poll the device status. Class 2masters can be connected permanently or temporarily at a bus.
PROFIBUS Slave
DP slaves of different manufactures are marked according to the functions
(DPV0 to DPV2) they support. Slaves, which support the basic functionalityare also referred to as DP standard slaves, and are described by astandardized file (so-called GSD file). This enables uniform configuration ofslaves from different manufacturers. Many Siemens Slaves have specialfunctions exceeding the PROFIBUS standard, and which can only be usedin conjunction with S7 masters (the master is an S7-300 or S7-400). If thePC cards CP 5611, CP 5613/14 are used as master, S7 slaves can only beused as standard slaves, which makes special functions unavailable.
8/12/2019 Distributed Automation With the PC
20/65
Function Principles and Program Structures
General Function Mechanisms
OPC DP Slave
V 1.0 Issue Feb.16th.2005 20/65
CopyrightS
iemensAG2
005A
llrightsreserved
21040390_O
PC_
DPSlave_
DOKU_
v10_
e
Relationship Master - Slaves
The following figure shows the relationships between master class 1(cyclic) and master class 2 (acyclic), as well as different functions ofcommunication which can be supported.
Figure 3-1
3.2 Basics OPC
Overview
The OPC Foundation (an interest grouping of well-known manufacturers forthe definition of standard interfaces) has in recent years defined a numberof software interfaces, in order to standardize the information flow fromprocess level to management level. Four different OPC specifications haveevolved according to the different requirements within an industrialapplication. Data Access (DA), Alarm&Events (A&E), Historical DataAccess (HDA) and Data eXchange (DX). Access to process data has beendescribed in the DO specification; A&E describes an interface for eventbased information including acknowledgement; HAD describes functions forarchived 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. Furtherinformation is available at www.opcfoundation.org.
What is OPC
OPC is a collection of software interfaces for data exchange between PCapplications and process devices. This software interface has been definedaccording to the rules of Microsoft COM (Component Object Model) andcan therefore easily be integrated into Microsoft operating systems. COMor DCOM (distributed COM) provides the functionality fo the inter processcommunication and organizes the information exchange betweenapplications 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.
http://www.opcfoundation.org/http://www.opcfoundation.org/8/12/2019 Distributed Automation With the PC
21/65
Function Principles and Program Structures
General Function Mechanisms
OPC DP Slave
V 1.0 Issue Feb.16th.2005 21/65
CopyrightS
iemensAG2
005A
llrightsreserved
21040390_O
PC_
DPSlave_
DOKU_
v10_
e
OPC Custom and Automation interface
The OPC server offers its functions at the so-called Custom interface.Clients developed in the programming languages C, C++ or Pascal, canaccess this interface directly. The automation interface is included in thedelivery scope to enable access from Visual Basic applications. It is a DLLwhich compiles all calls between Visual Basic and the custom interface(wrapper). Figure 3-2 on the following page illustrates the correlations.
Note If the client is located on a different computer than the server andaccesses the data "remotely", this is referred to as a DCOM connection.
OPC Server as Inproc or Outproc COM objectCOM servers are divided into two types. At identical OPC interface a servercan be realized as In Process (Inproc) or Out Of Process (Outproc). Inprocare implemented as downloadable DLL and Outproc as executable file(EXE).
If a client connects with an Inproc OPC server, the OPC server DLL isloaded 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 connectionto an Outproc OPC server, the server will be started by COM in a separateprocess. The communication between both processes, however, runs viaCOM mechanisms. In this second variant, OPC client and OPC server can
be started on separate computers. The process or computer boundary isillustrated in figure 3-2 as broken line.
The OPC server is started with a name (ProgID). This ProgID is for thePROFIBUS DP Inproc OPC server OPC.SIMATICNET.DP. The ProgIDof the Outproc Servers is OPC.SIMATICNET.
Note The PROFIBUS DP Inproc server can only be loaded into oneOPC clientprocess. If the OPC server is to be used by several OPC clients, or if theOPC client is to access the OPC server remotely, the Outproc OPCserver must be used.
8/12/2019 Distributed Automation With the PC
22/65
Function Principles and Program Structures
General Function Mechanisms
OPC DP Slave
V 1.0 Issue Feb.16th.2005 22/65
CopyrightS
iemensAG2
005A
llrightsreserved
21040390_O
PC_
DPSlave_
DOKU_
v10_
e
Variants
The following figure illustrates the different variants with Inproc and OutprocOPC server and OPC clients which are using the custom or automationinterface.
Protocol layer and driver layer have been simplified. The architecture isexplained in greater detail in the following chapter.
Figure 3-2
3.3 SIMATIC NET OPC DP-Slave
Overview
For each protocol supported by Siemens, the SIMATIC NET OPC serverfamily 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 forPROFIBUS DP Master.
Architecture of dr iver layers
Prior to introducing the OPC interfaces, a C interface, the DP-Slave-Lib,was used for developing DP slave applications. The OPC server is basedon this interface. The functionality of the DP-Slave-Lib has been realized inDPV0 and DPV1. The following figure shows the differences betweenmaster and slave interfaces for Softnet (CP5611 und CP5511).
8/12/2019 Distributed Automation With the PC
23/65
Function Principles and Program Structures
General Function Mechanisms
OPC DP Slave
V 1.0 Issue Feb.16th.2005 23/65
CopyrightS
iemensAG2
005A
llrightsreserved
21040390_O
PC_
DPSlave_
DOKU_
v10_
e
in this example, the Outproc DP OPC server on the Softnet DP-Slave-Lib is
used, which makes a CP5611 or CP5511 obligatory. As opposed to anOPC server as DP master, the server is only configured as slave. If anOPC client connects via the ProgID OPC.SIMATICNET the server isstarted according to its configuration.
Overview of the driver layers
Figure 3-3
Note CP5611 or CP5511 can be operated as DP master or as DP slave.However, only one operating mode is possible at a time.
3.4 Using OPC Data Access
This explains the basics of OPC Data Access (DA) necessary for theexample.
3.4.1 OPC DA Data model
Address space of the OPC DA server
An OPC DA server provides an address space of available variables(items) defined in the configuration. This address space can be searchedby the OPC client. Most OPC servers display the items there in a treestructure.
Unique identification of an item in the address space occurs via an ItemID.As for a file in a file system, not the name of the item in the directory isunique, but the name and path in the address space.
8/12/2019 Distributed Automation With the PC
24/65
Function Principles and Program Structures
General Function Mechanisms
OPC DP Slave
V 1.0 Issue Feb.16th.2005 24/65
CopyrightS
iemensAG2
005A
llrightsreserved
21040390_O
PC_
DPSlave_
DOKU_
v10_
e
Address space of the OPC server
The figure shows the address space of the PROFIBUS DP OPC serverconfigured for the example using the example on hand. The folder structureis shown in the left hand pane of the window. The middle section of thewindow displays items of the selected folder M00_I with the input bytes ofthe module 00. The right hand section of the window shows the selectedinput and output variables of the slave with its ItemID.
Figure 3-4 Adressraum des PROFIBUS DP OPC Servers im OPC Scout
Explanation of the structure of the address space
The structure of the address space is explained in the following table.
Table 3-1 Ebenen der Baumstruktur
Level Description
1 The connection name is defined during configuration. In this exampleit is CP 5611.
2 The configured PROFIBUS DP slave.
3 The modules of the slave divided into inputs and outputs.
Structure of ItemID
The ItemID (e.g. DP:[CP 5611]SlaveM00_IB0) is composed of the protocolID, the connection name, slave, module number and I/O address.
DP:[]Slave M_
The address space is only defined by the configuration of the OPC server.The OPC client has no influence on this address space.
OPC Server object
When establishing a connection with the OPC DA server, COM object"OPCServer" is created which can be accessed via different COMinterfaces. Apart from administration functions, it mainly offers access toinformation on the address space, and enables creating and deleting ofgroups. In this example only the groups are created and deleted via this
object.
1
2
3
8/12/2019 Distributed Automation With the PC
25/65
Function Principles and Program Structures
General Function Mechanisms
OPC DP Slave
V 1.0 Issue Feb.16th.2005 25/65
CopyrightS
iemensAG2
005A
llrightsreserved
21040390_O
PC_
DPSlave_
DOKU_
v10_
e
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 thegroups described below.
Groups and items
The items of the OPC server must be grouped for data exchange via theCOM object "OPCGroup. Thereby the group settings apply to all items inthe group. The most important properties are hereby the active status andthe update rate. If the group is active, the OPC server forms anintermediate storage (cache) for values, quality and time stamp for itemswithin this group. The OPC server updates this cache respectively after theupdate time has elapsed.
An item represents a value within the process, it can be entered by theOPC client into several groups. Thereby the status of the item in the othergroups cannot be influenced. Only with writing a new value onto the itemdoes the value also change in the other groups.
Unless an item is contained in a group, no data exchange occurs betweenthe OPC server and the process.
Access structure on the process variables
The following figure illustrates the access structure with which you canaccess process variables via the OPC server.
Figure 3-4
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 ofthe value, the data type of the item and the access privileges. On top ofthese properties, which each item must have, further information on theprocess value can be available via additional properties such as unit of thevalue or value range.
8/12/2019 Distributed Automation With the PC
26/65
Function Principles and Program Structures
General Function Mechanisms
OPC DP Slave
V 1.0 Issue Feb.16th.2005 26/65
CopyrightS
iemensAG2
005A
llrightsreserved
21040390_O
PC_
DPSlave_
DOKU_
v10_
e
The properties value, quality and time stamp are provided when reading the
process value. Further properties can be polled via an interface of theserver object.
Note The address space of the server is defined by the configuration andcannot be changed by the OPC client.
The server and group objects are created and managed by the OPCclient in the OPC server. These objects are only visible for an OPC clientand have no impact on the address space.
3.4.2 OPC DA data access
Types of data access
The following figure gives an overview of the different types of data accessused in this example. The arrows symbolize the call direction.
Figure 3-5
Explanation of access types
The following table lists the access types illustrated in the figure above.
Table 3-2
No.
1 Polling information on the address space. (Not used in this example)
2 Reading the current values from the cache.
8/12/2019 Distributed Automation With the PC
27/65
Function Principles and Program Structures
General Function Mechanisms
OPC DP Slave
V 1.0 Issue Feb.16th.2005 27/65
CopyrightS
iemensAG2
005A
llrightsreserved
21040390_O
PC_
DPSlave_
DOKU_
v10_
e
3 Cyclic reporting of changed values from server to client.
4 Writing values. Call always goes to the device.
5 Cyclic updating of values in the cache of the OPC server. (UpdateRate)
Reading values of the items from cache or device
The items of a group can be read from the cache or from the device (deviceor process value directly at the source).
When reading from the cache, the communication between OPC serverand device is not affected. This communication to the device is mostly thebottleneck of data throughput between device and OPC client. Updating thecache can be optimized from the OPC server independently of the read
calls.Reading directly from the device takes as long until all values have beenread directly from the device. For a slow communication, this may takeseveral seconds. Reading from the device is recommended if the value isread in very irregular intervals only and therefore a cyclic update of thecache is not affecting the data exchange between OPC server and device.
In this example the process image of the inputs are read from the device. Inthis 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 theaccess to the data very fast, and the latest values for the process image ofthe controlling process are always available.
Reporting value changes
For applications in which the data must be updated cyclically in the OPCclient, there is a better mechanism than reading from the cache. In thiscase the OPC client can have the changed values sent to it after the updatetime of the group.
A typical application case is the visualization of process values. In order tobe able to receive the OnDataChange event from the OPC server, the OPCclient must implement a callback object with the IOPCDataCallbackinterface, and log on this object at the OPC server. This mechanism is usedin the example for visualizing.
Writing values to the OPC server
The values of the items of a group can also be written from the client. Bydefinition, writing is performed directly onto the device.
Group calls
All methods at group objects affecting the items, are group calls, i.e., onecall can add for example 1000 items to the group or read 500 items withinthe group. This can help minimize the number of calls to the OPC server.Processing data within the OPC server is optimized, particularly writing andreading from the device. In this case the OPC server can better optimize
8/12/2019 Distributed Automation With the PC
28/65
Function Principles and Program Structures
General Function Mechanisms
OPC DP Slave
V 1.0 Issue Feb.16th.2005 28/65
CopyrightS
iemensAG2
005A
llrightsreserved
21040390_O
PC_
DPSlave_
DOKU_
v10_
e
number and size of the data packages to the device than reading or writing
the values individually.
8/12/2019 Distributed Automation With the PC
29/65
Function Principles and Program Structures
Function Mechanisms of this Application
OPC DP Slave
V 1.0 Issue Feb.16th.2005 29/65
CopyrightS
iemensAG2
005A
llrightsreserved
21040390_O
PC_
DPSlave_
DOKU_
v10_
e
4 Function Mechanisms of this Application
Here you will find information on
the functionality offered by the OPC client, how PROFIBUS, OPC serverand OPC client function mechanism work together, and how this has beenrealized in a C++ class model.
4.1 Functionality of the OPC Client
The OPC client application shows two different application options of OPCand 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 displayand 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 DPslave for a SIMATIC S7 station as DP master. It is to demonstrate theperformant and cost-effective incorporation of a PC into a SIMATICstation as distributed, intelligent I/O.
User interface of the application
The following figure shows the user interface of the OPC client.
Figure 4-1
8/12/2019 Distributed Automation With the PC
30/65
Function Principles and Program Structures
Function Mechanisms of this Application
OPC DP Slave
V 1.0 Issue Feb.16th.2005 30/65
CopyrightS
iemensAG2
005A
llrightsreserved
21040390_O
PC_
DPSlave_
DOKU_
v10_
e
Functionality o f the user interface
The user interface serves for visualizing process values and thePROFIBUS DP status values. Here it is possible to connect to ordisconnect from the OPC server.
The input and output modules of the PROFIBUS DP slave are visualized asprocess values. Two of the four input values of the Real type and the inputbyte can be changed from the user interface and be written to the OPCserver as default value by clicking the button. The two further input valuesof the Real type are only displayed.
Furthermore, the online status of the DP slave can be used manually. Thishelps simulate a slave error. This manual offline setting of the slave is inthis example prevented by the error OB82 of the control program.
After establishing the connection with the OPC server, the status of the DPslave, the status value SlaveConfigData and the online status of theslave are displayed.
Functionality of data transmission
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 examplesuch data is simulated and cyclically written into a separate thread into theOPC 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 forthis.
After initializing the OPC server, the data transfer is executed cyclically andthe values are written to the OPC server.
The functionality to the data transfer shows exemplary how values can beset. 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 anyuser data.
8/12/2019 Distributed Automation With the PC
31/65
Function Principles and Program Structures
Function Mechanisms of this Application
OPC DP Slave
V 1.0 Issue Feb.16th.2005 31/65
CopyrightS
iemensAG2
005A
llrightsreserved
21040390_O
PC_
DPSlave_
DOKU_
v10_
e
Used OPC items
The following table lists the OPC items used for visualizing and in thesimulation.
Note In the slave inputs are written and outputs are read as the names refer tothe view of the master.
Table 4-1
Visualizing Transfer
ItemIDData
TypeName
User interface
Data
Change
OPC
Write
PAA
Read
PAE
Write
DP:[CP 5611]SlaveSlvState STRING Slave State X
DP:[CP5611]SlaveMiscReadSlvParCfgData
STRING Slave ConfigData
X
DP:[CP 5611]&devicestate() STRING Device State X X
DP:[CP 5611]SlaveM00_IREAL0,1 REAL Real 0 X X
DP:[CP 5611]SlaveM00_IREAL4,1 REAL Real 4 X X
DP:[CP 5611]SlaveM00_IREAL8,1 REAL Real 8 X X
DP:[CP 5611]SlaveM00_IREAL12,1 REAL Real 12 X X
DP:[CP 5611]SlaveM01_IX0.0,1 BOOL 16.0 Input X X
DP:[CP 5611]SlaveM01_IX0.1,1 BOOL 16.1 Input X X
DP:[CP 5611]SlaveM01_IX0.2,1 BOOL 16.2 Input X X
DP:[CP 5611]SlaveM01_IX0.3,1 BOOL 16.3 Input X X
DP:[CP 5611]SlaveM01_IX0.4,1 BOOL 16.4 Input X X
DP:[CP 5611]SlaveM01_IX0.5,1 BOOL 16.5 Input X X
DP:[CP 5611]SlaveM01_IX0.6,1 BOOL 16.6 Input X X
DP:[CP 5611]SlaveM01_IX0.7,1 BOOL 16.7 Input X X
DP:[CP 5611]SlaveM01_QX0.0,1 BOOL 0.0 Output X
DP:[CP 5611]SlaveM01_QX0.1,1 BOOL 0.1 Output X
DP:[CP 5611]SlaveM01_QX0.2,1 BOOL 0.2 Output X
DP:[CP 5611]SlaveM01_QX0.3,1 BOOL 0.3 Output X
DP:[CP 5611]SlaveM01_QX0.4,1 BOOL 0.4 Output X
DP:[CP 5611]SlaveM01_QX0.5,1 BOOL 0.5 Output X
DP:[CP 5611]SlaveM01_QX0.6,1 BOOL 0.6 Output X
DP:[CP 5611]SlaveM01_QX0.7,1 BOOL 0.7 Output X
8/12/2019 Distributed Automation With the PC
32/65
Function Principles and Program Structures
Function Mechanisms of this Application
OPC DP Slave
V 1.0 Issue Feb.16th.2005 32/65
CopyrightS
iemensAG2
005A
llrightsreserved
21040390_O
PC_
DPSlave_
DOKU_
v10_
e
Descrip tion of the table
The contents of the table are defined as follows:
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 andBool 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 thevalue of the item is displayed and which OPC functionalities are used. Thename of the user interface elements does not refer to the slave modules.As for an S7 control program, inputs and outputs are continuouslynumbered.
Data Change the OPC group for visualizing is active and all valuechanges 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 datatransmission.
In this example, no outputs (PIQ - Process Image Outputs) are readfrom the OPC server However, the functionality exists and may be usedon demand.
Note This may become necessary when the DP master writes control data intothe DP slave, which in return must set its PIQ.
The OPC items for the PII (process image inputs) or the inputsrespectively are written via an inactive group.
Note The result of this is that as specified in 3.4.1 certain process variableare depicted twice in different groups on different OPC items. This makesthe different application purposes apparent.
8/12/2019 Distributed Automation With the PC
33/65
Function Principles and Program Structures
Function Mechanisms of this Application
OPC DP Slave
V 1.0 Issue Feb.16th.2005 33/65
CopyrightS
iemensAG2
005A
llrightsreserved
21040390_O
PC_
DPSlave_
DOKU_
v10_
e
4.2 Function mechanisms of the OPC Client
4.2.1 Overview
The following figure shows the function blocks in the OPC client and theinteraction with the objects in the OPC server.
Figure 4-2
Explanation of the diagram
Table 4-2
No. Description
1 When connecting the user interface with the OPC server, an OPC server object andan active OPCGroup object is created in the server, and a callback connectionestablished. The accesses to the OPC server are encapsuled in the client with anOPC management.
2 In the active group, the cache is cyclically updated with values from the driver of theCP5611. If the values have changed, they are sent to the OPC client via the callbackconnection.
3 If specified values are written in the user interface, then the CP5611 is written to viathe OPC management.
4 Connecting with the OPC server generates a separate thread in which a separateconnection with the OPC server is established with an inactive group. After thisinitialization, the measured data are simulated cyclically and written to the memory ofthe inputs.
5 The memory of the inputs is written to the device (CP 5611) via the OPCmanagement and the group in the server.
8/12/2019 Distributed Automation With the PC
34/65
Function Principles and Program Structures
Function Mechanisms of this Application
OPC DP Slave
V 1.0 Issue Feb.16th.2005 34/65
CopyrightS
iemensAG2
005A
llrightsreserved
21040390_O
PC_
DPSlave_
DOKU_
v10_
e
Function mechanisms PROFIBUS
When starting the OPC server process, the CP 5611 becomes active asPROFIBUS DP slave and is thus included in the PROFIBUS cycle bythe DP master.
In each PROFIBUS cycle, the master updates the outputs at the slaveand reads the inputs from the slave.
Function mechanisms for the visualization user interface
The functionality of the visualization user interface is executed in themain thread of the C++ application.
During Connect an OPC management is created for the user interface.
An OPCServer object and an active OPCGroup object are generated inthe OPC DA server process via this OPC management. A callbackconnection is established for updating the values in the user interface.(OnDataChange)
The cache in the active group is cyclically (UpdateRate) updated byreading the values from the CP 5611. If the value of an OPC Itemchanges within the UpdateRate, the changed values are sent to theuser interface via the Callback connection.
Function mechanisms for the data transfer:
The data transfer functionality is executed in a separate thread.
After generating the new thread, an OPC management is created. AnOPCServer object and an inactive OPCGroup object are generated forthe data transfer in the OPC DA server process via this OPCmanagement.
The inactive group has no cache. This is not required as the read andwrite calls are directly executed from the device.
After the initialization, the measured data is written cyclically into theinputs of the slave in a loop. In each cycle, the simulated measuredvalues are copied to the process image of the inputs, and then theprocess image is written to the inputs of the slaves via OPC.
4.2.2 Cycle times
Two cycle times can be set within the application. The setting is made viathe ServerDefines.h file in the source code.
Update Rate of the data in the user interface
Standard value in the example is 250ms.
Using as UpdateRate of the OPC group.
Values smaller than 100 ms should be not be used for the visualizing.
8/12/2019 Distributed Automation With the PC
35/65
Function Principles and Program Structures
Function Mechanisms of this Application
OPC DP Slave
V 1.0 Issue Feb.16th.2005 35/65
CopyrightS
iemensAG2
005A
llrightsreserved
21040390_O
PC_
DPSlave_
DOKU_
v10_
e
Cycle time of the data transfer
Standard value in the example is 50 ms.
Using pause times at the and of the cycle.
At pause time 0 ms a minimal cycle time of 230 s results on a PC withP4 2.4 GHz at 100% processor load. At a pause time of 1 ms theprocessor load is below 5 %.
The time for copying or simulating the measured values can beneglected in comparison with the time for the OPC call for writing theinputs.
The cycle time of the PROFIBUS is normally in the range of 1-10 ms
depending on bus parameters such as number of slaves. The resolution of the Windows operating system is 10 ms.
Composition of the cycle time
Figure 4-3
Note For reaching a cycle time on the PC as steady as possible, it isrecommended to not select the pause times smaller than 10 ms, as thevariation range in relation to the overall cycle time would hardly benoticeable.
4.2.3 Class diagram of the OPC Client
This chapter explains the static structure of the OPC client using an UMLclass diagram. The dynamic sequences are explained in chapter 7 usingsequence diagrams.
The dynamic sequences are explained in chapter 5using sequencediagrams.
The following class diagram shows the classes used in the OPC client andtheir relations. The following pages explain the individual classes, wherebyonly the most important tasks and methods are explained. For a completelist, please refer to the well commented source code.
Subject to fluctuation
Fixed timeCy
cletime
8/12/2019 Distributed Automation With the PC
36/65
Function Principles and Program Structures
Function Mechanisms of this Application
OPC DP Slave
V 1.0 Issue Feb.16th.2005 36/65
CopyrightS
iemensAG2
005A
llrightsreserved
21040390_O
PC_
DPSlave_
DOKU_
v10_
e
Figure 4-4
8/12/2019 Distributed Automation With the PC
37/65
Function Principles and Program Structures
Function Mechanisms of this Application
OPC DP Slave
V 1.0 Issue Feb.16th.2005 37/65
CopyrightS
iemensAG2
005A
llrightsreserved
21040390_O
PC_
DPSlave_
DOKU_
v10_
e
Overview
The following table gives an overview of the C++ classes and classifiesthem according to task and reusability. The classes have beenimplemented with support of the C++ class library MFC (MicrosoftFoundation Classes).
The class names correspond to the file names of the files which contain thesource 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
CMemoryMapSlave Data transfer
Allgemein fr Datentransfer verwendbar.Modifications necessary for size of the processimage.
CThread Data transfer Usable as basis for separate thread.
COPCServerMgt OPC general
COPCGroupMgt OPC general
COPCDataCallback OPC general
CDataCallback OPC general
Generally usable for OPC clients.
Class CUserInterface This class implements the functionality of the user interface.
CUserinterface is derived from the MFC class CDialog as well as theCDataCallback interface. The data changes are reported to the userinterface via CdataCallback.
The OnBtnClick methods are called by clicking the respective buttons inthe user interface.
Table 4-4
Method Functionality
OnBtnConnectClick Setup of connection to OPC server and activating the Callbackconnection. An instance of COPCServerMgt and COPCGroupMgt iscreated respectively.
Starting the data transfer. This creates an instance of the CdataCopyclass and the thread for executing the control functionality in theobject is started.
OnBtnDisconnectClick Terminating the data transfer.
Disconnecting from the OPC server.
OnBtnWriteAIClick
OnBtnWriteDIClick
Manual writing of input values.
DataChange Receiving the value changes from the OPC server and writing thevalues into the user interface elements.
8/12/2019 Distributed Automation With the PC
38/65
Function Principles and Program Structures
Function Mechanisms of this Application
OPC DP Slave
V 1.0 Issue Feb.16th.2005 38/65
CopyrightS
iemensAG2
005A
llrightsreserved
21040390_O
PC_
DPSlave_
DOKU_
v10_
e
Class COPCItemMgt
This class manages all information on an OPC item required in the userinterface. This information consists of Server Handle, ItemID, ControlID,value and data type of the item. The Server Handle is provided by theserver at AddItems and is required for all calls at the group such as Read,Write and RemoveItems. ControlID writes a new value into the respectiveelement of the user interface.
Note The CUserInterface contains a list of the OPCItemMgt objects and savesall information on the items. The index of this list is the client handle ofthe item, which in AddItems is transmitted to the OPC server and isprovided by the OPC server at OnDataChange.
Any amount of information can be added without changing the accessmechanism.
Class COPCServerMgt
COPCServerMgt encapsules the OPC object OPCServer and enablessimplified 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 andtransmitting an OPCGroupMgt object.
RemoveGroup Removing a group. Requires deleting the OPCGroupMgt object priorto the call.
Class COPCGroupMgt
The COPCGroupMgt encapsules the OPC object OPCGroup and simplifiesaccess to the COM object.
Table 4-6
Method Functionality
AddItems Hinzufgen 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 theIDataCallback interface. It is required for initializing the Callbackobject OPCDataCallback.
DisconnectCallback Deactivating the Callback.
8/12/2019 Distributed Automation With the PC
39/65
Function Principles and Program Structures
Function Mechanisms of this Application
OPC DP Slave
V 1.0 Issue Feb.16th.2005 39/65
CopyrightS
iemensAG2
005A
llrightsreserved
21040390_O
PC_
DPSlave_
DOKU_
v10_
e
Class COPCDataCallback
This class implements the OPC interface IOPCDataCallback. Realizing theCOM functionality is derived from the ATL (Active Template Libary) classCComObjectRoot. The OPC server sends the Callbacks to the OPC clientvia IOPCDataCallback interface.
Table 4-7
Method Functionality
Initialize Initializes the object with a pointer to the CDataChange interface inthis example implemented by CUserInterface.
OnDataChange Is called by the OPC server if the values of the items within the grouphave changed. Forwards the call to the user interface.
Class CDataCallback
This interface class has only an abstract DataChange method which mustbe implemented by the derived class. In this example this method isimplemented by CUserInterface.
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 isthe 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 derivedclass.
StopThread Stops the thread. An event is sent to the thread for it.
8/12/2019 Distributed Automation With the PC
40/65
Function Principles and Program Structures
Function Mechanisms of this Application
OPC DP Slave
V 1.0 Issue Feb.16th.2005 40/65
CopyrightS
iemensAG2
005A
llrightsreserved
21040390_O
PC_
DPSlave_
DOKU_
v10_
e
Class CDataCopyClass CDataCopy is derived from CThread and implements the datatransfer and the simulation of the measured values. Both functionalities areexecuted cyclically in the separate thread.
Table 4-9
Method Functionality
ThreadEnter Overwrites the method of the base class. In this method the OPCconnection is initialized.
DoWork In this method the data transfer is executed in a loop until the thread isterminated.
ReadMemoryMap In this method the output image is read from the OPC server andstored in MemoryMap.
WriteMemoryMap Here the input image is taken from the MemoryMap and written intothe OPC server.
SimulateData In this method, the simulation of the measured values is implementedwith ramp and sinus function.
ThreadLeave Overwrites the method of the base class. In this method the OPCconnection is terminated.
NoteIn 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 ofthe slave during a cycle.
Table 4-10
Method Functionality
WriteOutput This method enables writing data, read by the OPC sever, into theMemoryMap.
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 thesimulation.
SetIn This method enables accessing the individual output variables in thesimulation.
8/12/2019 Distributed Automation With the PC
41/65
Function Principles and Program Structures
Explanations on the Example Program
OPC DP Slave
V 1.0 Issue Feb.16th.2005 41/65
CopyrightS
iemensAG2
005A
llrightsreserved
21040390_O
PC_
DPSlave_
DOKU_
v10_
e
5 Explanations on the Example Program
Here you will find more information on
the dynamic processes within the application. These are explained usingUML sequence diagrams.
5.1 Sequence diagrams for the visualization user interface
Connecting to the OPC server.
The following sequence diagram shows the sequence chart upon clickingthe "Connect" button in the user interface.
Figure 5-1
1
2
3
4
5
6
7
8/12/2019 Distributed Automation With the PC
42/65
Function Principles and Program Structures
Explanations on the Example Program
OPC DP Slave
V 1.0 Issue Feb.16th.2005 42/65
CopyrightS
iemensAG2
005A
llrightsreserved
21040390_O
PC_
DPSlave_
DOKU_
v10_
e
Explanation
Table 5-1
No. Description
1 Clicking "Connect calls the OnBtnConnectClick method at the UserInterface object. Inthis method, the connection to the OPC server is established and initialized.
2 In OnBtnConnectClick an instance of the COPCServerMgt class is created. This objectOPCServerMgtUI manages the connection to the OPC server. For establishing theconnection, ConnectOPCServer is called at this object.
3 Creating an instance of the COPCGroupMgt class in which the group is managed. TheOPCGroupMgtUI object is transferred in the AddGroup method to the OPCServerMgtUIobject, where from this object the properties of the group are taken for the AddGroup callto 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 inthe BuildItemArrays method. This information consists of ItemID, desired data type, clienthandle and ID of the user interface element. With these lists AddItems is called at theOPCGroupMgtUI group management.
5 After adding the item the list of the OPCItemMgt management objects for the items iscreated. Thereby, the OPCItemMgt objects are initialized with the information from theBuildItemArrays and the server handles delivered by the OPC server. The index of the listcorresponds 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 datachanges to the OPC client via this connection. At ConnectCallback a pointer of theCDataCallback type is transmitted to the instance of CUserInterface. In ConnectCallback
an instance of COPCDataCallback is generated. With this object the Callback connectionto 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 OPCserver.
Details see sequence diagram "Starting the data transfer in chapter 5.2.
Writing output variables
If the user of the application presses the "Write Input" button for the analoginputs, the event handling method OnBtnWriteAIClick is called in the
UserInterface object. In this method, the values are read from the userinterface and transmitted to the Write method of the OPCGroupMgtUIobject and thus written to the OPC server.
8/12/2019 Distributed Automation With the PC
43/65
Function Principles and Program Structures
Explanations on the Example Program
OPC DP Slave
V 1.0 Issue Feb.16th.2005 43/65
CopyrightS
iemensAG2
005A
llrightsreserved
21040390_O
PC_
DPSlave_
DOKU_
v10_
e
Sequence for writing the digital inputs
The sequence for writing the digital inputs is analog to the sequence for theanalog inputs.
Figure 5-2
OnDataChange Callback
The OnDataChange Callback is called by the OPC server, as soon as thevalue of one or several items has changed within the update time of thegroup. The changed values are contained in the call.
Figure 5-3
Explanation
Table 5-2
No. Description
1 The OPC server calls the OnDataChange method at the Callback objectOPCDataCallback. Here the transmitted data are packed into MFC lists and passed onto the UserInterface object via the DataChange method.
2 In UserInterface the changed values are processed in a loop. The ID of the userinterface element to which the value is to be written is thereby determined via the clienthandle. The client handle is the index of the list of the OPCItemMgt objects. With the IDread from OPCItemMgt the value is written into the user interface element with theSetDlgItemText method. The new value is also written in OPCItemMgt via SetValue.
2
1
8/12/2019 Distributed Automation With the PC
44/65
Function Principles and Program Structures
Explanations on the Example Program
OPC DP Slave
V 1.0 Issue Feb.16th.2005 44/65
CopyrightS
iemensAG2
005A
llrightsreserved
21040390_O
PC_
DPSlave_
DOKU_
v10_
e
5.2 Sequence diagrams for the data transfer
Starting the data transfer
Figure 5-4
1
2
3
4
5
6
7
8/12/2019 Distributed Automation With the PC
45/65
Function Principles and Program Structures
Explanations on the Example Program
OPC DP Slave
V 1.0 Issue Feb.16th.2005 45/65
CopyrightS
iemensAG2
005A
llrightsreserved
21040390_O
PC_
DPSlave_
DOKU_
v10_
e
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 StartThreadmethod called at the CDataCopy object.
2 The statistical method Run and the object pointer of DataCopy are transmitted to thenew thread. This calls the statistical method run in the new thread in which theThreadMain 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 beenimplemented in the CThread base class.
3 ThreadEnter is then first called in the ThreadMain method. The method can beoverwritten from the derived class in order to perform initializations. Here the connectionto the OPC server is established in the ThreadEnter method.
4 For connecting with the OPC a new instance of the COPCServerMgt class is generatedand the connection established via ConnectOPCServer. Subsequently an instance isgenerated by COPCGroupMgt and the instance is transmitted to OPCServerMgt in theAddGroup call. In this method, the properties of the group are read and AddGroup isthen called at the OPC server with these parameters. The OPCGroupMgt object is theninitialized with the return value of AddGroup.
5 After adding the group the items for the process image are then added. The serverhandles delivered by the OPC server are stored in a list.
6 Creating and initializing an instance of the CMemoryMapSlave class for managing theprocess 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.
Note When generating the instance of COPCGroupMgt the activeness statusof the group is transmitted as inactive. This is important as the cache ofthe OPC server is not necessary in this application which puts load off theOPC server.
8/12/2019 Distributed Automation With the PC
46/65
Function Principles and Program Structures
Explanations on the Example Program
OPC DP Slave
V 1.0 Issue Feb.16th.2005 46/65
CopyrightS
iemensAG2
005A
llrightsreserved
21040390_O
PC_
DPSlave_
DOKU_
v10_
e
Executing data transfer
A cycle of the data transfer with the simulation of the measured values andwriting the image of the inputs is explained in the following sequencediagram.
Figure 5-5
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 theprocess image is thereby made via the SetInX method for the inputs. Thereby each datatype has its own Set And Get method. GetOutBool for example enables accessingindividual output bits or SetInFloat accessing an individual word. In the exampleimplementation, both measured values are simulated with a ramp function and a sinusfunction and are written to the respective input value.
3 At the end of the cycle, the image of the inputs is written via the WriteMemoryMapmethod. The values of the outputs are read from the MemoryMapSlave object with theReadInputs 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.
1
2
3
Simulationmeasured values
Writinginputs
8/12/2019 Distributed Automation With the PC
47/65
Function Principles and Program Structures
Explanations on the Example Program
OPC DP Slave
V 1.0 Issue Feb.16th.2005 47/65
CopyrightS
iemensAG2
005A
llrightsreserved
21040390_O
PC_
DPSlave_
DOKU_
v10_
e
5.3 Error handling in the OPC Client
Error handling in the user interface:
The user interface contains an output window for error messages.
The return values of all OPC calls are checked for errors.
In case of an error a message is output in the output window.
Error handling in the data transfer:
Errors during initialization are reported to the user interface via a
message and output in the output window.
The user interface contains a status display for the data transfer. In theerror-free state the color is green and in case of an error it is red.
The return values of all OPC calls are checked for errors.
In case of an error an error flag is set in the DataCopy object.
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 tothe user interface.
8/12/2019 Distributed Automation With the PC
48/65
Function Principles and Program Structures
Modifications to the Example Program
OPC DP Slave
V 1.0 Issue Feb.16th.2005 48/65
CopyrightS
iemensAG2
005A
llrightsreserved
21040390_O
PC_
DPSlave_
DOKU_
v10_
e
6 Modifications to the Example Program
Here you will find information on
what to do in order to expand the example code of the OPC client and usethe example code in your own Visual Studio NET C++ project.
6.1 Expanding the sample code of the OPC client
Definit ion of the configuration data for the OPC client
The configuration data for server, groups and items have been defined inthe ServerDefines.h file in the following sections:
Table 6-1
No. Section Note
1 OPC Server & Updaterate OPC server ProgID and group settings for the OPCconnection of the user interface.
2 Status ItemIDs of the PROFIBUS status items in the userinterface.
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 functionand ItemIDs of the input and output variables for theprocess image.
Expanding the scope of the OPC client
For expanding the scope, changes to the source code must be made at thefollowing locations:
Table 6-2
No. Source Code Change
1 ServerDefines.h file Supplementing definitions for additional ItemIDs andadjusting definitions for the number of items.
2 UserInterface.cpp file
BuildItemArrays method
Adjusting structure of item lists to the new items.
3 DataCopy.cpp file
BuildItemArrays method
Adjusting structure of item lists to the new items.
8/12/2019 Distributed Automation With the PC
49/65
Function Principles and Program Structures
Modifications to the Example Program
OPC DP Slave
V 1.0 Issue Feb.16th.2005 49/65
CopyrightS
iemensAG2
005A
llrightsreserved
21040390_O
PC_
DPSlave_
DOKU_
v10_
e
6.2 Using OPC in own Visual Studio .NET C++ project
This chapter contains a description of the steps necessary for creating anew C++ project in Visual Studio, in which the OPC is to be used. Furtherinformation is available in the documentation on Visual Studio .NET.
Table 6-3
No. Instructions Note
1 Open Microsoft Visual Studio .NET2003.
2 Create new project and select
Visual C++ MFCas project
type in the left hand pane.On the right hand pane select theMFC Applicationtemplate andspecify name and storage locationof the project.
After clicking OK a further dialogappears named MFC
Application Wizard.
3 SelectApplication Typeonthe left side in the blue field.
Select Dialog basedon the thendisplayed page.Pressing the Finishbuttoncreates the project with thesettings made.
4 Copy the files
opcda.h,
opcda_i.c,
opccomn.h,
opccomn_i.c,
opcerror.h
into the project directory.
The files can be taken from the delivered sampleproject or be obtained directly from the website of theOPC Foundation (www.opcfoundation.org).
http://www.opcfoundation.org/http://www.opcfoundation.org/8/12/2019 Distributed Automation With the PC
50/65
Function Principles and Program Structures
Modifications to the Example Program
OPC DP Slave
V 1.0 Issue Feb.16th.2005 50/65
CopyrightS
iemensAG2
005A
llrightsreserved
21040390_O
PC_
DPSlave_
DOKU_
v10_
e
No. Instructions Note
5 Open the context menu in theSolution Explorer of the studio byright-clicking the Source Files folder. There you selectAdd
Add Existing Item.
6 If necessary browse into theproject directory and select both Cfiles (*.c).
Pressing the Open buttonsaddsthe files to the project.
7 Open the Properties Dialog forboth newly added files via thecontext menu (right mouse button)and select the Not usingprecompiled Headersetting inConfiguration PropertiesC/C++ Precompiled
Header.
Pressing the OK buttonacknowledges the changed
settings.
8 Open the stdafx.h file in theSolution Explorer with a double-click and include the OPC headerfiles.
#includeopcda.h
#includeopccomn.h
#includeopcerror.h
9 Compile project.
Note The OPC interface can be used project wide in every Code file whichcontains the reference #includestdafx.h.
8/12/2019 Distributed Automation With the PC
51/65
Function Principles and Program Structures
Modifications to the Example Program
OPC DP Slave
V 1.0 Issue Feb.16th.2005 51/65
CopyrightS
iemensAG2
005A
llrightsreserved
21040390_O
PC_
DPSlave_
DOKU_
v10_
e
6.3 Using sample code in own Visual Studio .NET project
If the OPC classes from the example for encapsulating the OPC interfaceare being used, the following steps are necessary.
Note In the project the OPC classes require ATL Support.
Table 6-4
Nr. Aktion Anmerkung
1 Copy the following files into theproject directory:
OPCServerMgt.cpp, OPCServerMgt.h,
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.
3 Open the stdafx.h file via theSolution Explorer with a double-click and add the following codelines.
#i ncl ude t ypedef CArr ay CVARI ANTAr r ay;
t ypedef CArr ay CHRESULTAr r ay;
User defined arrays, which user the MFC templateCarray, are used in the newly added classes.
4 Add ATL Support to the project.
SelectAdd -> Add Classinthe Solution Explorer via the
context menu of the project (rightmouse button).
5
Click C++ ATLas categoryon the Add Class dialog, andselectAdd ATL Support ToMFCas template.
Pressing the Openbutton addsthe STL Support to the project.
8/12/2019 Distributed Automation With the PC
52/65
Structure, Configuration and Operation of the Application
Installation and Commissioning
OPC DP Slave
V 1.0 Issue Feb.16th.2005 52/65
CopyrightS
iemensAG2
005A
llrightsreserved
21040390_O
PC_
DPSlave_
DOKU_
v10_
e
Structure, Configuration and Operation of the Application
Content
This part leads you step by step through the structure, importantconfiguration steps, commissioning and operation of the application.
7 Installation and Commissioning
Here you will find information on
the hardware and software to be installed and which steps are necessaryfor commissioning the example.
7.1 Installation of Hardware and Software
This chapter describes the hardware and software components to beinstalled. The description and manuals as well as delivery informationcontained in the delivery scope of the respective products, should befollowed in any case.
Hardware configuration
The hardware components are available in chapter .For the hardware setup please proceed according to the following table:
!Warning
Switch on the power supply after the last step only .
Table 7-1
No. Focus Instructions
1 PC station Install the PCI plug-in card CP 5611 into the PC station according tothe attached manual /6/.
2 SIMATIC S7station
Set up the controlling according to the figure in chapter 2.1.
3 PROFIBUS Connect the PC station with the SIMATIC S7 station analog to thefigure in chapter 2.1.
Note Setup guidelines for PROFIBUS networks must generally be followed..
8/12/2019 Distributed Automation With the PC
53/65
8/12/2019 Distributed Automation With the PC
54/65
Structure, Configuration and Operation of the Application
Installation and Commissioning
OPC DP Slave
V 1.0 Issue Feb.16th.2005 54/65
CopyrightS
iemensAG2
005A
llrightsreserved
21040390_O
PC_
DPSlave_
DOKU_
v10_
e
7.2 Commission ing the SIMATIC S7 station
This chapter describes commissioning the SIMATIC S7 station for thehardware configuration described in chapter 2via the download of thestation from the STEP 7 project.
Note The STEP 7 project delivered with this example contains the completelyconfigured SIMATIC S7 station with control program. This project canonly be used without adjustment if the hardware is identical with theconfiguration.
The configuration for deviating hardware is available in chapter 8.3.
Table 7-2
No. Instructions Note
1 Dearchiving the project Extract the 21040390_OPC_DPSlave_STEP7_v10.zipfile
2 Open project in SIMATICManager.
3 Select station SIMATIC 315-2DPand load station into controller.
The access point S7ONLINEused by STEP 7 must have been
switched for loading the S7station.
7.3 Commission ing the SIMATIC PC station
This chapter describes commissioning the PC station with the configurationof the PC station via an XDB file for the hardware configuration described inchapter 2. Successful installation of all hardware and software componentsis a prerequisite.
8/12/2019 Distributed Automation With the PC
55/65
Structure, Configuration and Operation of the Application
Installation and Commissioning
OPC DP Slave
V 1.0 Issue Feb.16th.2005 55/65
CopyrightS
iemensAG2
005A
llrightsreserved
21040390_O
PC_
DPSlave_
DOKU_
v10_
e
Note The project file (XDB) delivered with this example contains the completelyconfigured PC station. This file can only be used without adjustment if thehardware 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 inthe task bar.
2 Click Import Station Confirm the query with Yes
3 Select the XDB file The XCB file is available in the XDBs sub-directory ofthe extracted ZIP-file.
4 After importing the XDB file thePC station has been configured.
Note The explanations on configuring the PC station and the SIMATIC S7station in chapter 8are only necessary, if the hardware configurationdoes not correlate with he configuration described in chapter 2.3.
7.4 Commission ing of the OPC Client
The user interface and the source code of the application are delivered asZIP file.
For installation of the OPC client extract the21040390_OPC_DPSlave_CODE_v10.zip file in to any directory.
8/12/2019 Distributed Automation With the PC
56/65
Structure, Configuration and Operation of the Application
Configuration
OPC DP Slave
V 1.0 Issue Feb.16th.2005 56/65
CopyrightS
iemensAG2
005A
llrightsreserved
21040390_O
PC_
DPSlave_
DOKU_
v10_
e
8 Configuration
Here you will find information on
the configuration steps necessary if the hardware deviates from thehardware used in the example.
8.1 Configuring the PC station
The communication processor must be switched into "Configured mode".This releases it for being used with an application (here OPC server) andcan be configured. This means that the configuration information fromSTEP 7 or HW Config can be loaded as for a hardware PLC (download).
Table 8-1
No. Instructions Note
1 Starting theConfigurations Console
2 Select CP and setConfigured mode.
3 Confirm selection and closethe dialog.
8/12/2019 Distributed Automation With the PC
57/65
8/12/2019 Distributed Automation With the PC
58/65
Structure, Configuration and Operation of the Application
Configuration
OPC DP Slave
V 1.0 Issue Feb.16th.2005 58/65
CopyrightS
iemensAG2
005A
llrightsreserved
21040390_O
PC_
DPSlave_
DOKU_
v10_
e
No. Instructions Note
5 Enter application (here OPCserver)
The used OPC Server must beselected according to theSIMATIC NET Version, hereV6.2.
6 The operating mode of the CP5611 is set to DP-Slave.
The assigned applicationconnecting as DP Slave is inthis case the OPC Server.
7 Saving compiling and loadingconfiguration (into PC station