+ All Categories
Home > Documents > Application for Communication - Siemens...• The S7-300 must not save unused data, but only...

Application for Communication - Siemens...• The S7-300 must not save unused data, but only...

Date post: 25-Dec-2019
Category:
Upload: others
View: 8 times
Download: 0 times
Share this document with a friend
54
Application for Communication External Block Management with S7 Block Management Services of the SIMATIC NET OPC Server Example in Visual Basic.NET
Transcript
Page 1: Application for Communication - Siemens...• The S7-300 must not save unused data, but only requires the blocks necessary for the program sequence. All further blocks are saved on

Application for Communication

External Block Management with S7 Block Management Services of the SIMATIC NET OPC Server

Example in Visual Basic.NET

Page 2: Application for Communication - Siemens...• The S7-300 must not save unused data, but only requires the blocks necessary for the program sequence. All further blocks are saved on

Warranty, Liability and Support

S7 Block Management Services Entry-ID: 21495347

V1.0 27.04.05 2/54

Cop

yrig

ht ©

Sie

men

s A

G 2

005

All

right

s re

serv

ed

2149

5347

_OP

C_B

auD

i_D

OK

U_v

10_e

.doc

Warranty, Liability and Support

We accept no liability for 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© 2005 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:

mailto:[email protected]

Page 3: Application for Communication - Siemens...• The S7-300 must not save unused data, but only requires the blocks necessary for the program sequence. All further blocks are saved on

Foreword

S7 Block Management Services Entry-ID: 21495347

V1.0 27.04.05 3/54

Cop

yrig

ht ©

Sie

men

s A

G 2

005

All

right

s re

serv

ed

2149

5347

_OP

C_B

auD

i_D

OK

U_v

10_e

.doc

Foreword

Objectives of the application The following example is a simple illustration of how to use the S7 block management services from a Visual Basic .NET client program.

The S7 block management services are thereby controlled via the OPC DA interface of the SIMATIC NET OPC-server and transferred with an S7 connection.

Main contents of this application The following main points are discussed using the S7 block management services:

• Loading blocks from the S7 controller to the PG/PC device and storing as (.blk) files

• Loading blocks stored within files to the controller and integrating them in the program sequence.

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 e.g. literature, glossary etc.

Reference for Automation and Drives 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/de/21495347

Page 4: Application for Communication - Siemens...• The S7-300 must not save unused data, but only requires the blocks necessary for the program sequence. All further blocks are saved on

Foreword

S7 Block Management Services Entry-ID: 21495347

V1.0 27.04.05 4/54

Cop

yrig

ht ©

Sie

men

s A

G 2

005

All

right

s re

serv

ed

2149

5347

_OP

C_B

auD

i_D

OK

U_v

10_e

.doc

Table of Contents

Table of Contents ......................................................................................................... 4

Application Description ............................................................................................... 6

1 Automation Task............................................................................................. 6 1.1 Overview........................................................................................................... 6 1.2 Requirements ................................................................................................... 7

2 Automation Solution ...................................................................................... 8 2.1 Overview of the overall solution........................................................................ 8 2.2 Required hardware and software components ............................................... 10 2.3 Basic Performance Data................................................................................. 12 2.4 Alternative solutions........................................................................................ 13

Function Principles and Program Structures .......................................................... 14

3 Function Mechanisms .................................................................................. 14 3.1 Basics of S7 block management services ...................................................... 14 3.1.1 General information ........................................................................................ 14 3.1.2 Block management service “&blockread()“ ..................................................... 17 3.1.3 Block management service “&blockread()“ ..................................................... 18 3.1.4 Block management service “&blockread()“ ..................................................... 20 3.2 OPC DA interface ........................................................................................... 21 3.3 Using OPC DA in .NET................................................................................... 22

4 Explanations on the Example Program ...................................................... 24 4.1 General program structure.............................................................................. 24 4.2 Code structure model ..................................................................................... 25 4.3 Status diagram................................................................................................ 26 4.4 Call structure of the example program............................................................ 27 4.5 Connection to the OPC.SimaticNET server.................................................... 29 4.6 Creating a group and polling the IOPCItemMgt interface ............................... 30 4.7 Creating items that control the OPC block management service ................... 31 4.8 Addint items at the OPC server ...................................................................... 32 4.9 Getting the interface for synchronous writing of values .................................. 33 4.10 Controlling the services .................................................................................. 34 4.11 Writing values to the OPC server ................................................................... 35

5 Program Description of the PLC Program (STL) ....................................... 36 5.1 Description of the example program............................................................... 36 5.2 Possible sources of errors .............................................................................. 38

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

Page 5: Application for Communication - Siemens...• The S7-300 must not save unused data, but only requires the blocks necessary for the program sequence. All further blocks are saved on

Foreword

S7 Block Management Services Entry-ID: 21495347

V1.0 27.04.05 5/54

Cop

yrig

ht ©

Sie

men

s A

G 2

005

All

right

s re

serv

ed

2149

5347

_OP

C_B

auD

i_D

OK

U_v

10_e

.doc

6 Installation and Commissioning ................................................................. 40 6.1 Installation of Hardware and Software............................................................ 40 6.2 Installation of the application software............................................................ 41

7 Configuration Process ................................................................................. 42 7.1 Configuration of the PG/PC interface ............................................................. 42 7.2 STEP 7-side configuration .............................................................................. 44

8 Operating the Application............................................................................ 48

Appendix and List of Further Literature ................................................................... 52

9 Literature ....................................................................................................... 52 9.1 Bibliographic References................................................................................ 52 9.2 Internet links ................................................................................................... 54

Page 6: Application for Communication - Siemens...• The S7-300 must not save unused data, but only requires the blocks necessary for the program sequence. All further blocks are saved on

Application Description

Automation Task

S7 Block Management Services Entry-ID: 21495347

V1.0 27.04.05 6/54

Cop

yrig

ht ©

Sie

men

s A

G 2

005

All

right

s re

serv

ed

2149

5347

_OP

C_B

auD

i_D

OK

U_v

10_e

.doc

Application Description

Content An overview of the introduced application is provided here. 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 following example is a simple illustration of how to use the S7 block management services from a Visual Basic .NET client program.

Overview of the automation task The following figure gives an overview of the automation task. Figure 1-1

Page 7: Application for Communication - Siemens...• The S7-300 must not save unused data, but only requires the blocks necessary for the program sequence. All further blocks are saved on

Application Description

Automation Task

S7 Block Management Services Entry-ID: 21495347

V1.0 27.04.05 7/54

Cop

yrig

ht ©

Sie

men

s A

G 2

005

All

right

s re

serv

ed

2149

5347

_OP

C_B

auD

i_D

OK

U_v

10_e

.doc

1.2 Requirements

Requirements for the automation task The solution on hand focuses on the functionality of the S7 block management service. The techniques used on PC and on the PLC/S7 side are explained here.

The solution is to show, how

• a PC-station is configured with the “Advanced PC Configuration”.

• the S7 block management services are used,

• a simple OPC Client, required for the S7 block management services, needs to be implemented using Visual Basic .NET.

It is also meant to provide a basis for simple expansion and flexible adaptation to your requirements.

Requirements for the controller Extensive input screens are not required. The data is stored consistently in a block.

Communication requirements This solution uses the S7 protocol tailored to SIMATIC. The protocol is quite fast compared with other automation protocols for data communication.

Quantity framework of the sample application: Different size blocks of various types (OB, FB, FC, DB) and different interfaces are transmitted.

For a clearer overview and better understanding, the quantity framework for this application was established very low. However, the example described here can also be applied for larger quantities.

Page 8: Application for Communication - Siemens...• The S7-300 must not save unused data, but only requires the blocks necessary for the program sequence. All further blocks are saved on

Application Description

Automation Solution

S7 Block Management Services Entry-ID: 21495347

V1.0 27.04.05 8/54

Cop

yrig

ht ©

Sie

men

s A

G 2

005

All

right

s re

serv

ed

2149

5347

_OP

C_B

auD

i_D

OK

U_v

10_e

.doc

2 Automation Solution

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

2.1 Overview of the overall solution

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

Note The correct interfaces must be used in order to provide a smooth operation.

