61
Application for Communication Controlling with the PC The SIMATIC NET OPC Inproc Server as DP Master Program Example in C++

21045282 Opc Dpmaster Doku v10 e

Embed Size (px)

Citation preview

Page 1: 21045282 Opc Dpmaster Doku v10 e

Application for Communication

Controlling with the PC The SIMATIC NET OPC Inproc Server as DP Master

Program Example in C++

Page 2: 21045282 Opc Dpmaster Doku v10 e

Warranty, Liability and Support

OPC DP Master

V 1.0 Issue 25th Nov 2005 2/61

Cop

yrig

ht ©

Sie

men

s AG

200

4 Al

l rig

hts

rese

rved

21

0452

82_O

PC_D

PMas

ter_

DO

KU_v

10_e

2

1045

282

Warranty, Liability and Support We do not accept any liability for the information contained in this document. Any claims against us - based on whatever legal reason - resulting from the use of the examples, information, programs, engineering and performance data etc., described in this document shall be excluded. Such an exclusion shall not apply in the case of mandatory liability, e.g. under the German Product Liability Act (“Produkthaftungsgesetz”), in case of intent, gross negligence, or injury of life, body or health, guarantee for the quality of a product, fraudulent concealment of a deficiency or breach of a condition which goes to the root of the contract (“wesentliche Vertragspflichten”). However, claims arising from a breach of a condition which goes to the root of the contract shall be limited to the foreseeable damage which is intrinsic to the contract, unless caused by intent or gross negligence or based on mandatory liability for injury of life, body or health. The above provisions does not imply a change in the burden of proof to your detriment. 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.

Copyright© 2004 Siemens A&D. It is not permissible to transfer or copy these Application Examples or excerpts of them without first having prior authorization from Siemens A&D in writing. For questions about this document please use the following e-mail-address: [email protected]

Page 3: 21045282 Opc Dpmaster Doku v10 e

Foreword

OPC DP Master

V 1.0 Issue 25th Nov 2005 3/61

Cop

yrig

ht ©

Sie

men

s AG

200

4 Al

l rig

hts

rese

rved

21

0452

82_O

PC_D

PMas

ter_

DO

KU_v

10_e

2

1045

282

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-Master for control tasks while the advantages of a PC can be used for parallel visualizing in an application at the same time. Particular emphasis is placed here on maximum performance and minimum resource consumption.

Main contents of this application The following main points are discussed in this application:

• Configuration of a PC station with OPC server.

• Configuration of the OPC server as PROFIBUS DP-Master.

• Background information on PROFIBUS DP and OPC Data Access 2.05.

• Using the OPC Data Access Custom interface in a C++ application with Visual Studio .NET as development environment.

• Realizing a control task in C++ on the PC: – Reading and writing the process image via OPC Data Access. – OPC Server configuration and optimal OPC calls for the highest

possible performance. – Reusable framework for a control task.

• 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 control and visualization tasks in an application without mutual impact.

Delimitation This application does not contain a description

• of Visual Studio .NET,

• of C++,

• of UML notation or basics on Microsoft COM. Previous knowledge in this field is assumed.

Page 4: 21045282 Opc Dpmaster Doku v10 e

Foreword

OPC DP Master

V 1.0 Issue 25th Nov 2005 4/61

Cop

yrig

ht ©

Sie

men

s AG

200

4 Al

l rig

hts

rese

rved

21

0452

82_O

PC_D

PMas

ter_

DO

KU_v

10_e

2

1045

282

Structure of the document The documentation of this application is divided into the following main parts.

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 program structures

Discusses the detailed function processes of the 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.

Structure, configuration and operation of the application

This part leads you step by step through the structure, important configuration steps, commissioning and operation of the application.

Appendix Here you find further information, such as bibliography, glossary etc..

References for A&D Service & Support This entry originates from the internet application portal of the A&D Service and Support. The following link takes you directly to the download page of this document. http://support.automation.siemens.com/WW/view/en/21045282

Page 5: 21045282 Opc Dpmaster Doku v10 e

Table of Contents

OPC DP Master

V 1.0 Issue 25th Nov 2005 5/61

Cop

yrig

ht ©

Sie

men

s AG

200

4 Al

l rig

hts

rese

rved

21

0452

82_O

PC_D

PMas

ter_

DO

KU_v

10_e

2

1045

282

Table of Contents Application Description ............................................................................................... 7

1 Automation Task............................................................................................. 7 1.1 Overview........................................................................................................... 7 1.2 Requirements: .................................................................................................. 8

2 Automation Solution .................................................................................... 10 2.1 Brief description of the core functionality ........................................................ 10 2.2 Required hardware and software components ............................................... 12 2.3 Alternative solutions and characteristics......................................................... 14 2.4 Basic performance data in this application ..................................................... 16

Function principles and program structures ........................................................... 17

3 General Function Mechanisms.................................................................... 17 3.1 Basics on PROFIBUS DP............................................................................... 17 3.2 Basics OPC .................................................................................................... 19 3.3 SIMATIC NET OPC-DP Master ...................................................................... 22 3.4 Using OPC Data Access................................................................................. 23

4 Function Mechanisms of this Application.................................................. 28 4.1 Functionality of the OPC Client....................................................................... 28 4.2 Function mechanisms of the OPC Client........................................................ 32 4.3 Class diagram of the OPC Client.................................................................... 35

5 Description of the Sample Code ................................................................. 40 5.1 Sequence diagrams for the visualization user interface ................................. 40 5.2 Sequence diagrams for the control functionality ............................................. 43 5.3 Error handling in the OPC client ..................................................................... 46

6 Expanding and Using the Sample Code of the Client ............................... 47 6.1 Expanding the sample code of the OPC client ............................................... 47 6.2 Using OPC in own Visual Studio .NET C++ project........................................ 48 6.3 Using sample code in own Visual Studio .NET project ................................... 50

Structure, Configuration and Operation of the Application ................................... 51

7 Installation and Commissioning ................................................................. 51 7.1 Installation of Hardware and Software............................................................ 51 7.2 Commissioning the SIMATIC PC station ........................................................ 52 7.3 Commissioning the OPC Client ...................................................................... 53

8 SIMATIC NET Configuration ........................................................................ 55 8.1 Configuring the PC station.............................................................................. 55 8.2 Configuring the PC station.............................................................................. 55 8.3 Testing with OPC Scout.................................................................................. 59

Page 6: 21045282 Opc Dpmaster Doku v10 e

Table of Contents

OPC DP Master

V 1.0 Issue 25th Nov 2005 6/61

Cop

yrig

ht ©

Sie

men

s AG

200

4 Al

l rig

hts

rese

rved

21

0452

82_O

PC_D

PMas

ter_

DO

KU_v

10_e

2

1045

282

Appendix and List of Further Literature ................................................................... 61

9 Bibliographic References ............................................................................ 61

Page 7: 21045282 Opc Dpmaster Doku v10 e

Application Description

Automation Task

OPC DP Master

V 1.0 Issue 25th Nov 2004 7/61

Cop

yrig

ht ©

Sie

men

s AG

200

4 Al

l rig

hts

rese

rved

21

0452

82_O

PC_D

PMas

ter_

DO

KU_v

10_e

2

1045

282

Application Description

Content Provides a general overview of the contents. 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.

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. Controlling as well as visualizing can be realized with the PC.

Overview of automation task The following figure gives an overview of the automation task. In this example, the PC works as PROFIBUS DP-Master. Figure 1-1

Page 8: 21045282 Opc Dpmaster Doku v10 e

Application Description

Automation Task

OPC DP Master

V 1.0 Issue 25th Nov 2004 8/61

Cop

yrig

ht ©

Sie

men

s AG

200

4 Al

l rig

hts

rese

rved

21

0452

82_O

PC_D

PMas

ter_

DO

KU_v

10_e

2

1045

282

1.2 Requirements:

Requirements for the automation task As opposed to controlling of a process with classic PLC and visualization on a PC or a panel, there often are also the following requirements:

• Integrated solution on a device.

• Performant and cost-effective solution of the control task.

• Complex calculation in the controller.

• Individually created, slim and optimized visualization. Apart from these requirements which are realized in this application, there are also further advantages which are useful during the realization on the PC:

• Interaction with other PC applications such as data bases.

• Simple integration into the company IT.

Requirements for the controller • Provision of PROFIBUS DP-Slave data in the memory of the PC for

further processing in the controller logic. • Process controlled by means of an encapsulated function.

• Simple logic functions with inputs and outputs.

• Simple calculations with inputs and outputs.

• Control cycle must not be affected by the operator action at the user interface.

Requirements for the visualization user interface • Visualizing the IO modules of the configured slaves.

• Starting and shutdown of the controller.

• Writing control commands to the outputs when the controller has been shut down. This enables manual control.