Page 9: Application for Communication - Siemens...• The S7-300 must not save unused data, but only requires the blocks necessary for the program sequence. All further blocks are saved on

Application Description

Automation Solution

S7 Block Management Services Entry-ID: 21495347

V1.0 27.04.05 9/54

Cop

yrig

ht ©

Sie

men

s A

G 2

005

All

right

s re

serv

ed

2149

5347

_OP

C_B

auD

i_D

OK

U_v

10_e

.doc

Advantages of the solution Due to the fact that the described functionality can be easily transferred, this application enables you to apply the following points to a customer-specific solution:

• Creating any number of recipes in form of data blocks (DB) or recipe procedures in form of STEP7 blocks (OB, FB, FC) with identical interface, in order to facilitate exchangeability.

• Load reduction of the S7 memory by directed loading of procedures and data to the controller. This prevents rarely used data being stored in the controller.

• Provision of many, completely programmed S7 blocks on the PC. Damit kann durch Nutzung der OPC DA Schnittstelle und des SIMATIC NET OPC-Servers in den Ablauf der Automatisierung eingegriffen werden.

• Simple storing of recipe data without implementing a database connection.

• Quick and simple changing of the program sequence taking into account the function / block interfaces.

• The S7-300 must not save unused data, but only requires the blocks necessary for the program sequence. All further blocks are saved on the PG/PC and loaded on demand.

• The solution on hand transfers all data within the block and then links them into the S7 program sequence. As a result, the new data are available without interruption from one cycle to the next. (Block changes are processed in the S7 controller at the beginning of cycle)

Page 10: Application for Communication - Siemens...• The S7-300 must not save unused data, but only requires the blocks necessary for the program sequence. All further blocks are saved on

Application Description

Automation Solution

S7 Block Management Services Entry-ID: 21495347

V1.0 27.04.05 10/54

Cop

yrig

ht ©

Sie

men

s A

G 2

005

All

right

s re

serv

ed

2149

5347

_OP

C_B

auD

i_D

OK

U_v

10_e

.doc

2.2 Required hardware and software components

Hardware components Table 2-1

Component No. MLFB / Order number Note Mounting rail L=480mm

1 6ES7 390-1AE80-0AA0

Load current supply PS307 5A

1 6ES7 307-1EA00-0AA0

Central processing unitCPU 315-2 DP

1 6ES7 315-2AG10-0AB0 MMC card required

Communications processor CP 343-1

1 6GK7 343-1EX20-0XE0

• Standard hub with twisted pair cable

• or 1 CrossOver cable

1 Depending on product

Power PG / PC 1 6ES7 751-0BA21-0LB3 Configurator: see FAQ ID 17128155; integrated Ethernet card

Standard software components Table 2-2

Component No. MLFB / Order number Note STEP 7 V 5.3 1 6ES7 810-4CC07-0YA5 Incl. SP1 SIMATIC NET IE SOFTNET-S7 V6.2

1 6GK1 704-1CW62-3AA0 Incl. SP1 and Microsoft .NET Framework V1.1

Microsoft Visual Studio .NET 2003 Professional

1 Optional, order via your administrator or via www.microsoft.com

Page 11: Application for Communication - Siemens...• The S7-300 must not save unused data, but only requires the blocks necessary for the program sequence. All further blocks are saved on

Application Description

Automation Solution

S7 Block Management Services Entry-ID: 21495347

V1.0 27.04.05 11/54

Cop

yrig

ht ©

Sie

men

s A

G 2

005

All

right

s re

serv

ed

2149

5347

_OP

C_B

auD

i_D

OK

U_v

10_e

.doc

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

Component Note 21495347_OPC_BauDi_CODE_v10.zip This .zip-file contains the STEP7

project as well as the executable files for the project and the Visual Basic .NET project.

21495347_OPC_BauDi_DOKU_v10_d.pdf This document

Page 12: Application for Communication - Siemens...• The S7-300 must not save unused data, but only requires the blocks necessary for the program sequence. All further blocks are saved on

Application Description

Automation Solution

S7 Block Management Services Entry-ID: 21495347

V1.0 27.04.05 12/54

Cop

yrig

ht ©

Sie

men

s A

G 2

005

All

right

s re

serv

ed

2149

5347

_OP

C_B

auD

i_D

OK

U_v

10_e

.doc

2.3 Basic Performance Data

Basic Performance Data For such a large number of components it is difficult to obtain the basic performance data and will also vary from case to case. Only some basics about the individual components are mentioned; the data of the overall system, hence this application, are not contained.

• The data access interface (based on COM and without the .NET Wrapper) strongly depends on the S7 communication between OPC server and S7 station.

• Using the .NET Framework and the Intermediate Language (IL) causes the program to slow down compared with programs compiled in native language (machine code).

Supported blocks The following table lists the blocks supported for this Getting Started document. Table 2-4

Blocks Supported Operation block OB + Function FC + Function block FB + Data block DB +

Page 13: Application for Communication - Siemens...• The S7-300 must not save unused data, but only requires the blocks necessary for the program sequence. All further blocks are saved on

Application Description

Automation Solution

S7 Block Management Services Entry-ID: 21495347

V1.0 27.04.05 13/54

Cop

yrig

ht ©

Sie

men

s A

G 2

005

All

right

s re

serv

ed

2149

5347

_OP

C_B

auD

i_D

OK

U_v

10_e

.doc

2.4 Alternative solutions

This solution differs from other solutions with the same result in the following points:

• Other solutions with input masks may transmit the data very slow and serial. The configuration effort for the operator is higher.

• Other solutions, based for example on the OPC variable or block management services, are less dependent of block interfaces. However, such a solution does not necessarily enable exchanging code blocks (FBs, FCs, OBs) during runtime in order to change the processing of programs.

• A solution with the STEP7 command interface requires installation of STEP7 on the respective PC.

• Other solutions may not depend on the SIMATIC-specific S7 protocol.

Page 14: Application for Communication - Siemens...• The S7-300 must not save unused data, but only requires the blocks necessary for the program sequence. All further blocks are saved on

Function Principles and Program Structures

Function Mechanisms

S7 Block Management Services Entry-ID: 21495347

V1.0 27.04.05 14/54

Cop

yrig

ht ©

Sie

men

s A

G 2

005

All

right

s re

serv

ed

2149

5347

_OP

C_B

auD

i_D

OK

U_v

10_e

.doc

Function Principles and Program Structures

Content Discusses the detailed function processes of the involved hardware and software components, the solution structures, and where sensible the concrete implementation of this application.

Read this part if you want to know how the individual solution components interact.

3 Function Mechanisms

Here you will find information on … basics on S7 block management services on S7 block management services. The terms OPC DA, Wrapper, S7 protocol and Industrial Ethernet are explained below.

3.1 Basics of S7 block management services

3.1.1 General information

S7 block services control monitoring and feedback of data and program blocks between PC and automation device. Data and program blocks are saved to files (.blk) on the PC.

For providing this function, the OPC server provides on respective OPC item (block read, block write, etc.) They are described with a configuration string which defines the desired function (blockread, blockwrite, blocklinkin).

The actual communication occurs via Industrial Ethernet using an S7 protocol.

If the affected blocks are password protected, the protection can be cancelled with the password service.

Note Further explanation on password service is available in Help or in the Introduction to SIMATIC NET.

Page 15: Application for Communication - Siemens...• The S7-300 must not save unused data, but only requires the blocks necessary for the program sequence. All further blocks are saved on

Function Principles and Program Structures

Function Mechanisms

S7 Block Management Services Entry-ID: 21495347

V1.0 27.04.05 15/54

Cop

yrig

ht ©

Sie

men

s A

G 2

005

All

right

s re

serv

ed

2149

5347

_OP

C_B

auD

i_D

OK

U_v

10_e

.doc

Linked and unlinked blocks The following figure illustrates the division of linked and unlinked blocks in the memory of the S7 controller. Figure 3-1

Explaining “linked” and “unlinked” The table below provides an explanation of the above figure. Table 3-1

Block status Explanation Unlinked A block transferred to an S7 controller via the S7 block

management services is stored in the load memory. This means the block is not yet available for an S7 program. The list of data blocks, which can be viewed via the online function of STEP 7, displays the block, but it cannot be opened. This process can be compared with loading blocks from the SIMATIC Manager to the S7 controller. The blocks are initially stored in the load memory.

Linked The S7 program of a controller is processed in the main memory. However, the embedded blocks are contained in the main memory of the S7 controller and are hence processed by the S7 program. Transferring (unlinked) blocks from the load memory to the main memory of the S7 controller is referred to as “linking”. This process corresponds to transferring the S7 program from the load memory to the main memory of a controller during startup (operating status from STOP to RUN mode).

Page 16: Application for Communication - Siemens...• The S7-300 must not save unused data, but only requires the blocks necessary for the program sequence. All further blocks are saved on

Function Principles and Program Structures

Function Mechanisms

S7 Block Management Services Entry-ID: 21495347

V1.0 27.04.05 16/54

Cop

yrig

ht ©

Sie

men

s A

G 2

005

All

right

s re

serv

ed

2149

5347

_OP

C_B

auD

i_D

OK

U_v

10_e

.doc

Syntax of OPC items The OPC items required for the services are described by the following syntax:

<Protocol-ID>:[<Connection name>]<Service parameter>

Explanation of the syntax Table 3-2

Parameter Description <Protocol-ID> Always ”S7“ (S7 protocol) <Connection name> Name of the S7-connection from OPC server to

controller configured in NetPro (”GS_Con“ in this Getting Started document)

<Service parameter> Name of the service to be called. The service parameters used in this Getting Started document are: &blockread(), &blockwrite() und &blocklinkin()

Example for an OPC item S7:[GS_Con]&blockread()

Calling the S7 block management services An S7 block management service is called by writing a value for the respective OPC item. The value to be written (=parameter string) contains the configuration of the S7 block management service.

Note Please note, that the block management service items are only written. (The OPC server -Server administrates the items as Write Only.) This is also the case for the &blockread() item!

Please do not be irritated by the term “read“. “Read“ refers to an S7 block, not to the OPC item!

The S7 block management services used in this Getting Started document and their parameters are described below.

Page 17: Application for Communication - Siemens...• The S7-300 must not save unused data, but only requires the blocks necessary for the program sequence. All further blocks are saved on

Function Principles and Program Structures

Function Mechanisms

S7 Block Management Services Entry-ID: 21495347

V1.0 27.04.05 17/54

Cop

yrig

ht ©

Sie

men

s A

G 2

005

All

right

s re

serv

ed

2149

5347

_OP

C_B

auD

i_D

OK

U_v

10_e

.doc

3.1.2 Block management service “&blockread()“

Function A block is transferred from an automation device to the PC where it is filed.

Overview The figure below shows the sequence of a blockread call. Figure 3-2

Explanation Table 3-3

No.

Function

1 A blockread call is started from the OPC client by writing a value into the OPC item with the “&blockread()“ service parameter. The value to be written contains the configuration of the blockread call (see ”Syntax of the parameter string“)

2 The OPC server addresses the block of the OPC item on the automation device.

3 The service enables reading blocks linked or not linked into the program sequence.

4 These linked or unlinked blocks are saved on the PG/PC into a blk-file.

Syntax of parameter strings The parameter string has a given syntax which is necessary for correct execution of the service. It is composed as follows:

{<Flag>|<Block identification>|<Path of target file>}

Page 18: Application for Communication - Siemens...• The S7-300 must not save unused data, but only requires the blocks necessary for the program sequence. All further blocks are saved on

Function Principles and Program Structures

Function Mechanisms

S7 Block Management Services Entry-ID: 21495347

V1.0 27.04.05 18/54

Cop

yrig

ht ©

Sie

men

s A

G 2

005

All

right

s re

serv

ed

2149

5347

_OP

C_B

auD

i_D

OK

U_v

10_e

.doc

Explanation of flags The required flags and their significance are explained below: Table 3-4

Flag Description 0x0001 An unchained block is read. If there is a target file, it is not overwritten,

an error message is output. 0x0040 An unchained block is read. If there is a target file, it is not overwritten,

an error message is output. 0x1001 An unchained block is read. An already existing target file is

overwritten. 0x1040 An unchained block is read. An already existing target file is

overwritten.

Example {0x0040|DB1|c:\db1_store.blk}

transmits a linked DB1. If the file “c:\db1_store.blk“ already exists it is not overwritten. An error message is output.

3.1.3 Block management service “&blockread()“

Function Transferring a block from a PC to an automation device.

Overview The figure below shows the sequence of a blockwrite call. Figure 3-3

Page 19: Application for Communication - Siemens...• The S7-300 must not save unused data, but only requires the blocks necessary for the program sequence. All further blocks are saved on

Function Principles and Program Structures

Function Mechanisms

S7 Block Management Services Entry-ID: 21495347

V1.0 27.04.05 19/54

Cop

yrig

ht ©

Sie

men

s A

G 2

005

All

right

s re

serv

ed

2149

5347

_OP

C_B

auD

i_D

OK

U_v

10_e

.doc

Explanation Table 3-5

No.

Function

1 A blockwrite call is started from the OPC client by writing a value into the OPC item with the “&blockwrite()“ service parameter. The value to be written contains the configuration of the blockwrite call (see ”Syntax of the parameter string“)

2 The service enables loading a block stored in a blk-file to the load memory of the controller.

3 After being loaded, the block is located in the load memory of the controller and cannot be linked with the S7 program. This means that with “Blockwrite“ blocks are written to the controller but they are not linked.

Note If a block with the same name has already been linked in the program sequence, it is not affected.

Syntax of parameter string The parameter string has a given syntax which is necessary for correct execution of the service. It is composed as follows:

{<Flag>|<Path to source file>}

Explanation of flags The required flags and their significance are explained below Table 3-6

Flag Meaning 0x1000 An unlinked block of the same name existing in the automation system

is to be overwritten. 0x0000 An unlinked block of the same name existing in the automation system

is not to be overwritten.

Example {0x0000|c:\db1_store.blk}

transmits the block saved in the db1_store.blk file to the controller, however, only if no block of the same name exists in the unlinked area.

Page 20: Application for Communication - Siemens...• The S7-300 must not save unused data, but only requires the blocks necessary for the program sequence. All further blocks are saved on

Function Principles and Program Structures

Function Mechanisms

S7 Block Management Services Entry-ID: 21495347

V1.0 27.04.05 20/54

Cop

yrig

ht ©

Sie

men

s A

G 2

005

All

right

s re

serv

ed

2149

5347

_OP

C_B

auD

i_D

OK

U_v

10_e

.doc

3.1.4 Block management service “&blockread()“

Function Linking a block of the passive status into the program sequence of the automation system. Thereby the part of the block relevant for program run is copied into the main memory of the automation system.

The block is then accessible for the S7 program. Linking a block overwrites an existing, active block without error message.

Overview The figure below shows the sequence of a blocklinkin call. Figure 3-4

Explanation Table 3-7

No.

Function

1 A blocklinkin call is started from the OPC client by writing a value into the OPC item with the “&blocklinkin()“ service parameter. The value to be written contains the configuration of the blocklinkin call (see ”Syntax of the parameter string“)

2 The service enables linking unlinked blocks existing on the S7 controller into the program sequence.

3 An already linked block is overwritten. The new block gets the status linked. If the given block does not exist in the load memory, an error is output.

Syntax of parameter string The parameter string has a given syntax which is necessary for correct execution of the service. It is composed as follows:

<Block Identification>

Example DB1

Page 21: Application for Communication - Siemens...• The S7-300 must not save unused data, but only requires the blocks necessary for the program sequence. All further blocks are saved on

Function Principles and Program Structures

Function Mechanisms

S7 Block Management Services Entry-ID: 21495347

V1.0 27.04.05 21/54

Cop

yrig

ht ©

Sie

men

s A

G 2

005

All

right

s re

serv

ed

2149

5347

_OP

C_B

auD

i_D

OK

U_v

10_e

.doc

3.2 OPC DA interface

What is OPC DA? OPC producer independent software interface which enables data exchange between hardware and software from different producers.

The OPC DA (OLE for Process Control Data Access) interface is a COM-based, worldwide and producer-independent standard for reading, writing and monitoring o process data.