• Display of specific DP variables and diagnostic information.

• User interface must always be operable even at active controller.

Requirements to the development environment and programming language • Application of C++,

• Development with Microsoft Visual Studio .NET.

Page 9: 21045282 Opc Dpmaster Doku v10 e

Application Description

Automation Task

OPC DP Master

V 1.0 Issue 25th Nov 2004 9/61

Cop

yrig

ht ©

Sie

men

s AG

200

4 Al

l rig

hts

rese

rved

21

0452

82_O

PC_D

PMas

ter_

DO

KU_v

10_e

2

1045

282

Requirements regarding connection to the process • Connection to the process data via PROFIBUS DP as well as the

SIMATIC NET OPC Server V6.2.

• Operating the OPC server as PROFIBUS DP-Master.

• Using the PROFIBUS Inprocess OPC server for maximum performance.

• Using the OPC Data Access Custom Interface V2.05.

• Reading and writing of process variables.

• Monitoring of process variables.

• Reading PROFIBUS DP specific variables and diagnostic information.

Emphasis of this application The emphasis of this example is on the provision and usage of a process image (analog to the process image of the inputs PII and the outputs PIQ of a WIMATIC CPU).

Page 10: 21045282 Opc Dpmaster Doku v10 e

Application Description

Automation Task

OPC DP Master

V 1.0 Issue 25th Nov 2004 10/61

Cop

yrig

ht ©

Sie

men

s AG

200

4 Al

l rig

hts

rese

rved

21

0452

82_O

PC_D

PMas

ter_

DO

KU_v

10_e

2

1045

282

2 Automation Solution

Here you will find information on … the solution selected for the automation task.

2.1 Brief description of the core functionality

Display The following figure displays the most important components of the solution: Figure 2-1

Setup • The PC with the CP 5613 is at the PROFIBUS network master and the

ET 200 is at the PROFIBUS network slave.

• The OPC server encapsulates the access to the process data with a standardized interface.

• The OPC Client is realized in C++.

• The C++ classes for the OPC functionality and the controller can generally be used again.

Control functionality • Reading the inputs via the OPC Server.

• Executing the control function with LEDs lighting in sequence, copying inputs to outputs, and calculating sinus functions and average values.

• Writing the outputs via the OPC server.

Page 11: 21045282 Opc Dpmaster Doku v10 e

Application Description

Automation Task

OPC DP Master

V 1.0 Issue 25th Nov 2004 11/61

Cop

yrig

ht ©

Sie

men

s AG

200

4 Al

l rig

hts

rese

rved

21

0452

82_O

PC_D

PMas

ter_

DO

KU_v

10_e

2

1045

282

User interface of the OPC Client Figure 2-2 User interface of the OPC Client

Functionality of the user interface The user interface of the application hereby fulfills the following functionalities:

• Connecting and disconnecting the OPC server.

• Starting and shutdown of the controller.

• Displaying slave specific data and diagnostic information.

• Displaying the three slave modules.

• Writing the values of the outputs. This function is locked when the controller has been started.

Page 12: 21045282 Opc Dpmaster Doku v10 e

Application Description

Automation Task

OPC DP Master

V 1.0 Issue 25th Nov 2004 12/61

Cop

yrig

ht ©

Sie

men

s AG

200

4 Al

l rig

hts

rese

rved

21

0452

82_O

PC_D

PMas

ter_

DO

KU_v

10_e

2

1045

282

2.2 Required hardware and software components

Overview The following figure schematically displays the required hardware and software components. Figure 2-3

Hardware components of the SIMATIC PC station A PG/PC is connected with the distributed I/O (DP) via PROFIBUS. The PROFIBUS card used is the CP 5613. Table 2-1

Component No. MLFB / Order number Note Industrial PC SIMATIC Rack PC IL 40 S

1 6AG4 011-1CA32-0KX0 Configurator: see FAQ ID 17128155.

Communications processor CP 5613 for PROFIBUS, PCI card

1 6GK1 561-3AA01 As an alternative, a CP 5611 may also be used for this purpose.

Page 13: 21045282 Opc Dpmaster Doku v10 e

Application Description

Automation Task

OPC DP Master

V 1.0 Issue 25th Nov 2004 13/61

Cop

yrig

ht ©

Sie

men

s AG

200

4 Al

l rig

hts

rese

rved

21

0452

82_O

PC_D

PMas

ter_

DO

KU_v

10_e

2

1045

282

Hardware components of the DP slave An ET 200M, in which the modules listed below are integrated, is used as a DP slave. Table 2-2

Component No. MLFB / Order number Note IM153-2 1 6ES7 153-2BA00-0XB0 Expansion module SM331 1 6ES7 331-7KB02-0AB0 analog input 2 channel:

AI 2x12Bit SM332 1 6ES7 332-5HD01-0AB0 analog output 4

channel: AO 4x12Bit SM374 1 6ES7 374-2XH01-0AA0 Simulation module

digital 8x IO

Software components The SIMATIC PC station requires software components which are listed in the following table. Table 2-3

Component No. MLFB / Order number Note SIMATIC NET CD V6.2 1 6GK1 704-0AA07-3AA0 Comes with the CP

5613. STEP 7 V5.3 1 6ES7 810-4CC07-0YA5 (Optional) only for

configuration of S7 300 / 400 CPUs as DP-Slaves.

Microsoft Visual Studio .NET 2003 Professional

1 Ordering via your administrator or the Microsoft Homepage

(Optional) Only if changes at the example code are necessary.

Example files and projects The following list contains all files and projects used in this example. Table 2-4

Component Note 21045282_OPC_DPMaster_CODES7_v10.zip This zip file contains the STEP

7 project for the PC station. 21045282_OPC_DPMaster_CODEPC_v10.zip This zip-file contains the

executable files for the OPC client as well as the Visual C++ project with the source code.

21045282_OPC_DPMaster _DOKU_v10_d.pdf This document

Page 14: 21045282 Opc Dpmaster Doku v10 e

Application Description

Automation Task

OPC DP Master

V 1.0 Issue 25th Nov 2004 14/61

Cop

yrig

ht ©

Sie

men

s AG

200

4 Al

l rig

hts

rese

rved

21

0452

82_O

PC_D

PMas

ter_

DO

KU_v

10_e

2

1045

282

2.3 Alternative solutions and characteristics

Here you will find information on … the existing alternatives for solving the automation task, and which characteristics the alternatives have. The solution realized in this example is respectively shaded in green.

Comparison Hardnet and Softnet Table 2-5

Component Description Hardnet with CP 5613 or CP 5614

• Less CPU load, as the main functions are executed in the hardware. • Quick access to the process image in the DP-RAM. • FastLogic, e.g. for EMERGENCY-STOP realization.

Softnet with CP 5611 or CP 5511

• More cost-effective solution. • Scaling the performance with rising PC load. • Higher CPU load through protocol execution in software particularly at

higher slave number. • Slower access to the process data.

Direct comparison of programming languages Table 2-6

Component Description Visual Basic V6.0

• The advantage of Visual Basic applications is simple handling of the OPC interface via the automation interface, and the quick application generation especially with the user interfaces.

• The disadvantage of Visual Basic is the lower performance due to the Visual Basic runtime and the additional software layer with OPC Automation DLL. Furthermore, several functionalities cannot be executed parallel, which reduces the performance of the control and visualization task.

.NET langua-ges C# and Visual Basic.NET