Options for accessing variables An OPC server for data access manages the process variables and the different accessing options to these variables. This enables:

• reading the value of one or several process variables

• changing the value of one or several process variables, by writing a new value

• monitoring the value of one or several process variables

Used interfaces of OPC DA. The following interfaces are provided by OPC DA:

Table 3-8

OPC – DA objects with your interfaces

Interfaces used in the example Only the following interfaces are used in this example:

• IOPCServer (controls the OPCServer by itself)

• IOPCGroupStateMgt (manages the created group)

• IOPCItemMgt (manages the items)

• IOPCSyncIO (interface for synchronous reading and writing)

Page 22: Application for Communication - Siemens...• The S7-300 must not save unused data, but only requires the blocks necessary for the program sequence. All further blocks are saved on

Function Principles and Program Structures

Function Mechanisms

S7 Block Management Services Entry-ID: 21495347

V1.0 27.04.05 22/54

Cop

yrig

ht ©

Sie

men

s A

G 2

005

All

right

s re

serv

ed

2149

5347

_OP

C_B

auD

i_D

OK

U_v

10_e

.doc

3.3 Using OPC DA in .NET

Overview The following figure shows, how the OPC DA interface is made available in .NET. .NET Framework divides the software on the computer into two areas which need to be described: Figure 3-5

.NET Managed Code The Managed Code is only that area which is runnable within .NET Framework. The reasons for this are firstly the file format. It is also distinguished which one was previously valid for Windows (so far PE; Portable Executable was used for Windows). Secondly the code is not available in machine code directly. It exists in Intermediate Language (IL) and cannot be executed by the computer without the help of .NET Framework.

Unmanaged Code The unmanaged code on the other hand can be directly executed by the computer (it is available in machine code), and is filed in PE (Portable Executable) format with can be executed by Windows. COM (Component Object Model) is a service in this field and which provides the option of controlling programs from a different program via interfaces. Its definition for controlling interfaces differs from those used in .NET Framework.

Both standards are connected by a Runtime Callable Wrapper which is described below.

Page 23: Application for Communication - Siemens...• The S7-300 must not save unused data, but only requires the blocks necessary for the program sequence. All further blocks are saved on

Function Principles and Program Structures

Function Mechanisms

S7 Block Management Services Entry-ID: 21495347

V1.0 27.04.05 23/54

Cop

yrig

ht ©

Sie

men

s A

G 2

005

All

right

s re

serv

ed

2149

5347

_OP

C_B

auD

i_D

OK

U_v

10_e

.doc

RCW (Runtime Callable Wrapper) A wrapper connects an already existing, however not technology-compatible, interface to the required technology.

.NET Framework does have mechanisms for automatically “wrapping“ components which implement the “Automation Interface“ (a user programmed “Wrapper“-file is not necessary), and making them available in Visual Basic .NET. However, this option is not available for custom interfaces of the likes of OPC DA interfaces.

When using the wrapper, it must be noted, that all operations based on memory space allocation in COM must also be managed by the user himself in the normally managed code.

“Garbage Collection“ (GC) technology is not applied to the memory areas created by COM objects, as COM objects are unmanaged code.

Note The required wrapper has been included in this example and consists of the files OpcRcw.Da.dll and OpcRcw.Comn.dll.

Page 24: Application for Communication - Siemens...• The S7-300 must not save unused data, but only requires the blocks necessary for the program sequence. All further blocks are saved on

Function Principles and Program Structures

Explanations on the Example Program

S7 Block Management Services Entry-ID: 21495347

V1.0 27.04.05 24/54

Cop

yrig

ht ©

Sie

men

s A

G 2

005

All

right

s re

serv

ed

2149

5347

_OP

C_B

auD

i_D

OK

U_v

10_e

.doc

4 Explanations on the Example Program

Here you will find information on … the structures and important code sections of this example.

4.1 General program structure

In this example, it is illustrated how the S7 block management services are accessed with a Visual Basic .NET program.

Overview The following figure shows how the different software and hardware layers which are used. Figure 4-1

Explanation The connection from the Visual Basic .NET program to the Custom Interface of the SIMATIC NET OPC server is made by the .NET RCW (Runtime Callable Wrapper).

The connection to the hardware layer is generated by the S7 protocol based on the Industrial Ethernet protocol.

Apart from the hardware layer, the S7 controller side also contains different block statuses which may occur during runtime. Depending on the call of the item, these are unlinked or linked (into the program sequence).

Page 25: Application for Communication - Siemens...• The S7-300 must not save unused data, but only requires the blocks necessary for the program sequence. All further blocks are saved on

Function Principles and Program Structures

Explanations on the Example Program

S7 Block Management Services Entry-ID: 21495347

V1.0 27.04.05 25/54

Cop

yrig

ht ©

Sie

men

s A

G 2

005

All

right

s re

serv

ed

2149

5347

_OP

C_B

auD

i_D

OK

U_v

10_e

.doc

4.2 Code structure model

The table below contains sequences which occur during program execution.

Table 4-1

Program structure Explanation Setting the options

General "Imports" which specify the library files to be used. These are .NET specific name spaces of the framework.

The OPC DA RCW name spaces necessary for using OPC. Class declaration with "regions" divided into: • Class variables • Windows generated code

(unchanged!) • Event handling such as clicking

etc. • Helper methods • Routines necessary for language

handling

Class with encapsulates OPC handling. It is divided into • Class variables and • Handling routines.

Page 26: Application for Communication - Siemens...• The S7-300 must not save unused data, but only requires the blocks necessary for the program sequence. All further blocks are saved on

Function Principles and Program Structures

Explanations on the Example Program

S7 Block Management Services Entry-ID: 21495347

V1.0 27.04.05 26/54

Cop

yrig

ht ©

Sie

men

s A

G 2

005

All

right

s re

serv

ed

2149

5347

_OP

C_B

auD

i_D

OK

U_v

10_e

.doc

4.3 Status diagram

General information on UML status diagram An UML status diagram starts with the full point and ends at the full point with circle. Each status pointing to a pointer can be reached, if the condition attached to the pointer becomes true. If there is no action, the program remains in the respective status (box).

UML status diagram for the Visual Basic .NET program The program can run through the following statuses. The possible transitions are labeled with the respective action and are available in code for detailed consideration.

Figure 4-2

Page 27: Application for Communication - Siemens...• The S7-300 must not save unused data, but only requires the blocks necessary for the program sequence. All further blocks are saved on

Function Principles and Program Structures

Explanations on the Example Program

S7 Block Management Services Entry-ID: 21495347

V1.0 27.04.05 27/54

Cop

yrig

ht ©

Sie

men

s A

G 2

005

All

right

s re

serv

ed

2149

5347

_OP

C_B

auD

i_D

OK

U_v

10_e

.doc

4.4 Call structure of the example program

User interface of the example program This is the user interface of the example program. The next section describes the behavior during operation. Figure 4-3

Page 28: Application for Communication - Siemens...• The S7-300 must not save unused data, but only requires the blocks necessary for the program sequence. All further blocks are saved on

Function Principles and Program Structures

Explanations on the Example Program

S7 Block Management Services Entry-ID: 21495347

V1.0 27.04.05 28/54

Cop

yrig

ht ©

Sie

men

s A

G 2

005

All

right

s re

serv

ed

2149

5347

_OP

C_B

auD

i_D

OK

U_v

10_e

.doc

Behavior of the example program Table 4-2

Program flow chart Explanation After program start, all required data are initialized. In the beginning, the user only has the option of connecting with the OPC.SimaticNET server. The respective steps are available in the m_OPC server object: • Detecting whether the server exists. • Creating and activating the server object.

If connecting to the OPC server was successful, the groups and items are added. To do this: • the group is created. • The items &blockread(), &blockwrite() and

&blocklinkin() from the (OPCItemMgt) list of variables of the OPC.SimaticNET server are added to the group.

• The IOPCSyncIO2 object necessary for processing the items is created.

If “Start transfer“ is clicked, the required data are searched and composed. • &blockread(): from the selected option,

the desired block and the selected path. If the block cannot be found, an error is output in Trace.

• &blockwrite(): from the selected option and the path to the file. &blocklinkin(): the desired block If the .blk-file cannot be found, an error is output in Trace.