• 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 (Runtime Callable 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 in the higher expense for the implementation especially for complex user interfaces.

Page 15: 21045282 Opc Dpmaster Doku v10 e

Application Description

Automation Task

OPC DP Master

V 1.0 Issue 25th Nov 2004 15/61

Cop

yrig

ht ©

Sie

men

s AG

200

4 Al

l rig

hts

rese

rved

21

0452

82_O

PC_D

PMas

ter_

DO

KU_v

10_e

2

1045

282

Direct comparison PLC and PC for control task Table 2-7

Component Description Classic PLC • Deterministic real-time behavior.

• Robust and fail-safe due to specialization of the device. • Investment protection due to long life-cycles of the products.

Advantages of a PC solution

• One device for controlling and visualizing. • Benefits from fast innovation in PC technology • Virtually unlimited memory space. • Optimized individual solution possible. Can be used cost-effectively in

many different ways.

Direct comparison Inproc / Outproc OPC Server for solution estimation The following points have to be taken into consideration when choosing the OPC server between In Process (OPC.SimaticNET.DP) and Out of Process (OPC.SimaticNET) (detailed description in chapter 3.2):

Table 2-8

Component Description Inproc OPC Server

• Faster calls from OPC client to server as there is no process boundary between client and server.

• The Inproc OPC server can only be loaded within a process, i.e. only a client can connect to this server.

• Using Hardnet and Softnet possible. Outproc OPC Server

• The Outproc OPC server can be accessed from several applications. • Remote access to the Outproc OPC server possible. • Using Hardnet and Softnet possible.

Decision criteria for selecting an Iproc / Outproc OPC server The following table gives you an overview of the relevant features of an Inproc and Outproc OPC server.

Table 2-9

Decision criteria Inproc OPC Server Outproc OPC Server Speed ++ + Number of connected clients 1 n Client and server on different computers No Yes Control application ++ + Visualization application + ++ Softnet CP5611 / CP5511 Yes Yes Hardnet CP 5613 / CP 5614 Yes Yes Average cycle time of the controller in this application without pause (see chapt. 2.4)

70 µs 210 µs

Page 16: 21045282 Opc Dpmaster Doku v10 e

Application Description

Automation Task

OPC DP Master

V 1.0 Issue 25th Nov 2004 16/61

Cop

yrig

ht ©

Sie

men

s AG

200

4 Al

l rig

hts

rese

rved

21

0452

82_O

PC_D

PMas

ter_

DO

KU_v

10_e

2

1045

282

2.4 Basic performance data in this application

Frame conditions for measured values The times given in this chapter were measured on a PC with Pentium 4 processor with 2.4 GHz. The specified times always refer to a control cycle with reading the PII via OPC, calculating the control function and writing the PIQ via OPC, as well as to the described hardware configuration. The "average cycle time" was determined from a total time of 1000 cycle runs. 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 chapter � on cycle times.

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 controller with the different programming languages and the Inproc OPC server. Table 2-10

Programming language Average cycle time C++ 70 µs C# 234 µs

Visual Basic V6.0 620 µs

Page 17: 21045282 Opc Dpmaster Doku v10 e

Function principles and program structures

General Function Mechanisms

OPC DP Master

V 1.0 Issue 25th Nov 2004 17/61

Cop

yrig

ht ©

Sie

men

s AG

200

4 Al

l rig

hts

rese

rved

21

0452

82_O

PC_D

PMas

ter_

DO

KU_v

10_e

2

1045

282

Function principles and program structures

Content Here the detailed function processes of the involved hardware and software components, the solution structures, and where sensible the concrete implementation of this application is discussed. Read this part if you want to know how the individual solution components interact.

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 on the cell or process level. Some terms from this field are explained below. Further information is available in the SIMATIC NET /4/ manual at www.profibus.com.

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.

Page 18: 21045282 Opc Dpmaster Doku v10 e

Function principles and program structures

General Function Mechanisms

OPC DP Master

V 1.0 Issue 25th Nov 2004 18/61

Cop

yrig

ht ©

Sie

men

s AG

200

4 Al

l rig

hts

rese

rved

21

0452

82_O

PC_D

PMas

ter_

DO

KU_v

10_e

2

1045

282

PROFIBUS Class 1 Master The active stations of class 1 are PROFIBUS DP masters cyclically polling their respectively assigned slaves - they are also simply referred to as DP master. Several DP masters may be present at one bus (access control using "Token Passing“), however, each master has to process a number of exclusively assigned slaves (a so-called master system). Which slaves are part of a master system is defined in the configuration (type, address, data volume) and is verified by the master in the startup phase. In the course of time, the DP specification has been expanded step by step and there are now three main versions with different functionality. DPV0 describes the underlying basic functionality, the cyclic data communication between a master and its slave, as well as station, module and channel-specific diagnosis and four interrupt types e.g. diagnosis and process interrupt, or pulling and stretching of slaves. DPV1 is an expansion of the DPV0 and describes acyclic services e.g. for parameter assignment, status display and interrupt control. DPV1 services of intelligent field devices are processed parallel to the cyclic data communication. This enables accessing stations online using engineering 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 Class 2 Master Active stations of the class 2 type are typically stations fulfilling engineering, diagnostics or configuration tasks. During the commissioning phase they are connected for maintenance or diagnostics purposes and can configure devices, evaluate measured values or poll the device status. Class 2 masters can be connected permanently or temporarily at a bus.

PROFIBUS Slaves 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.

Page 19: 21045282 Opc Dpmaster Doku v10 e

Function principles and program structures

General Function Mechanisms

OPC DP Master

V 1.0 Issue 25th Nov 2004 19/61

Cop

yrig

ht ©

Sie

men

s AG

200

4 Al

l rig

hts

rese

rved

21

0452

82_O

PC_D

PMas

ter_

DO

KU_v

10_e

2

1045

282

Relationship Master - Slaves The following figure shows the relationships between master class 1 (cyclic) and master class 2 (acyclic), as well as different functions of communication which can be supported.

Figure 3-1

3.2 Basics OPC

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. A detailed documentation is available on the SIMATIC NET CD-Rom. Further information 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 provides the functionality for the information exchange between applications on a PC. With DCOM (distributed COM) this even occurs 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 OPC server and can access the offered data.

Page 20: 21045282 Opc Dpmaster Doku v10 e

Function principles and program structures

General Function Mechanisms

OPC DP Master

V 1.0 Issue 25th Nov 2004 20/61

Cop

yrig

ht ©

Sie

men

s AG

200

4 Al

l rig

hts

rese

rved

21

0452

82_O

PC_D

PMas

ter_

DO

KU_v

10_e

2

1045

282

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, can access this interface directly. The automation interface is included in the delivery scope to enable access from Visual Basic applications. It is a DLL which 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 and accesses the data "remotely", this is referred to as a DCOM connection.

OPC Server as Inproc or Outproc COM object COM servers are divided into two types. At identical OPC interface a server can be realized as In Process (Inproc) or Out Of Process (Outproc). Inproc are implemented as downloadable DLL and Outproc as executable file (EXE). If a client connects with an Inproc OPC server, the OPC server DLL is 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.

Page 21: 21045282 Opc Dpmaster Doku v10 e

Function principles and program structures

General Function Mechanisms

OPC DP Master

V 1.0 Issue 25th Nov 2004 21/61

Cop

yrig

ht ©

Sie

men

s AG

200

4 Al

l rig

hts

rese

rved

21

0452

82_O

PC_D

PMas

ter_

DO

KU_v

10_e

2

1045

282

Display 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

Page 22: 21045282 Opc Dpmaster Doku v10 e

Function principles and program structures

General Function Mechanisms

OPC DP Master

V 1.0 Issue 25th Nov 2004 22/61

Cop

yrig

ht ©

Sie

men

s AG

200

4 Al

l rig

hts

rese

rved

21

0452

82_O

PC_D

PMas

ter_

DO

KU_v

10_e

2

1045

282

3.3 SIMATIC NET OPC-DP Master

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.

Architecture of driver layers Prior to introducing the OPC interfaces, a C interface, the DP-Lib, was used for developing DP Master applications. The Outproc OPC server is based on this interface. The functionality of DP-Lib contains master class 1 (DPV0 and DPV1) and master class 2. Particularly for applications with increased performance requirements, there is the so-called DP-Base interface for CP 5613/14, which enables direct access to the memory of the PROFIBUS card. The Inproc OPC Server used DP-Lib (CP 5611/CP 5511) as well as the fast DP-Base interface(CP 5613/14).

Architectural scheme The following application shows the difference between the cards as well as the architecture of the offered interfaces. This example uses the Inproc DP OPC Server, which accesses the DP-Base interface without process change to the memory of the PROFIBUS card CP 5613. Figure 3-3

Page 23: 21045282 Opc Dpmaster Doku v10 e

Function principles and program structures

General Function Mechanisms

OPC DP Master

V 1.0 Issue 25th Nov 2004 23/61

Cop

yrig

ht ©

Sie

men

s AG

200

4 Al

l rig

hts

rese

rved

21

0452

82_O

PC_D

PMas

ter_

DO

KU_v

10_e

2

1045

282

3.4 Using OPC Data Access

This explains the basics of OPC Data Access (DA) necessary for the example.

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 searched by the OPC client. Most OPC servers display the items there in a tree structure. 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 is unique, but the name and path in the address space.

Address space of the OPC server The figure shows the configured address space of the PROFIBUS DP OPC server using the example on hand. The folder structure is shown in the left hand pane of the window. The middle section of the window displays items of the selected folder M01_Q with the output words of the module 01. The right hand section of the window shows the selected input 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 Levels of the tree structure

Level Description 1 The connection name is defined during configuration. In this example

it is CP 5613 A2. 2 The configured PROFIBUS DP slaves with their PROFIBUS address.

In this example the address 5. 3 The modules of the slave divided into inputs and outputs.

1

2

3

Page 24: 21045282 Opc Dpmaster Doku v10 e

Function principles and program structures

General Function Mechanisms

OPC DP Master

V 1.0 Issue 25th Nov 2004 24/61

Cop

yrig

ht ©

Sie

men

s AG

200

4 Al

l rig

hts

rese

rved

21

0452

82_O

PC_D

PMas

ter_

DO

KU_v

10_e

2

1045

282

Structure of ItemID The ItemID (e.g. DP:[CP 5613 A2]Slave005M02_IB0) is composed of the protocol ID, the connection name, slave address, module number and I/O address. DP:[<connection name>]Slave<address>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 Server object When establishing a connection with the OPC DA server, COM object "OPCServer" is created which can be accessed via different COM interfaces. Apart from administration functions, it mainly offers access to information on the address space, and enables creating and deleting of groups. In this example only the groups are created and deleted via this object. 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.

Groups and items The items of the OPC server must be grouped for data exchange via the COM object "OPCGroup“. Thereby the group settings apply to all items in the group. The most important properties are hereby the active status and the update rate. If the group is active, the OPC server forms an intermediate storage (cache) for values, quality and time stamp for items within this group. The OPC server updates this cache respectively after the update time has elapsed. An item represents a value within the process, it can be entered by the OPC client into several groups. Thereby the status of the item in the other groups cannot be influenced. Only with writing a new value onto the item does the value also change in the other groups. Unless an item is contained in a group, no data exchange occurs between the OPC server and the process.

Page 25: 21045282 Opc Dpmaster Doku v10 e

Function principles and program structures

General Function Mechanisms

OPC DP Master

V 1.0 Issue 25th Nov 2004 25/61

Cop

yrig

ht ©

Sie

men

s AG

200

4 Al

l rig

hts

rese

rved

21

0452

82_O

PC_D

PMas

ter_

DO

KU_v

10_e

2

1045

282

Access structure on the process variables The following figure illustrates the access structure with which you can access process variables via the OPC server. Figure 3-5

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. 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.

Page 26: 21045282 Opc Dpmaster Doku v10 e

Function principles and program structures

General Function Mechanisms

OPC DP Master

V 1.0 Issue 25th Nov 2004 26/61

Cop

yrig

ht ©

Sie

men

s AG

200

4 Al

l rig

hts

rese

rved

21

0452

82_O

PC_D

PMas

ter_

DO

KU_v

10_e

2

1045

282

3.4.2 OPC DA data access

Types of data access The following figure gives an overview of the different types of data access used in this example. The arrows symbolize the call direction. Figure -6

Explanation of access types The following table lists the access types illustrated in the figure above. Table 3-2

No. Instructions 1 Polling information on the address space. (Not used in this example) 2 Reading the current values from the cache. 3 Cyclic reporting of changed values from server to client. 4 Reading the current values directly from the device (process image in the

CP) 5 Writing values. Call always goes to the device. 6 Cyclic updating of values in the cache of the OPC server. (UpdateRate)

Page 27: 21045282 Opc Dpmaster Doku v10 e

Function principles and program structures

General Function Mechanisms

OPC DP Master

V 1.0 Issue 25th Nov 2004 27/61

Cop

yrig

ht ©

Sie

men

s AG

200

4 Al

l rig

hts

rese

rved

21

0452

82_O

PC_D

PMas

ter_

DO

KU_v

10_e

2

1045

282

Reading values of the items from cache or device The items of a group can be read from the cache or from the device (device or process value directly at the source). When reading from the cache, the communication between OPC server and device is not affected. This communication to the device is mostly the bottleneck of data throughput between device and OPC client. Updating the cache can be optimized from the OPC server independently of the read calls. Reading directly from the device takes as long until all values have been read directly from the device. For a slower communication or larger data amount this may take up to several seconds. Reading from the device is recommended if the value is read in very irregular intervals only and therefore a cyclic update of the cache 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. 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.

Reporting value changes For applications in which the data must be updated cyclically in the OPC client, there is a better mechanism than reading from the cache. In this case the OPC client can have the changed values sent to it after the update time of the group. A typical application case is the visualization of process values. In order to be able to receive the OnDataChange event from the OPC server, the OPC client must implement a callback object with the IOPCDataCallback interface, and log on this object at the OPC server.

Writing values to the OPC server The values of the items of a group can also be written from the client. By definition, writing is performed directly onto the device.

Group calls All methods at the group object affecting 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 number and size of the data packages to the device than reading or writing the values individually.

Page 28: 21045282 Opc Dpmaster Doku v10 e

Function principles and program structures

Function Mechanisms of this Application

OPC DP Master

V 1.0 Issue 25th Nov 2004 28/61

Cop

yrig

ht ©

Sie

men

s AG

200

4 Al

l rig

hts

rese

rved

21

0452

82_O

PC_D

PMas

ter_

DO

KU_v

10_e

2

1045

282

4 Function Mechanisms of this Application

Here you will find information on … the functionality offered by the OPC client, how PROFIBUS, OPC server and OPC client function mechanism work together, and how this has been realized in a C++ class model.

4.1 Functionality of the OPC Client

The OPC client application shows two different application options of OPC and its realization in a C++ application.

• The first 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 second application is the realization of a control task in C++, whereby the process image of the inputs and outputs is transferred via OPC Data Access.

User interface of the application The following figure shows the user interface of the OPC client. Figure 4-1

Page 29: 21045282 Opc Dpmaster Doku v10 e

Function principles and program structures

Function Mechanisms of this Application

OPC DP Master

V 1.0 Issue 25th Nov 2004 29/61

Cop

yrig

ht ©

Sie

men

s AG

200

4 Al

l rig

hts

rese

rved

21

0452

82_O

PC_D

PMas

ter_

DO

KU_v

10_e

2

1045

282

Functionality of the user interface The user interface serves for visualizing process values and the PROFIBUS DP status values. The example implementation shows the realization of a visualization functionality in C++. Here it is possible to establish and cancel the connection to the OPC server as well as starting and stopping the control function. The input and output modules of the configured PROFIBUS DP slave are visualized as process values. The values of the inputs with two input words and one input byte are only displayed. The values of the outputs with four output words and one output byte can also be changed and written to the OPC server, if the controller is not active. This enables manual control. If the controller is active, the input fields are blocked, as the output values are cyclically written by the controller which makes manual setting unreasonable. After establishing a connection with the OPC server, the status of the DP master as well as the status values Slave Type, Slave State and Slave Diagnosis of the configured slave are displayed.

Functionality of the controller The functionality of the controller is of particular interest due to the performance advantages with C++ and the application of the Inproc PROFIBUS DP OPC server. In this part of the example it is shown how during starting the controller a separate thread is started for the control task, how the process image is exchanged, and how the OPC server is initialized optimally for this. This part of the application is executed in a separate thread in order to avoid mutual disturbance between display and controller. After the initialization of the OPC server, the process image of the inputs (PII) is cyclically read from the OPC sever, the control functionality is executed and the process image of the outputs (PIQ) is written to the OPC server.

Functionality of the control program The actual control functionality gives only an example of how the input values and the output values can be used.

• Depending on input 4.0, input bits are either copied to the output bits, or the value of the output byte 4 is changed so that an LED chaser is created. The input words 0 and 2 are copied to the output words 0 and 2.

• A sinus function is generated for output word 4. The frequency depends on the value of input byte 4.

• Output word 6 is set to the mean value from input words 0 and 2 and the output word 4.

Note The control function can be replaced by almost any control function.

Page 30: 21045282 Opc Dpmaster Doku v10 e

Function principles and program structures

Function Mechanisms of this Application

OPC DP Master

V 1.0 Issue 25th Nov 2004 30/61

Cop

yrig

ht ©

Sie

men

s AG

200

4 Al

l rig

hts

rese

rved

21

0452

82_O

PC_D

PMas

ter_

DO

KU_v

10_e

2

1045

282

Used OPC items The following table lists the OPC items used for visualizing and controlling.

Table 4-1

Visualizing Controlling ItemID Data

Type Name User interface

Data Change

OPC Write

PII Read

PIQ Write

DP:[CP 5613 A2]Masterstate STRING Masterstate X DP:[CP 5613 A2]Slave005MiscSlvType STRING Slave Type X DP:[CP 5613 A2]Slave005SlvState STRING Slave State X DP:[CP 5613 A2]Slave005SlvDiag BYTE[ ] Slave

Diagnosis X

DP:[CP 5613 A2]Slave005M00_IW0 WORD Word 0 In X X DP:[CP 5613 A2]Slave005M00_IW2 WORD Word 2 In X X DP:[CP 5613 A2]Slave005M01_QW0 WORD Word 0 Out X X X DP:[CP 5613 A2]Slave005M01_QW2 WORD Word 2 Out X X X DP:[CP 5613 A2]Slave005M01_QW4 WORD Word 4 Out X X X DP:[CP 5613 A2]Slave005M01_QW6 WORD Word 6 Out X X X DP:[CP 5613 A2]Slave005M02_IX0.0,1 BOOL 4.0 Input X DP:[CP 5613 A2]Slave005M02_IX0.1,1 BOOL 4.1 Input X DP:[CP 5613 A2]Slave005M02_IX0.2,1 BOOL 4.2 Input X DP:[CP 5613 A2]Slave005M02_IX0.3,1 BOOL 4.3 Input X DP:[CP 5613 A2]Slave005M02_IX0.4,1 BOOL 4.4 Input X DP:[CP 5613 A2]Slave005M02_IX0.5,1 BOOL 4.5 Input X DP:[CP 5613 A2]Slave005M02_IX0.6,1 BOOL 4.6 Input X DP:[CP 5613 A2]Slave005M02_IX0.7,1 BOOL 4.7 Input X DP:[CP 5613 A2]Slave005M02_QX0.0,1 BOOL 8.0 Output X X DP:[CP 5613 A2]Slave005M02_QX0.1,1 BOOL 8.1 Output X X DP:[CP 5613 A2]Slave005M02_QX0.2,1 BOOL 8.2 Output X X DP:[CP 5613 A2]Slave005M02_QX0.3,1 BOOL 8.3 Output X X DP:[CP 5613 A2]Slave005M02_QX0.4,1 BOOL 8.4 Output X X DP:[CP 5613 A2]Slave005M02_QX0.5,1 BOOL 8.5 Output X X DP:[CP 5613 A2]Slave005M02_QX0.6,1 BOOL 8.6 Output X X DP:[CP 5613 A2]Slave005M02_QX0.7,1 BOOL 8.7 Output X X DP:[CP 5613 A2]Slave005M02_IB0 BYTE X DP:[CP 5613 A2]Slave005M02_QB0 BYTE X

Page 31: 21045282 Opc Dpmaster Doku v10 e

Function principles and program structures

Function Mechanisms of this Application

OPC DP Master

V 1.0 Issue 25th Nov 2004 31/61

Cop

yrig

ht ©

Sie

men

s AG

200

4 Al

l rig

hts

rese

rved

21

0452

82_O

PC_D

PMas

ter_

DO

KU_v

10_e

2

1045

282

Description 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 5613 A2 as connection name,

• Slave005 for the Slave with the PROFIBUS address 5,

• M00 to M02 for the Slave module and

• I for input and Q for output, W, X and B for the data types Word, Bool and Byte and the Byte address in the input area 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. As for an S7 control program, inputs and outputs are continuously 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.

Controlling column The controlling column specifies which items of the controlling thread are used for the process image.

• The OPC items for the PII (process image inputs) are read via an inactive group.

• The OPC items for the PIQ (process image outputs) are written via an inactive group.

• The input and output bits of slave module 2 are, as opposed to visualizing, not read or written individually but as bytes.

Note The result is, that – as specified in Table 4-1 – certain process variables are depicted twice in different groups on different OPC items. This illustrates the different application purposes.

Page 32: 21045282 Opc Dpmaster Doku v10 e

Function principles and program structures

Function Mechanisms of this Application

OPC DP Master

V 1.0 Issue 25th Nov 2004 32/61

Cop

yrig

ht ©

Sie

men

s AG

200

4 Al

l rig

hts

rese

rved

21

0452

82_O

PC_D

PMas

ter_

DO

KU_v

10_e

2

1045

282

4.2 Function mechanisms of the OPC Client

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. The arrows indicate the call direction of the method calls. Figure 4-2

Explanation of the diagram The following table explains the interaction of the function blocks in OPC client and the objects in the OPC server as depicted above. Table 4-2

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, as well as 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 memory of the CP5613. 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 CP5613 is written to via the OPC management.

Page 33: 21045282 Opc Dpmaster Doku v10 e

Function principles and program structures

Function Mechanisms of this Application

OPC DP Master

V 1.0 Issue 25th Nov 2004 33/61

Cop

yrig

ht ©

Sie

men

s AG

200

4 Al

l rig

hts

rese

rved

21

0452

82_O

PC_D

PMas

ter_

DO

KU_v

10_e

2

1045

282

4 Starting the controller generates a separate thread in which a separate connection with the OPC server is established with an inactive group. After this initialization, the PII is read cyclically, the control function is executed and the PIQ is written.

5 The PII is read directly from the device (CP 5613) via the OPC management and the group in the server.

6 The PIQ is written to the device (CP 5613) via the OPC management and the group in the server.

Function mechanisms PROFIBUS • Starting the OPC servers makes the CP 5613 active as PROFIBUS DP

master, initializes the DP slaves and starts the PROFIBUS cycle.

• In each PROFIBUS cycle, the master updates the outputs at the DP slaves from the process image and updates the process image from the inputs of the DP slaves.

Function mechanisms for the visualization user interface • The functionality of the visualization user interface is executed in the

main thread of the C++ application.

• During connection an OPC management is created for the user interface. An OPCServer object and an active OPCGroup object are generated in the OPC DA server process via this OPC management. A callback connection is established for updating the values in the user interface.

• The cache in the active group is cyclically (UpdateRate) updated by reading the values from the CP 5613. If the value of an OPC Item changes within the UpdateRate, the changed values are sent to the user interface via the Callback connection.

Function mechanisms for controlling • The controlling functionality is executed in a separate thread.

• After generating the new thread, an OPC management is created. An OPCServer object and an inactive OPCGroup object are generated for the data transfer in the OPC DA server process via this OPC management.

• The inactive group has no cache. This is not required as the read and write calls are directly executed from the device.

• After the initialization the control functionality is cyclically executed in a loop, until the controller is stopped. During the cycle, the PII is read via OPC, the control function is executed and the PIQ written via OPC.

Page 34: 21045282 Opc Dpmaster Doku v10 e

Function principles and program structures

Function Mechanisms of this Application

OPC DP Master

V 1.0 Issue 25th Nov 2004 34/61

Cop

yrig

ht ©

Sie

men

s AG

200

4 Al

l rig

hts

rese

rved

21

0452

82_O

PC_D

PMas

ter_

DO

KU_v

10_e

2

1045

282

4.2.2 Cycle times

Two cycle times can be set within the application. The setting is made via the 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.

Controlling cycle time • 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 70 µs results on a PC with P4 2.4 GHz at 100% processor load. At a pause time of 1 ms the processor load is below 5 %.

• The time for executing the simple control function is compared with the time for the OPC calls neglectable.

• 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 is recommended to not select the pause times smaller than 10 ms, as the variation range in relation to the overall cycle time would hardly be noticeable.

Fluctuating

Fixed time

Cyc

le ti

me

Page 35: 21045282 Opc Dpmaster Doku v10 e

Function principles and program structures

Function Mechanisms of this Application

OPC DP Master

V 1.0 Issue 25th Nov 2004 35/61

Cop

yrig

ht ©

Sie

men

s AG

200

4 Al

l rig

hts

rese

rved

21

0452

82_O

PC_D

PMas

ter_

DO

KU_v

10_e

2

1045

282

4.3 Class diagram of the OPC Client

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 sequence charts are explained in chapter 7 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.

Figure 4-4

Page 36: 21045282 Opc Dpmaster Doku v10 e

Function principles and program structures

Function Mechanisms of this Application

OPC DP Master

V 1.0 Issue 25th Nov 2004 36/61

Cop

yrig

ht ©

Sie

men

s AG

200

4 Al

l rig

hts

rese

rved

21

0452

82_O

PC_D

PMas

ter_

DO

KU_v

10_e

2

1045

282

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. CControl Controlling CMemoryMap Controlling

Generally usable for controlling. Modifications necessary for size of the process image.

CThread Controlling 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 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.

OnBtnDisconnectClick Disconnecting from the OPC server. OnBtnWriteAOClick OnBtnWriteDOClick

Manual writing of output values.

DataChange Receiving the value changes from the OPC server and writing the values into the user interface elements.

OnBtnRunClick Starting the control functionality. This creates an instance of the CControl class and the thread for executing the control functionality in the object is started.

OnBtnStopClick Stopping the control functionality.

Page 37: 21045282 Opc Dpmaster Doku v10 e

Function principles and program structures

Function Mechanisms of this Application

OPC DP Master

V 1.0 Issue 25th Nov 2004 37/61

Cop

yrig

ht ©

Sie

men

s AG

200

4 Al

l rig

hts

rese

rved

21

0452

82_O

PC_D

PMas

ter_

DO

KU_v

10_e

2

1045

282

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 COPCServerMgt encapsules the OPC object OPCServer and enables 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 Adding items to the group. 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. Deactivating the Callback. DisconnectCallback

Note: Deactivates receiving of events from the OPC server. The group itself remains active.

Page 38: 21045282 Opc Dpmaster Doku v10 e

Function principles and program structures

Function Mechanisms of this Application

OPC DP Master

V 1.0 Issue 25th Nov 2004 38/61

Cop

yrig

ht ©

Sie

men

s AG

200

4 Al

l rig

hts

rese

rved

21

0452

82_O

PC_D

PMas

ter_

DO

KU_v

10_e

2

1045

282

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 CDataCallback 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.

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.

Page 39: 21045282 Opc Dpmaster Doku v10 e

Function principles and program structures

Function Mechanisms of this Application

OPC DP Master

V 1.0 Issue 25th Nov 2004 39/61

Cop

yrig

ht ©

Sie

men

s AG

200

4 Al

l rig

hts

rese

rved

21

0452

82_O

PC_D

PMas

ter_

DO

KU_v

10_e

2

1045

282

Class CControl The CControl class has been derived from the CThread and implements the control functionality executed 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 control functionality is executed in a loop until the thread is terminated.

ReadMemoryMap In this method the process image is read from the OPC server and stored in MemoryMap.

WriteMemoryMap Here the process image is taken from the MemoryMap and written into the OPC server.

ControlFunction In this method the actual control functionality has been implemented. It corresponds to the OB1 of the PLC.

ThreadLeave Overwrites the method of the base class. In this method the OPC connection is terminated.

Class CMemoryMap CMemoryMap manages the process image of the PII inputs and the PIQ outputs during a cycle.

Table 4-10

Method Functionality

WriteInput This method updates the PII. ReadOutput This method reads the PIQ at the end of a control cycle. GetIn This method enables accessing the individual input variables in the

control program. SetOut This method enables accessing the individual output variables in the

control program.

Page 40: 21045282 Opc Dpmaster Doku v10 e

Function principles and program structures

Description of the Sample Code

OPC DP Master

V 1.0 Issue 25th Nov 2004 40/61

Cop

yrig

ht ©

Sie

men

s AG

200

4 Al

l rig

hts

rese

rved

21

0452

82_O

PC_D

PMas

ter_

DO

KU_v

10_e

2

1045

282

5 Description of the Sample Code

This chapter describes the dynamic sequence charts using UML sequence diagrams. Details of the source code are not discussed here. The source code is commented in detail in the project files.

5.1 Sequence diagrams for the visualization user interface

Connecting to the OPC server. The following sequence diagram shows the sequence chart upon clicking the "Connect" button in the user interface.

Figure 5-1

12

3

4

5

6

Page 41: 21045282 Opc Dpmaster Doku v10 e

Function principles and program structures

Description of the Sample Code

OPC DP Master

V 1.0 Issue 25th Nov 2004 41/61

Cop

yrig

ht ©

Sie

men

s AG

200

4 Al

l rig

hts

rese

rved

21

0452

82_O

PC_D

PMas

ter_

DO

KU_v

10_e

2

1045

282

Explanation Table 5-1

No. Description 1 Clicking "Connect“: Calls the OnBtnConnectClick method of 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 transmitted to the OPCServerMgtUI object in the AddGroup method. There the properties of the group for the AddGroup call to the OPC server are retrieved from this object. 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.

5 After adding the item the list of the OPCItemMgt management objects for the items is 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 assigned 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.

Writing output variables If the user of the application presses the "Write Output" button for the analog outputs, the event handling method OnBtnWriteAOClick is called in the UserInterface object. In this method, the values are read from the user interface and transmitted to the Write method of the OPCGroupMgtUI object and thus written to the OPC server. The sequence for writing the digital outputs is analog to the sequence for the analog outputs.

Page 42: 21045282 Opc Dpmaster Doku v10 e

Function principles and program structures

Description of the Sample Code

OPC DP Master

V 1.0 Issue 25th Nov 2004 42/61

Cop

yrig

ht ©

Sie

men

s AG

200

4 Al

l rig

hts

rese

rved

21

0452

82_O

PC_D

PMas

ter_

DO

KU_v

10_e

2

1045

282

Figure 5-2

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 group. 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 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.

1

2

Page 43: 21045282 Opc Dpmaster Doku v10 e

Function principles and program structures

Description of the Sample Code

OPC DP Master

V 1.0 Issue 25th Nov 2004 43/61

Cop

yrig

ht ©

Sie

men

s AG

200

4 Al

l rig

hts

rese

rved

21

0452

82_O

PC_D

PMas

ter_

DO

KU_v

10_e

2

1045

282

5.2 Sequence diagrams for the control functionality

Starting the control functionality The following sequence diagram shows the sequence chart upon clicking the "Run" button for starting the controlling process.

Figure 5-4

12

3

4

5

6

7

Page 44: 21045282 Opc Dpmaster Doku v10 e

Function principles and program structures

Description of the Sample Code

OPC DP Master

V 1.0 Issue 25th Nov 2004 44/61

Cop

yrig

ht ©

Sie

men

s AG

200

4 Al

l rig

hts

rese

rved

21

0452

82_O

PC_D

PMas

ter_

DO

KU_v

10_e

2

1045

282

Explanation Table 5-3

No. Description 1 Clicking "Connect“ calls the OnBtnConnectClick method at the UserInterface object. In this

method an instance of the CControl class is generated and the StartThread method called at the Control object.

2 The statistical method Run and the object pointer of Control are transmitted to the new thread. This calls the statistical method Run in the new thread. In this method the ThreadMain method can then be called at the Control object via the object indicator. 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 generated by COPCGroupMgt and the instance is transmitted to OPCServerMgt in the 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 from the OPC server are stored in two lists for reading and writing, as the items are either read or written.

6 Creating and initializing an instance of the CMemoryMap class for managing the process image.

7 Calling the DoWork method in which the actual functionality of the thread is processed. Here the control functionality is executed in a loop until the "Stop" button is clicked in the user interface and the thread is stopped. Processing the control functionality in a loop is illustrated in the following sequence diagram.

Note When generating the instance of COPCGroupMgt the activeness status of the group is transmitted as inactive. This is important as the cache of the OPC server is not necessary in this application which puts load off the OPC server.

Page 45: 21045282 Opc Dpmaster Doku v10 e

Function principles and program structures

Description of the Sample Code

OPC DP Master

V 1.0 Issue 25th Nov 2004 45/61

Cop

yrig

ht ©

Sie

men

s AG

200

4 Al

l rig

hts

rese

rved

21

0452

82_O

PC_D

PMas

ter_

DO

KU_v

10_e

2

1045

282

Executing the control functionality A cycle of the control with reading the process image of the inputs, executing the control functionality and writing the process image of the outputs is explained in the following sequence diagram.

Figure 5-5

Explanation Table 5-4

No. Description 1 The method is called after starting the thread. See previous sequence diagram. In this

method the control functionality is processed in a loop until the thread is terminated via the user interface.

2 First the PII is read via the ReadMemoryMap method. Thereby the server handles for the OPC Read call stored during initialization are used via OPCGroupMgtControl. The values returned by Read are updated in the MemoryMap object via the WriteInput method. The values are read from the device directly and not from the cache.

1

2PAE Reading

PAA Writing

Controlling

3

4

Page 46: 21045282 Opc Dpmaster Doku v10 e

Function principles and program structures

Description of the Sample Code

OPC DP Master

V 1.0 Issue 25th Nov 2004 46/61

Cop

yrig

ht ©

Sie

men

s AG

200

4 Al

l rig

hts

rese

rved

21

0452

82_O

PC_D

PMas

ter_

DO

KU_v

10_e

2

1045

282

No. Description 3 In the ControlFunction method the actual control functionality is implemented. Access to

the process image thereby occurs via the GetInX methods for inputs and SetOutX for the outputs. Thereby each data type has its own Set And Get method. GetInBool enables accessing individual input bits, or SetOutWord an output word, for example. In the sample implementation bits are only copied exemplary from the input to the output or a sinus function is generated, whereby the frequency depends on the number of active inputs.

Note This function can also be replaced with an own control function.

4 At the end of the cycle, the PII is written via the WriteMemoryMap method. The values of the outputs are read from the MemoryMap object with the ReadOutput method and written to the OPC server via the OPCGroupMgt object.

The pause time at the end of a cycle (at the end of the while loop) is realized by the Windows system call MsgWaitForMultipleObjects.

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 controller: • 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 controller. In the error-free state the color is green and in case of an error it is red.

• In case of an error an error flag is set in the Control object.

• If an error has occurred during reading the PII, the control function and writing of the PII are left out.

• 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.

Page 47: 21045282 Opc Dpmaster Doku v10 e

Function principles and program structures

Expanding and Using the Sample Code of the Client

OPC DP Master

V 1.0 Issue 25th Nov 2004 47/61

Cop

yrig

ht ©

Sie

men

s AG

200

4 Al

l rig

hts

rese

rved

21

0452

82_O

PC_D

PMas

ter_

DO

KU_v

10_e

2

1045

282

6 Expanding and Using the Sample Code of the Client

6.1 Expanding the sample code of the OPC client

Definition of the configuration data for the OPC client The configuration data for server, groups and items have been defined in the ServerDefines.h file in the following sections:

Table 6-1

No. Section Comment 1 OPC Server & Updaterate OPC server ProgID and group settings for the OPC

connection of the user interface. 2 Status ItemIDs of the PROFIBUS status items in the user

interface. 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 Control Function OPC Server ProgID, cycle time of controller ItemIDs of

the input and output variables for the process image.

Expanding the scope of the OPC client For expanding the scope, changes to the source code must be made at the following locations:

Table 6-2

No. Source code Comment 1 ServerDefines.h file Supplementing definitions for additional ItemIDs and

adjusting definitions for the number of items. 2 UserInterface.cpp file

BuildItemArrays method Adjusting structure of item lists to the new items.

3 Control.cpp file BuildItemArrays method

Adjusting structure of item lists to the new items.

Page 48: 21045282 Opc Dpmaster Doku v10 e

Function principles and program structures

Expanding and Using the Sample Code of the Client

OPC DP Master

V 1.0 Issue 25th Nov 2004 48/61

Cop

yrig

ht ©

Sie

men

s AG

200

4 Al

l rig

hts

rese

rved

21

0452

82_O

PC_D

PMas

ter_

DO

KU_v

10_e

2

1045

282

6.2 Using OPC in own Visual Studio .NET C++ project

This chapter contains a description of the steps necessary for creating a new C++ project in Visual Studio, in which the OPC is to be used. Further information is available in the documentation on Visual Studio .NET.

Table 6-3

No. Instruction Comment / screenshot 1 Open Microsoft Visual Studio

.NET 2003.

2 Create new project and select Visual C++ MFC as project type in the left hand pane. On the right hand pane select the MFC Application template and specify name and storage location of the project. After clicking OK a further dialog appears named MFC Application Wizard.

3 Select Application Type on

the left side in the blue field. Select Dialog based on the then displayed page. Pressing the Finish button creates the project with the settings 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 sample project or be obtained directly from the website of the OPC Foundation (www.opcfoundation.org).

Page 49: 21045282 Opc Dpmaster Doku v10 e

Function principles and program structures

Expanding and Using the Sample Code of the Client

OPC DP Master

V 1.0 Issue 25th Nov 2004 49/61

Cop

yrig

ht ©

Sie

men

s AG

200

4 Al

l rig

hts

rese

rved

21

0452

82_O

PC_D

PMas

ter_

DO

KU_v

10_e

2

1045

282

No. Instruction Comment / screenshot 5 Open the context menu in the

Solution Explorer of the studio by right-clicking the Source Files folder. There you select Add Add Existing Item.

6 If necessary browse into the

project directory and select both C files (*.c). Pressing the Open buttons adds the files to the project.

7 Open the Properties Dialog for

both newly added files via the context menu (right mouse button) and select the Not using precompiled Header setting in Configuration Properties C/C++ Precompiled Header. Pressing the OK button acknowledges the changed settings.

8 Open the stdafx.h file in the

Solution Explorer with a double-click and include the OPC header files.

#include “opcda.h“ #include “opccomn.h“ #include “opcerror.h“

9 Compile project.

Note The OPC interface can be used project wide in every Code file which contains the reference #include “stdafx.h“.

Page 50: 21045282 Opc Dpmaster Doku v10 e

Function principles and program structures

Expanding and Using the Sample Code of the Client

OPC DP Master

V 1.0 Issue 25th Nov 2004 50/61

Cop

yrig

ht ©

Sie

men

s AG

200

4 Al

l rig

hts

rese

rved

21

0452

82_O

PC_D

PMas

ter_

DO

KU_v

10_e

2

1045

282

6.3 Using sample code in own Visual Studio .NET project

If the OPC classes from the example for encapsulating the OPC interface are being used, the following steps are necessary.

Note In the project the OPC classes require ATL Support.

Table 6-4

No. Instruction Note 10 Copy files into the project

directory:

OPCServerMgt.cpp, OPCServerMgt.h, OPCGroupMgt.cpp, OPCGroupMgt.h, OPCDataCallback.cpp, OPCDataCallback.h, DataCallback.h.

11 Add copied files to the project. Procedure see no.5 and no.6 in Table 8-3 12 Open the stdafx.h file via the

Solution Explorer with a double-click and add the following code lines.

#include <afxtempl.h> typedef CArray<VARIANT, VARIANT&> CVARIANTArray; typedef CArray<HRESULT, HRESULT&> CHRESULTArray;

User defined arrays, which user the MFC template Carray, are used in the newly added classes.

13 Add ATL Support to the project. Select Add -> Add Class in the Solution Explorer via the context menu of the project (right mouse button).

14 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.

Page 51: 21045282 Opc Dpmaster Doku v10 e

Structure, Configuration and Operation of the Application

Installation and Commissioning

OPC DP Master

V 1.0 Issue 25th Nov 2004 51/61

Cop

yrig

ht ©

Sie

men

s AG

200

4 Al

l rig

hts

rese

rved

21

0452

82_O

PC_D

PMas

ter_

DO

KU_v

10_e

2

1045

282

Structure, Configuration and Operation of the Application

Content This part leads you step by step through the structure, important configuration 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 necessary for commissioning the example.

7.1 Installation of Hardware and Software

This chapter describes the hardware and software components to be installed. The description and manuals as well as delivery information contained in the delivery scope of the respective products, should be followed in any case.

Hardware configuration The hardware components are available in chapter 2.2. For the hardware setup please proceed according to the following table:

! Attention

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 5613 into the PC station

according to the attached manual /6/. 2 PROFIBUS

Slave Set up the PROFIBUS Slave ET 200 M according to the figure in chapter 2.2.

3 PROFIBUS Connect the PC station with the PROFIBUS Slave analog to the figure in chapter 2.2.

Note Setup guidelines for PROFIBUS networks must generally be followed.

Software The software components are available in chapter 2.2.

Page 52: 21045282 Opc Dpmaster Doku v10 e

Structure, Configuration and Operation of the Application

Installation and Commissioning

OPC DP Master

V 1.0 Issue 25th Nov 2004 52/61

Cop

yrig

ht ©

Sie

men

s AG

200

4 Al

l rig

hts

rese

rved

21

0452

82_O

PC_D

PMas

ter_

DO

KU_v

10_e

2

1045

282

Commissioning the example requires the following components from SIMATIC NET CD V6.2:

• SIMATIC NET PC products

• SIMATIC NCM PC/S7

Note SIMATIC NCM PC/S7 needs only be installed if no STEP 7 has been installed on the PC.

Microsoft Visual Studio .NET Microsoft Visual Studio .Net Professional is only required on the SIMATIC PC station if the example code needs to be changed. Alternatively the development environment can be installed on a separate PC (e.g. Engineering Station).

Note During the installation of Visual Studio .Net the safety settings of the Windows operating system are loosened. After installing the development environment pleas check the safety of the SIMATIC PC station and if necessary install Window updates.

7.2 Commissioning the SIMATIC PC station

This chapter describes commissioning the PC station with the configuration of the PC station via an XDB file for the hardware configuration described in chapter 2. Successful installation of all hardware and software components is a prerequisite.

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 0. The following steps are necessary for loading the PC station.

Table 7-2

No. Instructions Note 1 Dearchiving the project Extract the

21045282_OPC_DPMaster_CODES7_v10.zip file. 2 Open the Components

Configurator by double-

clicking the icon in the task bar.

3 Click Import Station Confirm the query with Yes

Page 53: 21045282 Opc Dpmaster Doku v10 e

Structure, Configuration and Operation of the Application

Installation and Commissioning

OPC DP Master

V 1.0 Issue 25th Nov 2004 53/61

Cop

yrig

ht ©

Sie

men

s AG

200

4 Al

l rig

hts

rese

rved

21

0452

82_O

PC_D

PMas

ter_

DO

KU_v

10_e

2

1045

282

4 Select the XDB file The XCB file is available in the XDBs sub-directory of the extracted ZIP-file.

5 After importing the XDB file the PC station has been configured.

Note The explanations on configuring the PC station in chapter 0 are only necessary if the hardware configuration differs from that descried in chapter 1.2.

7.3 Commissioning the OPC Client

The user interface and the source code of the application are delivered as ZIP file. Starting the user interface on the SIMATIC PC station requires the following steps:

Table 7-3

No. Instructions Note 1 Extracting the

21045282_OPC_DPMaster_CODEPC_v10.zip file Contains the executable file and a source code.

2 Double-click the OpcClientDPMaster.exe file Starts the sample application.. The application is now runnable

Page 54: 21045282 Opc Dpmaster Doku v10 e

Structure, Configuration and Operation of the Application

Installation and Commissioning

OPC DP Master

V 1.0 Issue 25th Nov 2004 54/61

Cop

yrig

ht ©

Sie

men

s AG

200

4 Al

l rig

hts

rese

rved

21

0452

82_O

PC_D

PMas

ter_

DO

KU_v

10_e

2

1045

282

User interface of the application The elements of the user interface are described in the figure below Figure 7-1

Elements of the user interface Table 7-4

No. Description 1 Connecting to and disconnecting from OPC server and display of

Masterstate 2 Starting and stopping the control functionality and display of the OPC Error

status in the controller. (Changes to red if an OPC error occurs in the controller)

3 Status of the PROFIBUS Slave with Slave Type, Slave State and Slave Diagnosis.

4 Visualizing the values of the analog input module of the slave. 5 Visualizing the values of the analog output module of the slave. If the

control functionality has been stopped the output values can be written. 6 visualizing the digital input and output module. If the control functionality

has been stopped the output values can be written. 7 Output field for OPC error messages.

If the output 4-0 has been set at the slave, an LED chaser will be generated by the control program on all outputs. If input 4.0 has not been set, the input byte 4 in the control program is copied to the output byte 0.

Page 55: 21045282 Opc Dpmaster Doku v10 e

Structure, Configuration and Operation of the Application

SIMATIC NET Configuration

OPC DP Master

V 1.0 Issue 25th Nov 2004 55/61

Cop

yrig

ht ©

Sie

men

s AG

200

4 Al

l rig

hts

rese

rved

21

0452

82_O

PC_D

PMas

ter_

DO

KU_v

10_e

2

1045

282

8 SIMATIC NET Configuration

Here you will find information on … the configuration steps necessary if the hardware deviates from the hardware 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) and can be configured. This means that the configuration information from STEP 7 or HW Config can be loaded as for a SIMATIC S7 station.

Table 8-1

No. Instructions Note

1 Starting the Configurations Console

2 Select CP and set Configured mode.

3 Confirm selection and close

the dialog.

8.2 Configuring the PC station

The configuration of the SIMATIC PC station is performed with STEP 7 and described step by step. Alternatively, this can also be performed using the NCM-PROFIBUS software package. The procedure is identical.

Page 56: 21045282 Opc Dpmaster Doku v10 e

Structure, Configuration and Operation of the Application

SIMATIC NET Configuration

OPC DP Master

V 1.0 Issue 25th Nov 2004 56/61

Cop

yrig

ht ©

Sie

men

s AG

200

4 Al

l rig

hts

rese

rved

21

0452

82_O

PC_D

PMas

ter_

DO

KU_v

10_e

2

1045

282

Table 8-2

No. Instructions Note 1 Starting the SIMATIC

Manager and creating new project.

The name “OPCMaster“ was used here.

2 Insert SIMATIC PC Station and specify name. The name of the PC station must be identical with the station name in the Component configurator of the station.

3 Open PC Station with HW-

Config and insert CP. The slot must be identical with the index which was assigned in the configuration console, here index "1".

4 Enter application (here OPC

server) The used OPC Server must be selected according to the SIMATIC NET Version, here V6.2.

Page 57: 21045282 Opc Dpmaster Doku v10 e

Structure, Configuration and Operation of the Application

SIMATIC NET Configuration

OPC DP Master

V 1.0 Issue 25th Nov 2004 57/61

Cop

yrig

ht ©

Sie

men

s AG

200

4 Al

l rig

hts

rese

rved

21

0452

82_O

PC_D

PMas

ter_

DO

KU_v

10_e

2

1045

282

No. Instructions Note 5 Add PROFIBUS network and

specify the PROFIBUS-address of the master. The setting here is PROFIBUS DP with 1.5 MBit/s and the PROFIBUS address 2 for the Master.

6 The operating mode of the CP

5613 is set to DP-Master. DPV1 is selected as a standard. The assigned application connecting as DP master is in this case the OPC Server.

7 Add DP slave and assign a

PROFIBUS address. At ET 200M the PROFIBUS address has been set with dip switches, here 5.

Page 58: 21045282 Opc Dpmaster Doku v10 e

Structure, Configuration and Operation of the Application

SIMATIC NET Configuration

OPC DP Master

V 1.0 Issue 25th Nov 2004 58/61

Cop

yrig

ht ©

Sie

men

s AG

200

4 Al

l rig

hts

rese

rved

21

0452

82_O

PC_D

PMas

ter_

DO

KU_v

10_e

2

1045

282

No. Instructions Note 8 Inserting input and output

modules. The addresses within the module are automatically assigned here.

9 Saving compiling and loading

configuration (into PC station). Note: The access point S7ONLINE, used by STEP 7, must be set to "PC internal (local)“. After successful loading, HW-Config and the SIMATIC Manager are closed.

10 The Component Configurator shows the current state of the SIMATIC PC Station.

Starting with the icon in the taskbar.

Page 59: 21045282 Opc Dpmaster Doku v10 e

Structure, Configuration and Operation of the Application

SIMATIC NET Configuration

OPC DP Master

V 1.0 Issue 25th Nov 2004 59/61

Cop

yrig

ht ©

Sie

men

s AG

200

4 Al

l rig

hts

rese

rved

21

0452

82_O

PC_D

PMas

ter_

DO

KU_v

10_e

2

1045

282

8.3 Testing with OPC Scout

Overview 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-3

No. Instructions Note 1 Starting the OPC Scout. Start SIMATIC SIMATIC NET PROFIBUS

CP5613_CP5614 OPC Scout 2 Connecting with the Inproc

OPC server OPC.SimaticNet.DP with double-click. During the connecting process, the OPC server is started (this also starts the DP master) and only then does the master send the configuration telegram. Only now does the bus error LED of the slave turn off.

3 Creating a group.

At least one active group must be created. The OPC Scout displays all data event-controlled (for changes).

Page 60: 21045282 Opc Dpmaster Doku v10 e

Structure, Configuration and Operation of the Application

SIMATIC NET Configuration

OPC DP Master

V 1.0 Issue 25th Nov 2004 60/61

Cop

yrig

ht ©

Sie

men

s AG

200

4 Al

l rig

hts

rese

rved

21

0452

82_O

PC_D

PMas

ter_

DO

KU_v

10_e

2

1045

282

No. Instructions Note 4 Browsing the address space

and selecting the OPC item. The address space of the server should display exactly one slave (according to configuration on the right).

5 Displaying items and system

variables. In addition to the configured modules the slave has so-called system variables such as SlaveState. All variables should be displayed in GOOD quality.

6 Terminating OPC Scout.

When terminating the client, the OPC server is also terminated.

Note When terminating the client, the OPC server is also terminated. Due to the fact, that then there will be no active DP master at the PROFIBUS, the slave indicates a bus error.

Page 61: 21045282 Opc Dpmaster Doku v10 e

Appendix and List of Further Literature

Bibliographic References

OPC DP Master

V 1.0 Issue 25th Nov 2004 61/61

Cop

yrig

ht ©

Sie

men

s AG

200

4 Al

l rig

hts

rese

rved

21

0452

82_O

PC_D

PMas

ter_

DO

KU_v

10_e

2

1045

282

Appendix and List of Further Literature

9 Bibliographic References

Bibliographic References This list is by no means exhaustive and only gives a selection of appropriate sources. After SIMATIC NET product installation has been completed, the manuals are available in the documentation directory on the target computer at: Start SIMATIC Documentation [Language]. The Product Support is available on the internet at: http://support.automation.siemens.com/ (There you enter the entry ID into the search field). Table 9-1

Topic Title 1 OPC Data Access 2.05a specification

On the SIMATIC NET documentation CD-Rom or on the OPC Foundation website as a download www.opcfoundation.org

OPC Custom Interface, Interface description

2 Manual about standards, topologies and devices as well as installation guidelines. On the SIMATIC NET documentation CD-Rom In the Product Support at the entry ID: 1172302

SIMATIC NET PROFIBUS-networks

3 Description or information on: • General information on the PC tools • Functions of NCM PC Installed by SIMATIC NET, see: Start SIMATIC Documentation German In the Product Support at the entry ID: 13542666

Commissioning of SIMATIC NET PC stations – instruction and quick start for SIMATIC NCM PC / STEP 7 from version V5.2 and up.

4 Manual for industrial communication on PG/PC with SIMATIC NET. Installed by SIMATIC NET, see: Start SIMATIC Documentation German In the Product Support at the entry ID: 2044387

SIMATIC NET – Industrial Communication with PG/PC

5 Manual for SIMATIC Rack PC IL40 S V2 In the Product Support at the entry ID: 19250619

SIMATIC Rack PC IL40 S V2 Manual

6 Installation instruction CP 5613 / 14, FO and A2 In the Product Support at the entry ID: 13664901.

Product information / installation instruction