Disconnect Server terminates the connection with the OPC server. • remove items • remove group • release interfaces

Page 29: Application for Communication - Siemens...• The S7-300 must not save unused data, but only requires the blocks necessary for the program sequence. All further blocks are saved on

Function Principles and Program Structures

Explanations on the Example Program

S7 Block Management Services Entry-ID: 21495347

V1.0 27.04.05 29/54

Cop

yrig

ht ©

Sie

men

s A

G 2

005

All

right

s re

serv

ed

2149

5347

_OP

C_B

auD

i_D

OK

U_v

10_e

.doc

4.5 Connection to the OPC.SimaticNET server

Code example Figure 4-4

Explanations on the code example Table 4-3

No. Description 1 Request at the system whether the OPC.SimaticNET type has been

registered as an object (OPC server). 2 Instancing and activating the OPC.SimaticNET server.

1

2

Page 30: Application for Communication - Siemens...• The S7-300 must not save unused data, but only requires the blocks necessary for the program sequence. All further blocks are saved on

Function Principles and Program Structures

Explanations on the Example Program

S7 Block Management Services Entry-ID: 21495347

V1.0 27.04.05 30/54

Cop

yrig

ht ©

Sie

men

s A

G 2

005

All

right

s re

serv

ed

2149

5347

_OP

C_B

auD

i_D

OK

U_v

10_e

.doc

4.6 Creating a group and polling the IOPCItemMgt interface

Code example Figure 4-5

Explanations on the code example Table 4-4

No. Description 1 AddGroup adds a group to the server. A reference to an

IOPCGroupStateMgt is returned. 2 Following the allocation, the group returns an interface to IOPCItemMgt.

1

2

Page 31: Application for Communication - Siemens...• The S7-300 must not save unused data, but only requires the blocks necessary for the program sequence. All further blocks are saved on

Function Principles and Program Structures

Explanations on the Example Program

S7 Block Management Services Entry-ID: 21495347

V1.0 27.04.05 31/54

Cop

yrig

ht ©

Sie

men

s A

G 2

005

All

right

s re

serv

ed

2149

5347

_OP

C_B

auD

i_D

OK

U_v

10_e

.doc

4.7 Creating items that control the OPC block management service

Code example “Create Items“ is a function which encapsulates the actual creation of OPC items in a manner suitable for this application. Figure 4-6

Explanations on the code example Table 4-5

No. Description 1 AddItem transfers an item to the group for it to be monitored. A

ServerHandle is returned. 2 If an error occurs, the status is reset to “Connected“. The group is

removed and an error message output.

1

2

Page 32: Application for Communication - Siemens...• The S7-300 must not save unused data, but only requires the blocks necessary for the program sequence. All further blocks are saved on

Function Principles and Program Structures

Explanations on the Example Program

S7 Block Management Services Entry-ID: 21495347

V1.0 27.04.05 32/54

Cop

yrig

ht ©

Sie

men

s A

G 2

005

All

right

s re

serv

ed

2149

5347

_OP

C_B

auD

i_D

OK

U_v

10_e

.doc

4.8 Addint items at the OPC server

Code example Figure 4-7

Explanations on the code example Table 4-6

No. Description 1 The structures necessary for creating items are created and values

assigned to them. 2 In this case, AddItems adds an item to the group. 3 If an error occurred during the generation process, then this will be

reported to the higher-level function with an exception handler. If no error has occurred, the Handle value assigned by the server (the ServerHandle) will be saved in the variable (ServerHandle) available for it.

1

2

3

Page 33: Application for Communication - Siemens...• The S7-300 must not save unused data, but only requires the blocks necessary for the program sequence. All further blocks are saved on

Function Principles and Program Structures

Explanations on the Example Program

S7 Block Management Services Entry-ID: 21495347

V1.0 27.04.05 33/54

Cop

yrig

ht ©

Sie

men

s A

G 2

005

All

right

s re

serv

ed

2149

5347

_OP

C_B

auD

i_D

OK

U_v

10_e

.doc

4.9 Getting the interface for synchronous writing of values

Code example Figure 4-8

Explanations on the code example Table 4-7

No. Description 1 The allocation process automatically assigns the interface IOPCSyncIO2

from the group of variables m_SyncIO2. 2 If the allocation should fail (if, for example, the interface at the group

object has not been implemented), then the error forwarded to the caller.

Note It is also possible to write several items simultaneously. However, for improved readability, only one item is written here.

Another reason is that Blockwrite must be executed prior to Blocklinkin. For simultaneous writing this is not guaranteed.

Note Please note, that block management service items must always be

written. See chapter 3.1

1

2

Page 34: Application for Communication - Siemens...• The S7-300 must not save unused data, but only requires the blocks necessary for the program sequence. All further blocks are saved on

Function Principles and Program Structures

Explanations on the Example Program

S7 Block Management Services Entry-ID: 21495347

V1.0 27.04.05 34/54

Cop

yrig

ht ©

Sie

men

s A

G 2

005

All

right

s re

serv

ed

2149

5347

_OP

C_B

auD

i_D

OK

U_v

10_e

.doc

4.10 Controlling the services

Code example Figure 4-9

Explanations on the code example Table 4-8

No. Description 1 Here the value for the respective variable is composed. In the original

OPC.SimaticNET server conception, an array of the Variant type is used. In Visual Basic .NET this is replaced with a string array. For transferring an array write: {<Element1>|<Element2>|...} The strings are composed and written according to the explanations in chapter 3.1.

2 The value is now written to the variable with the existing Serverhandle. 3 The value for Linkin consists only of the block ID and has no flags.

Note The program encapsulates the flags entirely in order to improve usability. They are stored in a System.Collections.Hashtable collection type, and are exchanged at the time of usage.

1

2

1

2

3

Page 35: Application for Communication - Siemens...• The S7-300 must not save unused data, but only requires the blocks necessary for the program sequence. All further blocks are saved on

Function Principles and Program Structures

Explanations on the Example Program

S7 Block Management Services Entry-ID: 21495347

V1.0 27.04.05 35/54

Cop

yrig

ht ©

Sie

men

s A

G 2

005

All

right

s re

serv

ed

2149

5347

_OP

C_B

auD

i_D

OK

U_v

10_e

.doc

4.11 Writing values to the OPC server

Code example Figure 4-10

Explanations on the code example Table 4-9

No. Description 1 First all necessary data structures are collected for writing. This includes

the Handle which belongs to the item as well as an array in which errors are reported from the server to our program.

2 Write is called at the synchronous interface. 3 If an error occurs, the GetErrorString gets the error message from the

server. A program internal error message is generated.

1

2

3

Page 36: Application for Communication - Siemens...• The S7-300 must not save unused data, but only requires the blocks necessary for the program sequence. All further blocks are saved on

Function Principles and Program Structures

Program Description of the PLC Program (STL)

S7 Block Management Services Entry-ID: 21495347

V1.0 27.04.05 36/54

Cop

yrig

ht ©

Sie

men

s A

G 2

005

All

right

s re

serv

ed

2149

5347

_OP

C_B

auD

i_D

OK

U_v

10_e

.doc

5 Program Description of the PLC Program (STL)

5.1 Description of the example program

The S7 program, coded in STL, has a simple program structure for illustrating the block exchange.

Functions of the relocated blocks For test purposes various blocks relocated to .blk-files are already available. They have the following integrated functions: Table 5-1

File name Functionality DB2_HighByte.blk A DB2, in which all bits of the DB2.DBB 22 have been set to

1 (0xFF). The front section contains a block identification with the title: ”GS_OPC-S7 HIGH Byte“

DB2_LowByte.blk A DB2, in which all bits of the DB2.DBB 21 have been set to 1 (0xFF). The front section contains a block identification with the title: ”GS_OPC-S7 LOW Byte“

FB1_Blink.blk Uses data from DB2.DBW 22 and writes them to the MW 1 alternatingly with the value 0x00 at a frequency of 5Hz.

FB1_Static.blk Uses data from DB2.DBW 22 and writes them to MW 1 in each cycle.

FC1_Fastblink.blk Uses data from DB2.DBW 22 and writes them to the MW 1 alternatingly with the value 0x00 at a frequency which is supplied by the its controlled OB1.

OB1_CallFB.blk OB, which calls FB1. OB1_CallFB.blk OB, which calls the FC1 and transfers the value M0.1. This

generates a blinking in FC1 with a frequency of 5Hz.

Page 37: Application for Communication - Siemens...• The S7-300 must not save unused data, but only requires the blocks necessary for the program sequence. All further blocks are saved on

Function Principles and Program Structures

Program Description of the PLC Program (STL)

S7 Block Management Services Entry-ID: 21495347

V1.0 27.04.05 37/54

Cop

yrig

ht ©

Sie

men

s A

G 2

005

All

right

s re

serv

ed

2149

5347

_OP

C_B

auD

i_D

OK

U_v

10_e

.doc

Exchangeability of blocks Possible operating sequences, i.e. excangeabilities, are illustrated in the following figure. Following this organization chart prevents errors in the controller: Figure 5-1

Possible errors when exchanging blocks An error may occur when transferring the OB1 which calls the FC to the controller, but FC1 does not exist on the controller, or has a different interface.

The exact error behavior is described in the following section.

Note The DB1 in this project is empty and only works as instance data block of FB1.

Page 38: Application for Communication - Siemens...• The S7-300 must not save unused data, but only requires the blocks necessary for the program sequence. All further blocks are saved on

Function Principles and Program Structures

Program Description of the PLC Program (STL)

S7 Block Management Services Entry-ID: 21495347

V1.0 27.04.05 38/54

Cop

yrig

ht ©

Sie

men

s A

G 2

005

All

right

s re

serv

ed

2149

5347

_OP

C_B

auD

i_D

OK

U_v

10_e

.doc

5.2 Possible sources of errors

Possible sources of errors in the PLC, when using the technology described in this document, can be basically reduced to two causes:

A required block does not exist on the PLC (in linked status) Table 5-2

Explanation Example action

A block is exchanged, because a different functionality is required, without considering that this requires (calls) other blocks which at this point in time do not exist in the S7 program of the controller.

Reaction of the S7 controller

Here the S7 controller generally goes to STOP mode and can only be restarted manually (by pressing the mode switch).

Solution First either: • all required blocks must be transferred and linked or • the previously used block must be transferred. This is generally only possible using the SIMATIC Manager, as it provides the option of describing the S7 controller in STOP mode.

A block is addressed with a false interface. Table 5-3

Explanation Example action

A block is exchanged, because a different functionality is required, without considering that it has a function interface different to that of the block previously linked in the S7 program.

Reaction of the S7 controller

An interface failure causes different behavior of the PLC which mainly changes to STOP mode. More detailed information is available in the table below.

Solution Adjust the interface correctly to the requirements, as otherwise the values will be false, or transfer the blocks with a suitable interface.

Page 39: Application for Communication - Siemens...• The S7-300 must not save unused data, but only requires the blocks necessary for the program sequence. All further blocks are saved on

Function Principles and Program Structures

Program Description of the PLC Program (STL)

S7 Block Management Services Entry-ID: 21495347

V1.0 27.04.05 39/54

Cop

yrig

ht ©

Sie

men

s A

G 2

005

All

right

s re

serv

ed

2149

5347

_OP

C_B

auD

i_D

OK

U_v

10_e

.doc

Error behavior of the CPU during block exchange Table 5-4

Initial situation in the S7 controller

replaced with by means of... with the result, that...

...only the DB is exchanged

...the CPU continues running, however, the interface is not called.

FB4 or. DB4 with a larger interface (more transferred values) ...only the FB is

exchanged …the action is rejected by the OPC server.

...only exchanging the DB

...the CPU goes to STOP mode.FB4 or. DB4 with a smaller interface(fewer transferred values)

...only exchanging the FB

...the CPU continues running, and the interface is called. (DANGER of false data!)

...only exchanging the DB

...CPU message Values false

...only exchanging the FB

...CPU message Values false

...only exchanging the FB

...CPU message Values false

FB4, DB4 (DB 4 as instance data block of the FB4)

FB4 or. DB4 with an entirely different interface

...first exchanging the FB then the DB

...CPU message Values false

Note The statements made above refer to blocks with the status “linkedin“!

Page 40: Application for Communication - Siemens...• The S7-300 must not save unused data, but only requires the blocks necessary for the program sequence. All further blocks are saved on

Structure, Configuration and Operation of the Application

Installation and Commissioning

S7 Block Management Services Entry-ID: 21495347

V1.0 27.04.05 40/54

Cop

yrig

ht ©

Sie

men

s A

G 2

005

All

right

s re

serv

ed

2149

5347

_OP

C_B

auD

i_D

OK

U_v

10_e

.doc

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.

6 Installation and Commissioning

Here you will find information on … the hardware and software to be installed, and the steps necessary for commissioning the example.

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

Installation of the hardware For details on the hardware components, please refer to chapter 2. For the hardware setup, proceed in accordance with the table below:

Table 6-1

No. Instructions Note 1. Install the station in compliance with the diagram

shown in chapter 2.1 / 2.2. Note It is recommended to delete the MMC card of the CPU 315-2 DP prior to usage with the SIMATIC Manager (Menu File S7-Memory Card Delete...).

2. Install the network card according to instruction (unless already integrated). Please observe the installation instruction enclosed in the respective product!

3. Connect the CP 343-1 with the PG/PC network card analog to the figure in chapter 2.1. Note Instead of a hub or switch, you can also use a CrossCable for a direct connection between PG/PC and S7 controller.

4. Switch on the power supply for S7-300 station and hub and start the PG/PC.

Page 41: Application for Communication - Siemens...• The S7-300 must not save unused data, but only requires the blocks necessary for the program sequence. All further blocks are saved on

Structure, Configuration and Operation of the Application

Installation and Commissioning

S7 Block Management Services Entry-ID: 21495347

V1.0 27.04.05 41/54

Cop

yrig

ht ©

Sie

men

s A

G 2

005

All

right

s re

serv

ed

2149

5347

_OP

C_B

auD

i_D

OK

U_v

10_e

.doc

Note Setup guidelines for S7-300 must generally be followed.

Installation of the standard software A description of the installation procedure for STEP 7 V5.3 and SIMATIC NET V6.2 (see installation instruction /4/) is not part of this documentation. The installation takes place in the familiar Windows environment and is self-explanatory.

With SIMATIC NET PC Software V6.2 + SP1 the Microsoft .NET Framework V1.1 is automatically installed. This is also used by the Visual Basic .NET program of this example.

Table 6-2

No. Instructions Note 1. Install STEP 7 V5.3 + SP1 (or higher) on the PG 2. Install SIMATIC NET PC Software V6.2 + SP1 (or

higher) on the PG

3. Optionally install Microsoft Visual Studio 2003 .NET on the PG.

Microsoft Visual Studio 2003 .NET is necessary for processing the enclosed project. The files themselves are also runnable without Visual Studio.

6.2 Installation of the application software

This chapter explains how the example software which is part of this documentation, is installed on your PG/PC. Follow the instructions of the table below.

Table 6-3

No. Instructions Note 1. Unzip the file 21495347_OPC_BauDi_CODE_v10.zip

into any directory. Unzipping creates the folders S7_CODE and VB_CODE.

2. The folder S7_CODE contains an exctracted STEP 7 project named GS_03_02.zip. Extract it into your project directory using the SIMATIC Manager.

Page 42: Application for Communication - Siemens...• The S7-300 must not save unused data, but only requires the blocks necessary for the program sequence. All further blocks are saved on

Structure, Configuration and Operation of the Application

Configuration Process

S7 Block Management Services Entry-ID: 21495347

V1.0 27.04.05 42/54

Cop

yrig

ht ©

Sie

men

s A

G 2

005

All

right

s re

serv

ed

2149

5347

_OP

C_B

auD

i_D

OK

U_v

10_e

.doc

7 Configuration Process

Here you will find information on … the main configuration steps necessary for this application to be commissioned.

7.1 Configuration of the PG/PC interface

Configuration of the PG/PC network card In order to commission the example, the network card in the PG/PC must be configured as follows:

Note For test purposes it is recommended to not install this example in an existing network, but to set up a separate test network.

Table 7-1

No. Instructions Note

1 Open the “Local Area Connection Properties” dialog box via Start Control Panel Network <Connection name of network connection> Properties.

2 From the list “This connection uses the following items“ you select the option Internet Protocol (TCP/IP) and click on Properties.

The dialog Internet Protocol(TCP/IP)Properties opens.

3 Change to Use the following IP address: and set the IP address (e.g. 140.180.0.1) as well as a subnet mask (e.g. 255.255.255.0). The field Default gateway can stay empty. Acknowledge this and the previous dialog with OK.

Page 43: Application for Communication - Siemens...• The S7-300 must not save unused data, but only requires the blocks necessary for the program sequence. All further blocks are saved on

Structure, Configuration and Operation of the Application

Configuration Process

S7 Block Management Services Entry-ID: 21495347

V1.0 27.04.05 43/54

Cop

yrig

ht ©

Sie

men

s A

G 2

005

All

right

s re

serv

ed

2149

5347

_OP

C_B

auD

i_D

OK

U_v

10_e

.doc

Configure the PG/PC interface In order to be able to load the S7 program and the configuration to the S7-300 station via Industrial Ethernet the PG/PC interface must be set accordingly. Follow the instructions listed in the table:

Table 7-2

No. Instructions Note

1 Start the SIMATIC manager. 2 Open the dialog “Set PG/PI Interface“ with

“OK“. Options Set PG/PC interface

3 From the list Interface Parameter Assignment Used: you select the entry TCP/IP -> <Name of network card>.

4 Close dialog box with "OK”.

Page 44: Application for Communication - Siemens...• The S7-300 must not save unused data, but only requires the blocks necessary for the program sequence. All further blocks are saved on

Structure, Configuration and Operation of the Application

Configuration Process

S7 Block Management Services Entry-ID: 21495347

V1.0 27.04.05 44/54

Cop

yrig

ht ©

Sie

men

s A

G 2

005

All

right

s re

serv

ed

2149

5347

_OP

C_B

auD

i_D

OK

U_v

10_e

.doc

7.2 STEP 7-side configuration

Assigning IP address for the CP 343-1 IT The S7-300 station can only be accessed with STEP 7 after an IP address has been assigned to the CP 343-1. Please follow the instructions listed in the table:

Table 7-3

No. Instructions Note

1 In the SIMATIC Manager you open the dialog Assign Ethernet Address via the menu: Target system Assign Ethernet Address...

2 Start the search for stations at the Ethernet network with the Browse... button.

The Browse Network dialog is displayed in which all accessible Ethernet stations are listed.

3 Select the S7-300 CP from the list and close the dialog with OK.

4 In the IP Address field you specify an IP address for the CP 343-1 (e.g. 140.180.0.2; see “Configuration of the PG/PC network card”). Note Please ensure, that the IP addresses of PG/PC and CP 343-1 correspond with each other. This is best achieved if the last digit of both IP addresses only differs by one.

5 Allocate the IP address set by you to the CP 343-1 by pressing Assign IP Configuration.

The S7 station can now be reached from the SIMATIC Manager via Ethernet.

6 Close dialog box with "OK”. 7 Switch the CP 343-1 to RUN mode by pressing

the mode switch.

Page 45: Application for Communication - Siemens...• The S7-300 must not save unused data, but only requires the blocks necessary for the program sequence. All further blocks are saved on

Structure, Configuration and Operation of the Application

Configuration Process

S7 Block Management Services Entry-ID: 21495347

V1.0 27.04.05 45/54

Cop

yrig

ht ©

Sie

men

s A

G 2

005

All

right

s re

serv

ed

2149

5347

_OP

C_B

auD

i_D

OK

U_v

10_e

.doc

Adjust the hardware configuration in the STEP 7 project If using a hardware configuration which differs from that in this example (see chapter 2.1 Overview of the overall solution), the example project on hand needs to be adjusted accordingly.

Adjusting the network configuration in the STEP 7 project In order to adjust the STEP 7 example project to your setup, perform the following steps.

Table 7-4

No. Instructions Note

1 Open the extracted STEP 7 project “GS_03_02” in the SIMATIC Manager.

2 Start the network configuration tool “NetPro” via

the button . The network configuration on the right will be displayed.

3 Adjust the IP address of the PG/PC ”GS_03_02“: • Double-click “IE General“ in the “GS_03_02“

station • Change the IP address and the subnet mask

to the values actually set on the PG/PC via the Properties button.

• Click OK to confirm the properties dialog..

Configuration of the PG/PC network card

4 Adjust the IP addresses of the S7-300 station: • Double-click “CP 343-1“ in the “SIMATIC 300“

station • Change the IP address and the subnet mask

to the desired values by pressing Properties in the General tab.

• Click OK to confirm the properties dialog..

Please ensure, that the same stations have been set in the both stations and that the IP addresses correspond. Assigning IP address for the CP 343-1 IT

5 Save and compile the configuration with the button.

6 Select the SIMATIC 300 station and load the

configuration data to the controller using the button.

7 Close NetPro.

Page 46: Application for Communication - Siemens...• The S7-300 must not save unused data, but only requires the blocks necessary for the program sequence. All further blocks are saved on

Structure, Configuration and Operation of the Application

Configuration Process

S7 Block Management Services Entry-ID: 21495347

V1.0 27.04.05 46/54

Cop

yrig

ht ©

Sie

men

s A

G 2

005

All

right

s re

serv

ed

2149

5347

_OP

C_B

auD

i_D

OK

U_v

10_e

.doc

Load blocks into the S7-300 station Next, the blocks of the S7 program must be loaded to the S7-300 station. Follow the instructions of the table below.

Table 7-5

No. Instructions Note

1 Select the block folder of the SIMATIC 300 station in the STEP 7 project “GS_03_02“.

2 Load the blocks to the controller via the button.

The system data needs not be loaded.

3 Switch the CPU 315-2 DP to RUN mode by pressing the mode switch.

Importing the PG/PC configuration In order to use the OPC server on the PG/PC the configuration must be loaded from the STEP 7 project to the component configurator of the PG/PC. Please follow the instructions below:

Table 7-6

No. Instructions Note

1 Open the component configuration on the PG/PC via: Start Station Configuration Editor

2 Open the Import XDB-file dialog with the Import station... button.

Confirm the message with Yes.

3 Select the XDB-file “pcst_1.xdb“ of the STEP 7 project ”GS_03_02“. It is located at: <LW>\<project directory>\GS_03_02\XDBs\

This XDB file contains the complete PG/PC configuration. Example for project directory: C:\Programme\Siemens\Step7\S7Proj\GS_03_02\XDBs

4 Open the Station Configuration Editor dialog with Open.

5 Start the import by pressing OK. After a successful import the component configurator should display the configuration on the right.

Even if a warning is displayed in the “Station Configuration Editor“ dialog ( ), the import can be performed.

Page 47: Application for Communication - Siemens...• The S7-300 must not save unused data, but only requires the blocks necessary for the program sequence. All further blocks are saved on

Structure, Configuration and Operation of the Application

Configuration Process

S7 Block Management Services Entry-ID: 21495347

V1.0 27.04.05 47/54

Cop

yrig

ht ©

Sie

men

s A

G 2

005

All

right

s re

serv

ed

2149

5347

_OP

C_B

auD

i_D

OK

U_v

10_e

.doc

No. Instructions Note

6 Adjust the station name of the PG/PC via Station name. The station name equals the name of the PC station in the STEP 7 project. In this example: “GS_03_02“.

The station name in the component configurator is different to the computer name of the PG/PC (see Control Panel System).

7 Close the “Station Configuration Editor” dialog box.

Page 48: Application for Communication - Siemens...• The S7-300 must not save unused data, but only requires the blocks necessary for the program sequence. All further blocks are saved on

Structure, Configuration and Operation of the Application

Operating the Application

S7 Block Management Services Entry-ID: 21495347

V1.0 27.04.05 48/54

Cop

yrig

ht ©

Sie

men

s A

G 2

005

All

right

s re

serv

ed

2149

5347

_OP

C_B

auD

i_D

OK

U_v

10_e

.doc

8 Operating the Application

Here you will find information on …

how to operated all function of this application.

Visual Basic .NET Programm on the PG/PC All operating steps of the Visual Basic .NET program are described below.

Table 8-1

No. Instructions Note 1 Start the example program via

..\VB_CODE\GS_03_02\bin\ GS_03_02.exe Filing location of example program see chapter 6.1 Installation of Hardware and Software

2 To select the language German or English, click the right mouse button and select the desired language from the context menu.

3 The connection with the

OPC.SimaticNET server can be established by clicking the Connect to OPC Server button The successful connection is displayed in the status field. Each further status message is added to the top of the list.

Successful connection is displayed in the status field.

Page 49: Application for Communication - Siemens...• The S7-300 must not save unused data, but only requires the blocks necessary for the program sequence. All further blocks are saved on

Structure, Configuration and Operation of the Application

Operating the Application

S7 Block Management Services Entry-ID: 21495347

V1.0 27.04.05 49/54

Cop

yrig

ht ©

Sie

men

s A

G 2

005

All

right

s re

serv

ed

2149

5347

_OP

C_B

auD

i_D

OK

U_v

10_e

.doc

No. Instructions Note 4 If an error occurs in one of the

points displayed here, this is indicated by the Trace field turning red/white. This color remains until the operation is performed without error. The changed language is accepted from the next trace point on.

Note System error messages are displayed in the language set for the operating system and cannot be changed!

5 Create the required OPC goup as well as the OPC items via Add Groups and Items.

6 In Settings you select the respective action.

• Blockread: Read block from the controller and store on the PC as .blk-file.

• Blockwrite & Linkin: Load block from a .blk-file on the PC to the controller and link to S7 program.

7 When selecting “Blockwrite & Linkin“ please ensure that “Block Identification“ you set must be the same as in the .blk-file. If yu do not, an error will occur

Warning If the block in the .blk-file (e.g. FB1) does not correspond with the specified block identification (here: OB1) the block FB1 is transferred to the load memory with &blockwrite(), however, &blocklinkin() then tries to link the non-existent block OB1 into the S7 program. This causes an error message.

8 Now specify the path to the block file which is to be read or written.

9 Now you enter the block type and its number.

Note The specified number must correspond to the original block name (saved in the .blk-file). The S7 controller verifies this during writing. Name changes are not possible here!

Page 50: Application for Communication - Siemens...• The S7-300 must not save unused data, but only requires the blocks necessary for the program sequence. All further blocks are saved on

Structure, Configuration and Operation of the Application

Operating the Application

S7 Block Management Services Entry-ID: 21495347

V1.0 27.04.05 50/54

Cop

yrig

ht ©

Sie

men

s A

G 2

005

All

right

s re

serv

ed

2149

5347

_OP

C_B

auD

i_D

OK

U_v

10_e

.doc

No. Instructions Note 10 Depending on whether you read

or write a block, you have different selection options determined by the behavior during writing or reading. Select the desired behavior.

Note In Blockread, the options refer to the block before the semicolon, and to the .blk-file after the semicolon. Please also refer to the description of Optionen/Flags in chapter 3.1.

11 The Start transfer button starts the actions set at Settings.

The effects of the transfer can be observed immediately in the variable table “VAT_1“ of the STEP 7 project.

12 The Disconnect from OPC Server button disconnects the OPC server. This can be done any time after the connection has been established.

Note The behavior of the program during an error is such, that the action which caused the error can be repeated, or the status prior to the performed action is restored.

A precise description of the errors is available in the SIMATIC NET traces, which can be set as follows.

Open the configuration console “Set PC Station“ with:

Start Simatic SIMATIC NET Set PC Station

In the configuration console you then select:

PC Station SIMATIC NET Configuration Applications OPC settings

Here you can trace the errors of the OPC server at OPC Trace, and the errors of the protocol at Protocol Trace.

Page 51: Application for Communication - Siemens...• The S7-300 must not save unused data, but only requires the blocks necessary for the program sequence. All further blocks are saved on

Structure, Configuration and Operation of the Application

Operating the Application

S7 Block Management Services Entry-ID: 21495347

V1.0 27.04.05 51/54

Cop

yrig

ht ©

Sie

men

s A

G 2

005

All

right

s re

serv

ed

2149

5347

_OP

C_B

auD

i_D

OK

U_v

10_e

.doc

Monitoring with variable tables The table below contains a description of how to apply the variable tables of the STEP 7 project.

Table 8-2

No. Instructions Note 1 The block folder of the SIMATIC

300 station contains the VAT named VAT_1. Open this block with a double-click.

2 VAT_1 contains all variables which

can be changed by exchanging blocks. The upper half displays the identification of the respective DB2. Below the individual bits of memory word 1 are displayed, which serves as output bit. Changes made by blockread and blockwrite can be viewed here.

3 Start monitoring the variables with

the button. Now execute the different functions with the Visual Basic .NET program and monitor the changes in the variable table.

Page 52: Application for Communication - Siemens...• The S7-300 must not save unused data, but only requires the blocks necessary for the program sequence. All further blocks are saved on

Appendix and List of Further Literature

Literature

S7 Block Management Services Entry-ID: 21495347

V1.0 27.04.05 52/54

Cop

yrig

ht ©

Sie

men

s A

G 2

005

All

right

s re

serv

ed

2149

5347

_OP

C_B

auD

i_D

OK

U_v

10_e

.doc

Appendix and List of Further Literature

9 Literature

9.1 Bibliographic References

This list is by no means exhaustive and only gives a selection of appropriate sources.

Table 9-1

Topic Title /1/ STEP 7 Automatisieren mit STEP7 in

AWL und SCL (Automating with STEP7 in STL and SCL) Hans Berger published by: Publicis MCD Verlag ISBN 3-89578-113-4

/2/ Manual for industrial communication on PG/PC with SIMATIC NET. Installed by SIMATIC NET, see: Start

SIMATIC Documentation [Language]

SIMATIC NET – Industrielle Kommunikation mit PG/PC (Industrial Communication with PG/PC) Band 1 Grundlagen (Basics) Band 2 Schnittstellen (Interfaces) In product support under the entry ID: 52044387

/3/ Description or information on: • General information on the PC

tools • Functions of NCM PC Installed by SIMATIC NET, see: Start

SIMATIC Documentation [Language]

SIMATIC NET PC-Stationen in Betrieb nehmen - Anleitung und Schnelleinstieg für SIMATIC NCM PC / STEP 7 ab Version V5.2 (Commissioning of SIMATIC NET PC stations – instruction and quick start for SIMATIC NCM PC / STEP 7 from version V5.2) In product support under the entry ID: 13542666

/4/ This document describes how the SIMATIC NET PC software products can be installed on your PG/PC.

SIMATIC NET PC-Software CD 11/2003 SP1 Installationsanleitung (Installation instruction). In product support under the entry ID: 19996981

/5/ Setting up S7-300 S7-300, CPU 31xC und CPU 31x: Aufbauen Betriebsanleitung

Page 53: Application for Communication - Siemens...• The S7-300 must not save unused data, but only requires the blocks necessary for the program sequence. All further blocks are saved on

Appendix and List of Further Literature

Literature

S7 Block Management Services Entry-ID: 21495347

V1.0 27.04.05 53/54

Cop

yrig

ht ©

Sie

men

s A

G 2

005

All

right

s re

serv

ed

2149

5347

_OP

C_B

auD

i_D

OK

U_v

10_e

.doc

Topic Title (Setup and operating instructions) In product support under the entry ID: 13008499

Page 54: Application for Communication - Siemens...• The S7-300 must not save unused data, but only requires the blocks necessary for the program sequence. All further blocks are saved on

Appendix and List of Further Literature

Literature

S7 Block Management Services Entry-ID: 21495347

V1.0 27.04.05 54/54

Cop

yrig

ht ©

Sie

men

s A

G 2

005

All

right

s re

serv

ed

2149

5347

_OP

C_B

auD

i_D

OK

U_v

10_e

.doc

9.2 Internet links

This list is by no means exhaustive and only gives a selection of appropriate sources.

Topic Title \1\ Reference to

the entry http://support.automation.siemens.com/WW/view/en/21402169

\2\ Siemens A&D Customer Support

http://support.automation.siemens.com


Recommended