You are on page 1of 46

Application for Process Automation

Export of WinCC / CAS Archive Data to Excel using the WinCC OLE DB Provider
Application Note

Warranty, liability and support

Export of WinCC / CAS Archive Data

35840700

Note

The Application Examples are not binding and do not claim to be complete regarding the circuits shown, equipping and any eventuality. The application examples do not represent customer-specific solutions. They are only intended to provide support for typical applications. You are responsible for ensuring that the described products are used correctly. These application examples do not relieve you of the responsibility to use sound practices in application, installation, operation and maintenance. When using these Application Examples, you recognize that Siemens cannot be made liable for any damage/claims beyond the liability clause described. We reserve the right to make changes to these application examples at any time without prior notice. If there are any deviations between the recommendations provided in these application examples and other Siemens publications e.g. Catalogs the contents of the other documents have priority.

Copyright Siemens AG 2009 All rights reserved

V1.0

08.10.2009

2/46

Warranty, liability and support

Export of WinCC / CAS Archive Data

35840700

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 Application Example 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 do not imply a change of the burden of proof to your detriment. Copyright 2009 Siemens I IA. Any form of duplication or distribution of these application examples or excerpts hereof is prohibited without the expressed consent of Siemens I IA.
Copyright Siemens AG 2009 All rights reserved

For questions about this document please use the following e-mail address: online-support.automation@siemens.com

V1.0

08.10.2009

3/46

Table of Contents

Export of WinCC / CAS Archive Data

35840700

Table of Contents
Warranty, liability and support ................................................................................... 3 Table of Contents......................................................................................................... 4 Preface .......................................................................................................................... 5 1 Introduction........................................................................................................ 7 1.1 1.2 1.3 1.4 2 Background .......................................................................................... 7 Structure of the documentation ............................................................ 7 Runtime environment ........................................................................... 8 Test results........................................................................................... 8

Structure, Function and Application ............................................................. 10 2.1 2.2 2.2.1 2.2.2 2.3 2.3.1 2.3.2 2.3.3 2.3.4 2.3.5 First call of the application.................................................................. 10 Setup of the application window......................................................... 11 Toolbar design.................................................................................... 14 Table view .......................................................................................... 14 Operation of the Application............................................................... 15 Application call ................................................................................... 15 Making the basic settings ................................................................... 16 Making the filter settings..................................................................... 17 Adapting the message structure ........................................................ 21 Reading the messages....................................................................... 23

Copyright Siemens AG 2009 All rights reserved

Background Information on the Principle of Operation .............................. 25 3.1 3.1.1 3.1.2 3.1.3 3.2 SQL statement ................................................................................... 25 Parts of the SQL statement................................................................ 25 Adding message languages............................................................... 27 Adding message types ....................................................................... 29 Expansion capability of the message structure.................................. 34

Appendix .......................................................................................................... 38 4.1 4.2 4.3 4.4 Enabling macros................................................................................. 38 Interpreting the wildcards for associated values ................................ 41 Creating wildcards for associated values........................................... 43 Creating a new user for the WinCC Runtime database ..................... 45

History............................................................................................................... 46

V1.0

08.10.2009

4/46

Introduction

Export of WinCC / CAS Archive Data

35840700

Preface
Objective of the application This application provides the user with a simple tool with which he/she can access the process values (tags) and message data archived by WinCC to export it to Excel. This data can thus be saved WinCC-externally and further evaluated. The application mainly focuses on the description of the procedure for accessing WinCC archive data, not on creating and describing a VBA application. Used technologies The application was written in the Visual Basic for Applications (VBA) programming language. Access to the data base takes place via OLE DB. The WinCC OLE DB Provider is used to establish the connection between the application and process value or the message archive.

Copyright Siemens AG 2009 All rights reserved

Note

Use the link below to obtain an overview of the different options for accessing WinCC archives: http://support.automation.siemens.com/WW/view/en/22578952

Functional scope Reading out the data from the WinCC Runtime database of an OS server or a CAS (Central Archive Server) Individual combination of the process value and message information Possibility of interpolation for missing values (process values) Adjustable time intervals (process values) Accessing the archives of different languages (messages) Using filters such as time interval and message type (messages) Interpreting the wildcards in the message texts (messages)

V1.0

08.10.2009

5/46

Introduction

Export of WinCC / CAS Archive Data Restriction

35840700

To limit the scope of this document, it does not include a complete description of programming language VBA Database language SQL Principle of operation of OLE DB WinCC Runtime database

Required knowledge No previous knowledge is required to understand the functional description in chapter 2. However, understanding chapter 3, which describes the structure and the expansion options of the application, requires basic knowledge of VBA and SQL. Reference to Automation and Drives Service & Support
Copyright Siemens AG 2009 All rights reserved

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/35840700

V1.0

08.10.2009

6/46

Introduction

Export of WinCC / CAS Archive Data

35840700

1
1.1

Introduction
Background
The WinCC Runtime database is segmented for WinCC V6.0 and higher. This means that the data is stored in several archive segments (several databases), partly in compressed, binary form. Both WinCC and the WinCC WinCC Connectivity Pack option provide the WinCC OLE DB Provider. It enables direct reading of the Tag Logging and Alarm Logging Runtime data. The WinCC OLE DB Provider provides the data from the respective archive segments in decompressed, decrypted form. Thus the user does not have to worry about the segmentation of the archives and their encryption when accessing the Tag Logging and Alarm Logging data. Based on this, this VB application was created in the form of an Excel macro. It conveniently provides the user with the corresponding functions and at the same time offers room for individual adaptations and expansions.
Figure 1-1: Representation of the data flow

Copyright Siemens AG 2009 All rights reserved

Figure 1-1 provides an overview of the data flow. The Excel client is the computer on which the application is run. Basically, this can be any computer that meets the conditions listed in 1.3. On the one hand, the OS server (in its function as a shortterm archive) and on the other hand, the CAS, Central Archive Server (the swapped out long-term archive), are possible as a data source.

1.2

Structure of the documentation


This document is divided into two main parts: Description of the structure, function and application Illustration of the main adjustment options and instructions on performing respective modifications

V1.0

08.10.2009

7/46

Introduction

Export of WinCC / CAS Archive Data

35840700

The second section imparts background knowledge and is not required for the mere use of the application.

1.3

Runtime environment
The application was tested on stations with the following configuration: MS Excel 2003 and WinCC V6.0 SP 3a to V7.0 SP1 the respectively associated WinCC Connectivity Pack

or/and

The application requires that WinCC Runtime be active on the computer from which the data is to be read. The application can be used on any computer that meets the above-listed requirements and that is connected to the OS server or the CAS via the network (provided that corresponding access rights exist).
Copyright Siemens AG 2009 All rights reserved

Using the application, it is also possible to access a local archive (e.g., OS single station). It is absolutely necessary to observe the following note:
ATTENTION

When executing the application the additional computing load must be taken into account, since it may affect the reaction time of WinCC Runtime. This applies to both the client and the data source!

For an exact list of tested systems, please refer to point 1.4.

1.4

Test results
On the one hand, the following tables show the configurations of the computers which form the test environment; on the other hand, they list some test results, achieved during the readout of messages. Since the test results for process values strongly depend on the made settings, they will not be presented.

Table 1-1: Computer configurations SIMATIC PC station OS-Server Name OS_SV1 OS_SV2 CAS CAS Operating system MS Win Server 2003 SP2 MS Win Server 2003 SP2 MS Win Server 2003 SP2 WinCC/ ConPack WinCC WinCC WinCC Version 6.0.3a 6.2.2 6.2.2 CPU [GHz] 3,4 2,8 3,4 RAM [MB] 2k 1k 2k

V1.0

08.10.2009

8/46

Introduction

Export of WinCC / CAS Archive Data


SIMATIC PC station OS Client OpenPCS 7 Station Connectivity Pack Client OS Single Station Name OS_CL1 OS_CL2 Open CP_CL SiSt Operating system Win XP 2002 SP3 Win XP 2002 SP3 Win XP 2002 SP2 Win XP 2002 SP2 Win XP 2002 SP3 WinCC/ ConPack WinCC WinCC WinCC ConPack WinCC Version 6.0.3a 7.0.1 6.2.2 6.2.2 7.0.1

35840700
CPU [GHz] 3,4 3,4 2,8 0,8 2,8 RAM [MB] 512 512 512 512 2k

Table 1-2: Test results Client name OS_CL1 OS_CL2


Copyright Siemens AG 2009 All rights reserved

Data source OS_SV1 OS_SV1 CAS OS_SV2 SiSt

No. of messages 21932 22943 7116 3102 22265

Total duration [min] 01:54 01:20 00:19 00:24 01:11

Messages / second 219 310 396 389 405

Open Open SiSt

Note

The messages per second only refer to the processing speed of the previously collected data. The duration of the actual data acquisition is thus not included in this value. The total duration begins with the start of the read command and ends with the final conditioning of the data. It is mainly composed of the execution time of the SCL command and the time required to accept all data into the worksheet. Selecting and formatting the data as well as replacing the dummies on the other hand takes comparatively little time.

V1.0

08.10.2009

9/46

Structure, Function and Application

Export of WinCC / CAS Archive Data

35840700

Structure, Function and Application


This chapter provides a detailed description of the applications functional scope.

2.1

First call of the application


The application does not have to be installed separately. Copy the OLE-DB Tag and Alarm Export.xls file directly to your desired location. The Excel file contains the entire source code in the form of macros that are run in the background.

Storage location

Application call Start the application by double-clicking on the Excel file. Depending on your Excel settings, the following warning may appear as soon as the application has opened:
Figure 2-1: Warning concerning disabled macros

Copyright Siemens AG 2009 All rights reserved

The reason for this warning is that your macro security level is set to High. To ensure the operating capability of the application for this case, proceed as described in the Appendix in 4.1.

V1.0

08.10.2009

10/46

Structure, Function and Application

Export of WinCC / CAS Archive Data

35840700

2.2
Overview

Setup of the application window


Figure 2-2 and Figure 2-3 show the application directly after its call. Which interface is displayed depends on which tab was active during the last storing process. The entries are also those available when it was last saved.

Figure 2-2: Start screen (Tags tab)

Copyright Siemens AG 2009 All rights reserved

Figure 2-3: Start screen (Alarms tab)

V1.0

08.10.2009

11/46

Structure, Function and Application

Export of WinCC / CAS Archive Data Note

35840700

The user interface is completely in English. The selection in the Alarm Language drop-down list of the Alarms tab refers to the language of the messages to be read out.

Switching between Tags and Alarms occurs via the selection of the respective tab at the bottom edge of the Excel window.
Figure 2-4: Tab change

Copyright Siemens AG 2009 All rights reserved

V1.0

08.10.2009

12/46

Structure, Function and Application

Export of WinCC / CAS Archive Data Workspace structure

35840700

Representing both tabs the structure of the workspace is illustrated here as the Alarms tab.
Figure 2-5: Structure of the workspace (Alarms tab)

Copyright Siemens AG 2009 All rights reserved

Each of the three selected sections performs its own function, which is described in the following Table 2-1.
Table 2-1: Subdivision of the workspace Range Toolbar Function All required settings are made using the toolbar. These settings include the selection of the data source and the definition of message filter or process filter. For a more detailed description of this section, please refer to 2.2.1. The column headers define the structure of the displayed messages. Note: You can adapt both the sequence and the structure as desired. The exact procedure is described in 2.3.4. This section contains the read out messages or process values with your selected structure.

Column Headers

Messages (Tags tab: process values)

ATTENTION

The boxes of the Toolbar and Column Headers sections are protected to avoid unintended changes. To ensure that the applications operating capability remains unaffected, we recommend that this protection be left unchanged.

V1.0

08.10.2009

13/46

Structure, Function and Application

Export of WinCC / CAS Archive Data

35840700

2.2.1

Toolbar design
In the toolbar, you make all settings that are necessary to display your desired data in a format of your choice. The design of the toolbar can be subdivided into three sections (illustrated in Figure 2-6 as an example for the Alarms tab): The basic settings which once they have been set remain unchanged for the entire session in most cases The filter which allows to describe the required archive data in greater detail and to thus improve the search result The action section from which the adaptation of the structure of the displayed messages (selection of the message blocks) or process values (selection of static values) and the actual read action can be started.

Each of these sections includes several control elements that are described in greater detail later in the instructions for operating the application in section 2.3.
Figure 2-6: Structure of the toolbar (Alarms tab)
Copyright Siemens AG 2009 All rights reserved

2.2.2

Table view
The representation of the received archive data varies and enables you to define a structure which is ideal for you. For process values different static functions can be executed for example, and their results be displayed. The table view for displaying the messages is based on the journal list of the WinCC alarm system. Similar to the original, the display of the different message blocks can be designed individually (see 2.3.4).

V1.0

08.10.2009

14/46

Structure, Function and Application

Export of WinCC / CAS Archive Data

35840700

2.3

Operation of the Application


This section describes how process values and messages can be read out from the archive. With the exception of the explanation of the filter, this is performed exemplary at the procedure for messages, since the treatment of process values differs very little.

2.3.1

Application call
Table 2-2: Calling the application Description 1. Start the application. Note: After starting the application, it is possible that it does not respond for a short period of time. This is due to the fact that the network is busy and that the listing of available computers progresses only slowly. If several subnets exist, only members of the own work group are determined. Nevertheless, you can also access computers which are not displayed, as long as there is a valid connection to them. You only need to enter the name of the target computer into the text field of the dropdown menu Host. 2. If required, enable macros. Control element

Copyright Siemens AG 2009 All rights reserved

V1.0

08.10.2009

15/46

Structure, Function and Application

Export of WinCC / CAS Archive Data

35840700

2.3.2

Making the basic settings


In the basic settings, you make settings that in most cases remain identical for the entire session. This includes defining the source computer and the message language.
Table 2-3: Making the basic settings Description 1. 2. Select the Alarms tab. In the Host drop-down list, select the computer that serves as a source of information. After starting the program, the name of the calling computer is entered. Note: It is required that WinCC Runtime be started on the computer specified here since the WinCC OLE DB Provider communicates with its services. In addition, it must be observed that only the data is read that is locally available on this computer. If you are using a CAS (Central Archive Server), you have to select between this server (long-term archive) and the OS server (short-term archive) to receive the messages of a specific time range. 3. In the drop-down list, select the language in which the messages to be exported were configured. The following languages are available: German English French Italian Spanish Note: The language selection is not available for process values. If one of these message languages is not configured separately, the messages of this language contain the standard texts. Control element

Copyright Siemens AG 2009 All rights reserved

V1.0

08.10.2009

16/46

Structure, Function and Application

Export of WinCC / CAS Archive Data

35840700

2.3.3

Making the filter settings


The filter settings enable you to reduce the returned archive data to the ones you are actually interested in with regard to tag, time range, time interval (process values) or time, type and origin (messages). Differences between the procedure for process values and messages are explained in parallel steps.
Table 2-4: Making the filter settings Description 1. In the two input boxes, define the time range in which the archive data you are searching for has occurred. Ensure that the start time is before the end time. By default, the current date from 0 - 24 h is set. Note: Time and date have to be entered in a specific form: YYYY-MM-DD hh:mm:ss In addition, it must be ensured that the input is intrinsically logical (e.g., no February 30, no 70 minutes or similar inputs). If the value is invalid when exiting the input field, a warning will appear and the previously entered value is restored. 2. Click on the Read Tags / Areas button for reading the archived process values (tags) or the configured (plant) areas. Note: To be able to perform reading, the relevant host must have previously been selected. Error handling: If the following message is displayed, communication with the database has failed: Area / Tag determination failed + error description. Possible causes are: Network problems (host not accessible) Missing rights (remedy see section 4.4) OS not in Runtime Once you have read out the information, the respective drop-down list provides them to you. 3. For the Tags tab: In the dropdown list Archive Tags you select the process value whose archived values you wish to read out. Control element

Copyright Siemens AG 2009 All rights reserved

V1.0

08.10.2009

17/46

Structure, Function and Application

Export of WinCC / CAS Archive Data


Description For the Alarms tab: If you wish to filter the messages according to a certain area, select this area in the Areas dropdown list. If you do not wish to filter by areas, select the blank line. Note: Some messages, for example system messages, cannot be assigned to an area. To still receive these messages, do not use this filter. While in WinCC the area filter is applied after reading the messages and replacing the dummies, in this application this occurs directly via the SQL command due to performance reasons. It is searched in those message blocks in which the Area occurs most frequently (Text2 and PText2). Should you be located at a different position, the area filter will not lead to the desired result. 4. For the Tags tab: Specify the desired time interval in seconds, via which the originally occurred values (native) shall be summarized. If no interval shall be used, (values remain native), then enter 0. Note: To provide an option of reducing the number of read out process values without any larger information loss, using the time interval is offered. The time interval enables to summarize all process values which have occurred in a certain time interval (e.g. all values in a minute or hour). For this amount of values evaluations can then be made (e.g. maximum value, minimum value, total). This principle is illustrated in Figure 2-7. For the Alarms tab: For filtering by different types (classes) of messages, a total of six option boxes are available to you that can be combined as desired. When nothing is selected, filtering by messages is disabled.

35840700
Control element

Copyright Siemens AG 2009 All rights reserved

V1.0

08.10.2009

18/46

Structure, Function and Application

Export of WinCC / CAS Archive Data


Description 5. For the Tags tab: Select whether an interpolation shall occur. Note: The interpolation requires a time interval unequal zero. Using the interpolation ensures that the time distance between two received values always remains the same. If no value has been archived for a point in time, a respective intermediate value is determined from the direct previously and the direct successively archived value. Interpolation only occurs between two respectively archived values within the time range. Interpolation does not occur between one value within and a value outside the time range.
Copyright Siemens AG 2009 All rights reserved

35840700
Control element

Note

You should use the filter options to limit the selection criteria to the largest extent possible. By doing so, you reduce the number of relevant archive data and thus the access time to the database and the subsequent processing time. Please also observe that Excel has only a limited number of rows. This limits the maximum number of data records that can be listed to 65526. If the query returns more data records, the first 65526 are processed and the remaining ones are rejected. For messages, the number of returned data records is additionally restricted to 65000 by the SQL. Where this value is determined is given in section 3.1.1.

V1.0

08.10.2009

19/46

Structure, Function and Application

Export of WinCC / CAS Archive Data Explanation of the time interval

35840700

The subsequent figure represents the course of a process value over several hours. Using the vertical, dotted line, the curve is divided into the individual hours.
Figure 2-7: Representation of the time interval

Copyright Siemens AG 2009 All rights reserved

Assuming the archiving of the process values occurs every second, then the list of up to 18000 values (for 5 hours) is fairly unclear. However, if specifying a time interval of one hour, a total of maximal five values per column are given. To still get a fair idea of the actual course of the curve it is possible to have different information determined via the numbers of affected values. This is illustrated in the Details view of the figure. It is possible to determine the extreme values of the curve, the first and last value, the average and (not represented) the total of all values which occurred in this interval and their number. If an interval shows particularly noticeable behavior, it is possible to later on restrict the time range accordingly, and reduce the time interval so that all information are available to search for the cause in greater detail.

V1.0

08.10.2009

20/46

Structure, Function and Application

Export of WinCC / CAS Archive Data

35840700

2.3.4

Adapting the message structure


The adaptation of the message structure (selection of the message blocks) allows you to individually display the received messages in the way that suits you best. If the message structure is as desired, you can skip this point.
Figure 2-8: Window for adapting the message structure

Copyright Siemens AG 2009 All rights reserved

The table below describes how you can adapt the message structure to meet your individual requirements.
Table 2-5: Adapting the message structure Description 1. 2. Click on the Adapt Structure button. The Data Selection dialog box is opened. In the left list (Available Data), select the element you want to add to the selection and click on the -> button. New elements of the right list (Selected Data) are always inserted after the currently selected element in this list. Control element

V1.0

08.10.2009

21/46

Structure, Function and Application

Export of WinCC / CAS Archive Data


Description 3. To remove this element from the selection, select it in the right list and click on <-. Removed elements are added in the lower part of the left list.

35840700
Control element

4.

Your settings are applied by clicking on OK. To discard the changes, click on the Exit button. Attention: Adapting the data structure deletes all currently listed messages. After confirming the changes, no additional prompt is displayed.

Copyright Siemens AG 2009 All rights reserved

5.

After confirming the changes, all column headers and messages are deleted. Subsequently, the new column headers are entered and the column widths are adjusted. Note: If you have not selected a column for display, the later read process is cancelled prematurely. The status line displays the text No Data to be read.

Note

When starting the application, it automatically determines the settings last used for the message structure from the entries in the Column Headers section of the workspace.

When selecting the information for process values, ensure that any information there, apart from the time stamp and the quality code, triggers its own read process. The cause for this lies in the functionality of the respective SQL query.

V1.0

08.10.2009

22/46

Structure, Function and Application

Export of WinCC / CAS Archive Data

35840700

2.3.5
Instruction

Reading the messages

After you have made all settings, you can now read the desired messages from the archive.
Table 2-6: Reading the messages Description 1. Click on the Read button to read out the messages from the archive that correspond to the filter. Attention: Using the Read button deletes all currently listed messages. There is no additional prompt. Note: Listing the messages can be aborted by pressing the ESC key. 2. If necessary, back up the read data separately. Control element

Copyright Siemens AG 2009 All rights reserved

Note

After triggering the read command, the SQL query is first created and executed. During this time, the application is not reactive since it has to wait for a response of the SQL server. Depending on the number of requested messages, this can last up to several minutes. Subsequently, the individual messages are prepared (replacing the wildcards) and listed. During this process, the update of the workspace is disabled to increase message throughput, the status bar displays the progress of the process.

V1.0

08.10.2009

23/46

Structure, Function and Application

Export of WinCC / CAS Archive Data Error handling

35840700

The following section lists all error categories that can be assigned to the read action: Connection error Action: Connecting to the database Message: Error during Connect + error description Possible causes: Network problems (host not accessible); missing rights; missing installation of the WinCC OLE DB Provider on the client

Reading error Action: Opening the database and reading out the messages Message: Error during Open + error description Possible cause: WinCC is not in Runtime on the server.

Copyright Siemens AG 2009 All rights reserved

Processing error Action: Sorting and interpreting the message blocks, entering the messages Message: Error during Processing + error description Possible cause: The structure of the database and thus the structure of the returned messages have changed.

V1.0

08.10.2009

24/46

Background Information on the Principle of Operation

Export of WinCC / CAS Archive Data

35840700

Background Information on the Principle of Operation


This chapter provides information that makes it easier to expand the Alarms tab of the existing application or to better adapt it to your individual requirements. No change options are displayed for the Tags tab since all respective functionalities supported by the WinCC Connectivity Pack have already been implemented. This chapter is only relevant to you if you are interested in the software implementation or if you want to make changes to the application.

3.1

SQL statement
This section will help you understand the function of the SQL statement for reading out the data. If you have basic knowledge of programming in VBA and the SQL database language, reading this section will enable you to expand the application in different points if necessary.

Copyright Siemens AG 2009 All rights reserved

Note

The SQL statement used here contains a modification that is especially required for communicating with the WinCC OLE DB Provider. Due to this, the statement partly differs from the specified standard.

3.1.1

Parts of the SQL statement


An example explains the parts of the SQL statement and illustrates how the SQL statement is composed at full length. The description mainly focuses on showing the variable parameters. The following points describe in greater detail how these variable parameters are defined.

SQL example The example below shows an SQL statement that uses all filter options of the application. "ALARMVIEW: SELECT TOP 65000 * FROM AlgViewEnu WHERE DateTime > '2009-3-17 0:0:0' AND DateTime < '2009-3-17 23:59:59' AND (CLASS = 1 OR CLASS = 10) AND (Text2 = 'WEIGHT' OR (Text2 = '@2%s@' AND PText2 = 'WEIGHT') ) ORDER BY DateTime ASC"

V1.0

08.10.2009

25/46

Background Information on the Principle of Operation

Export of WinCC / CAS Archive Data Explanation of the statement elements

35840700

To enable you to better understand the different elements of the statement, the table below explains them in detail.
Table 3-1: Explanation of the elements of the SQL statement Statement element ALARMVIEW: SELECT * TOP 65000 FROM AlgViewEnu Explanation The relevant database is the one for Alarmview (providerspecific supplement). All data fields (columns) in the table or view still to be defined are required. The number of messages returned by the query is 65000. The data records are located in the AlgViewEnu view. This name contains several pieces of information: Alg: Prefix for AlarmLogging View: View (not a table). Enu: The alarms of the English configuration. Note: Unlike a table, a view does not contain data records. It merely compiles the desired information by means of references to different tables. The required messages have occurred in the specified period (UTC). Note: The conversion from local time to UTC and back is automatically performed by the application. Messages of the Alarm (coded as class 1 within the database) and Operator Message type (class 10) are required. Only messages are returned that have been generated in the plant area (internally directly stored in Text2 or from there referenced to associated value PText2) with the configured name WEIGHT. The messages are sorted in ascending order by their date of generation. Var (-) (-) (-) x Opt (-) (-) -

Copyright Siemens AG 2009 All rights reserved

WHERE DateTime > '2009-3-17 0:0:0' AND DateTime < '2009-3-17 23:59:59' AND (CLASS = 1 OR CLASS = 10) AND (Text2 = 'WEIGHT' )

(-)

ORDER BY DateTime ASC

(-)

(-)

Legend

Var Opt x (-)

Does the statement element change depending on the made settings? Can the element, irrespective of the made settings, be skipped ? Yes No No (relating to the application in unchanged form)

V1.0

08.10.2009

26/46

Background Information on the Principle of Operation

Export of WinCC / CAS Archive Data

35840700

3.1.2
Problem

Adding message languages

In this application, you can select between the archived messages in five different languages. However, since PCS 7 is used worldwide, it is possible that you want to access messages in additional languages. This section describes how the language selection is currently realized and how you can adapt it to your specific requirements if necessary. It can not be ensured that the procedure described below is successful in every case. This depends primarily on whether the name and the structure of the view associated with the language corresponds to the structure of the languages that have already been implemented. Overview To change the message language, the user proceeds as described in 2.3.2. The language is selected by means of the Language drop-down list the application requests when creating the SQL statement.
Copyright Siemens AG 2009 All rights reserved

The following table provides an overview of the currently available languages, the associated entries in the drop-down list and the names of the respective views.
Table 3-2: Overview of the language options Language German English French Italian Spanish Drop-down list entry German English Franais Italiano Espaol View name AlgViewDeu AlgViewEnu AlgViewFra AlgViewIta AlgViewEsp

Explanation As you see in the above overview, the view names differ only in their last three letters that are used to define the message language. In addition, it becomes clear that the first three letters of the drop-down list entries correspond to the last three letters of the view names in almost all cases. Procedure To create the SQL statement in the required form, the following code is used (VBAProject -> Microsoft Excel Objects -> Sheet2 -> cmdAlarmRead_Click): 'Select all columns strSQL = "ALARMVIEW: SELECT * FROM AlgView" 'Select the table according to the project language If Left(cmbAlarmLang.Text, 3) = "Eng" Then strSQL = strSQL & "Enu" Else strSQL = strSQL & Left(cmbAlarmLang.Text, 3)

V1.0

08.10.2009

27/46

Background Information on the Principle of Operation

Export of WinCC / CAS Archive Data End If

35840700

After assigning the constant part of the SQL statement, it is checked whether the selected entry in the drop-down list starts with Eng. If this is the case, Enu is added to the statement. Otherwise, the first three letters of the drop-down list entry are added.

Copyright Siemens AG 2009 All rights reserved

V1.0

08.10.2009

28/46

Background Information on the Principle of Operation

Export of WinCC / CAS Archive Data Adding a language

35840700

To add a message language to the existing selection, proceed as follows:


Table 3-3: Procedure for adding a message language Step 1. Expanding the dropdown list Description To expand the drop-down list, edit the initialization statements in the VBAProject -> Microsoft Excel Objects -> ThisWorkBook -> Workbook_Open module. Add an additional command line of the cmbAlarmLang.AddItem "English" form to the existing ones. Use your SQL Server Management Studio to determine the name of the view associated with this language. If the first three letters of your drop-down list entry correspond to the last three letters of the view name, no further change is required. If the letters differ, extend the if statement in the code excerpt presented above by a suitable ElseIf element.

2. 3.

Checking the identifiers Case 1: No further change necessary Case 2: Extending the if statement

4.
Copyright Siemens AG 2009 All rights reserved

3.1.3
Problem

Adding message types

This version of the application is capable of filtering the archived messages by up to six different message types. In PCS 7, however, another seven message types exist in addition to these six types. Furthermore, you have the option of creating your own message types. It may thus be required that the filter be extended by these message types. As in the previous section, this section first presents the current implementation and subsequently shows an option to change it. Overview Using the filter for message types has already been described in detail in 2.3.3. With the aid of the option box, the individual types are selected and added to the SQL statement when creating it.

V1.0

08.10.2009

29/46

Background Information on the Principle of Operation

Export of WinCC / CAS Archive Data Procedure

35840700

The following code realizes the necessary expansion of the SQL statement (VBAProject -> Microsoft Excel Objects -> Sheet2 -> cmdAlarmRead_Click): 'Apply filter If chkAlarmAlarms.Value = True Or _ chkAlarmWarnings.Value = True Or _ chkAlarmASPLCMessages.Value = True Or _ chkAlarmOSPLCMessages.Value = True Or _ chkAlarmOperatingMessages.Value = True Or _ chkAlarmSystemMessages.Value = True Then 'Flag to signalize that a part of the filter has already been entered 'Depending on the flag, further parts of the filter will be added in a different format Dim boolIsFirst As Boolean boolIsFirst = True 'If EventCategories are filtered a prefix is necessary strSQL = strSQL & "AND (" If chkAlarmAlarms.Value = True Then strSQL = strSQL & "CLASS = 1" boolIsFirst = False End If If chkAlarmWarnings.Value = True Then If Not boolIsFirst Then strSQL = strSQL & " OR CLASS = 2" Else strSQL = strSQL & "CLASS = 2" boolIsFirst = False End If End If () If chkAlarmSystemMessages.Value = True Then If Not boolIsFirst Then strSQL = strSQL & " OR CLASS = 18" Else strSQL = strSQL & "CLASS = 18" boolIsFirst = False End If End If

Copyright Siemens AG 2009 All rights reserved

V1.0

08.10.2009

30/46

Background Information on the Principle of Operation

Export of WinCC / CAS Archive Data 'If EventCategories are filtered a suffix is necessary strSQL = strSQL & ") " End If

35840700

Copyright Siemens AG 2009 All rights reserved

V1.0

08.10.2009

31/46

Background Information on the Principle of Operation

Export of WinCC / CAS Archive Data

35840700

The program flowchart shown in Figure 3-1 describes the structure of the above code excerpt. In the application, the area silhouetted in gray is executed once for each filterable message type, except for the alarms. To improve clarity, this representative section is included only once. Figure 3-1: Program flowchart for filtering by message types

Start
Is filter selected ? Yes boolIsFirst = True Append prefix to strSQL Are alarms filtered ? No No Is element selected ? Yes
boolIsFirst = False ?

No

Copyright Siemens AG 2009 All rights reserved

Yes

Append string to strSQL boolIsFirst = False

No

Append string2 to strSQL boolIsFirst = False

Yes Append string1 to strSQL Add suffix to strSQL

End

Adding a language To extend the filter elements by an additional message type, follow the instructions listed in the table below:

V1.0

08.10.2009

32/46

Background Information on the Principle of Operation

Export of WinCC / CAS Archive Data

35840700

Table 3-4: Procedure for adding a message type Step 1. Unprotecting the sheet Description Before you can insert the control element necessary for the extension, you have to unprotect the sheet. Use the following menu option: Tools -> Protection -> Unprotect Sheet Insert an additional option box to the already existing ones and enter a representative name for it. Note: To avoid layout problems, separate the position and size properties of the control element from the cell properties: 1. Open the Format -> Control menu option. 2. Go to the Properties tab. 3. Select Dont move or size with cells. 4. Confirm the changes. 3.
Copyright Siemens AG 2009 All rights reserved

2.

Inserting control element

Extending the source code

Extend the code section shown above by an element of the form: If chkAlarmSystemMessages.Value = True Then If Not boolIsFirst Then strSQL = strSQL & " OR CLASS = 18" Else strSQL = strSQL & "CLASS = 18" boolIsFirst = False End If End If The option box name and the message type number have to be changed. In the higher level query (If chkAlarmAlarms.Value = True Or ) you enter an appropriate condition ( Or chkAlarmSystemMessages.Value = True ). Note: With the aid of SQL Server Management Studio, you find an overview of the coding of the message types used in the current project. 1. When starting the application, select your WinCC server. 2. Navigate to the following table (example): Databases -> CC_OS_1__09_03_19_18_33_31 -> Tables -> dbo.MSMsgGroup 3. For the relevant coding from the GROUPDAT column, refer to this table. The relevant entries are of TYPE 3.

4.

Protecting the sheet

Protect the sheet again: Tools -> Protection -> Protect Sheet

V1.0

08.10.2009

33/46

Background Information on the Principle of Operation

Export of WinCC / CAS Archive Data

35840700

3.2
Problem

Expansion capability of the message structure


This application provides the option of displaying all message information (columns) that is also available in WinCC. However, the archived messages contain additional information such as AlarmTag, AckType and Servername that cannot be selected with these settings. To facilitate understanding, the current implementation is explained first. Based on this explanation, you are then provided with step-by-step instructions on how the message structure can be adapted.

Overview The procedure for adapting the message structure has already been described in detail in 2.3.4. The settings are made in a separate window. After confirming the changes, the workspace of the application is automatically adjusted.

Copyright Siemens AG 2009 All rights reserved

V1.0

08.10.2009

34/46

Background Information on the Principle of Operation

Export of WinCC / CAS Archive Data Procedure

35840700

The message structure influences the application in most different areas. For the expansion, it is merely important to know how the necessary basic information is initialized. All further sequences adapt to the respective settings (as long as they correspond to the program logic). Three arrays form the basis for the message structure:
Table 3-5: Basis of the message structure Array strAlarmDataName s Content Contains the names that are displayed to the user for selection. The current entries correspond to the names that are also used when editing the WinCC message structure in Graphics Designer. Note: These names differ from the ones used in the database. They are used to provide the user with an intuitive understanding.
Copyright Siemens AG 2009 All rights reserved

intAlarmRecordSe tID

Contains the position of each piece of message information of the record set. Note: After requesting the messages via the SQL statement (see 3.1.1), they are returned as a record set. The structure of a record set is always identical as long as neither the data source (the view) nor the queried structure (SELECT *) change. Due to this fact, each piece of information in this record set has a fixed position.

dblAlarmColumnWi dth

Contains the column width assigned to a piece of message information by default. Note: When adapting the message structure, the width of the assigned column is automatically adjusted for each selected piece of message information (see 2.3.4). This is done to ensure optimum display of the messages.

V1.0

08.10.2009

35/46

Background Information on the Principle of Operation

Export of WinCC / CAS Archive Data

35840700

The declaration of the arrays is made with the aid of a constant so that a uniform structure can be ensured (VBA-Project -> Modules -> MngAlarmPositions): Public strAlarmDataNames(1 To MAX_ALARM_DATA_COLUMNS) As String This constant corresponds to the number of pieces of message information which is 38 by default. The response of the arrays, e.g. during their initialization, occurs via further constants of which each one corresponds to one message information respectively (VBA-Project -> Modules -> MngAlarmPositions -> InitializeAlarmArrays): strAlarmDataNames(C_DATE_TIME) = "Date / Time" This improves the readability of the source code and simplifies making changes. According to their function as an index of the arrays, the constants for the message information include consecutive numbers (VBA-Project -> Modules -> Constants for jointly used constants or VBA-Project -> Modules -> ConstantsAlarm for alarmspecific constants): Public Const C_DATE_TIME = 1 Public Const C_MS = 2 Public Const C_PRIORITY = 3 The pieces of standard information are sorted according to their sequence in WinCC Graphics Designer. Expanding the message structure Expanding the message structure merely requires that the constants and array initializations be adapted. To do this, proceed as described in the following table:
Table 3-6: Procedure for expanding the message structure Step 1. Adapting the maximum value constant Description In VBA-Project -> Modules -> ConstantsAlarm, you enter the number of message information items for the MAX_ALARM_DATA_COLUMNS constant. Note: Via the constant, the application adjusts to the changed conditions. A correct value for this constant is thus essential.

Copyright Siemens AG 2009 All rights reserved

V1.0

08.10.2009

36/46

Background Information on the Principle of Operation

Export of WinCC / CAS Archive Data


Step 2. Adding the index constants Description

35840700

In the same module, add as many constants as required to the already existing index constants (e.g., C_PRIORITY). Note: Ensure that the new numbers are consecutive and that the value defined in MAX_ALARM_DATA_COLUMNS is not exceeded.

3.

Extending the array initialization

The presented arrays are initialized in the VBA-Project -> Modules -> MngPositions -> InitializeArrays module. Insert as many elements into each of the three arrays as pieces of message information you want to add and fill them with the associated data (see Table 3-5).

Copyright Siemens AG 2009 All rights reserved

V1.0

08.10.2009

37/46

Appendix

Export of WinCC / CAS Archive Data

35840700

4
4.1

Appendix
Enabling macros
As described in 2.1, the High setting for macro security prevents the application from being properly executed.

Application reference

Background The High default setting is used to protect your computer against harmful applications. Lowering the macro security level to Medium enables you to define the sources you trust and dont trust. When is the security setting too high? Figure 4-1 shows the warning displayed when the macros can no longer be run due to security settings that are set too high.
Copyright Siemens AG 2009 All rights reserved

Figure 4-1: Warning concerning disabled macros

How can macros be enabled? To enable macros, the macro security level must be set to Medium. To do this, proceed as follows: 1. Open Excel (setting is not file-specific). 2. Close all possibly occurring messages. 3. Select the Tools -> Options menu option.

V1.0

08.10.2009

38/46

Appendix

Export of WinCC / CAS Archive Data 4. The Options window opens.


Figure 4-2: Security settings Options window

35840700

Copyright Siemens AG 2009 All rights reserved

5. Select the Security tab and in this tab, click on the Macro Security button.

V1.0

08.10.2009

39/46

Appendix

Export of WinCC / CAS Archive Data 6. The Security window opens.


Figure 4-3: Security settings Security window

35840700

Copyright Siemens AG 2009 All rights reserved

7. Select Medium.

ATTENTION

Lowering the security settings to Low can also be used to enable macros. Using this setting, however, there is no protection whatsoever against running harmful macros of potentially unsafe Excel files.

8. Close both windows by clicking on the corresponding OK buttons.

V1.0

08.10.2009

40/46

Appendix

Export of WinCC / CAS Archive Data

35840700

9. When calling the application from now on, a warning indicating that this application contains macros is displayed. You are prompted to decide whether you want to enable these macros or not.
Figure 4-4: Confirmation prompt with regard to enabling macros

Copyright Siemens AG 2009 All rights reserved

10. Enable the macros by clicking on the Enable Macros button. 11. Subsequently, the application is loaded with enabled macros and is thus fully functional.

4.2

Interpreting the wildcards for associated values


To optimize the size of the message databases, the messages occurring in WinCC contain wildcards. This ensures that it is not necessary to repeatedly save the static information of the message. Since this application is based on the alarm system of WinCC, these wildcards have to be interpreted accordingly. Wildcards deviating from the standard (see description below) cannot be replaced. Instead, they are entered unchanged in the message text. The composition of these wildcards is explained in Figure 4-1 by the following example: @4%06.3f@

V1.0

08.10.2009

41/46

Appendix

Export of WinCC / CAS Archive Data


Table 4-1: Wildcard elements Name Process value block Section @ 4 Opening character The process variable whose value is inserted is defined here. Up to ten associated message values (process values assigned to the message, e.g. a level) and ten free texts (for example, the computer or user name for a process control message) can be assigned to each message. Separator There are two additional formatting options: Leading zeros (0) (*): When this function is activated, floating-point numbers are filled up to the number of characters specified in the Precision text field. Not available for texts Align left (-): If the number of digits of the process value to be inserted is less than the number of digits reserved, use this function to define whether the process value is aligned right or left when inserted into the user text. You can select max. one of the two formattings. Defines the number of characters that are reserved for the process value within the user text. Defines how many characters of the process value are to be inserted into the user text. Precision is not available for texts. Defines the type of the process value to be inserted. The following types are available: Text (s) Fixed point number Decimal (d) Octal (o) Hexadecimal (h) Floating-point number (f or g) Closing character Description

35840700

Optional No No

Format (*)

% 0

No Yes

Copyright Siemens AG 2009 All rights reserved

Number of reserved digits (*) Accuracy (*) Data type (*)

Yes

Yes

No

No

In the table above, several entries are marked with (*). The associated settings influence each other in their effects. The subsequent Table 4-2 describes the interaction occurring interactions.

V1.0

08.10.2009

42/46

Appendix

Export of WinCC / CAS Archive Data


Table 4-2: Interaction of the settings Number of Digits Data type Fixed point number Floating-point number Text With 0 LZ if precision is zero, otherwise LS LZ N/a Without 0 LS LZ With 0 LZ Precision

35840700

Without 0

LS LS

Decimal positions are filled with zeros N/a

Decimal positions are filled with zeros N/a

Legend

LS leading space (free digits are filled with blanks up to the number of digits) LZ leading zero (free digits are filled with zeros up to the number of digits or up to the precision)

Copyright Siemens AG 2009 All rights reserved

4.3

Creating wildcards for associated values


This section describes an option of how you can design your own wildcards. A WinCC function is presented that is both comprehensive and easily understood. However, please note that this information is only to be used for creating a template. In PCS 7, messages are still configured in the SIMATIC Manager and subsequently downloaded to the OS.

Preliminary Remarks

Instruction You can use a WinCC tool to create a template for your own wildcards (for message configuration). To do this, proceed as follows: 1. Start WinCC. 2. Open AlarmLogging Editor.

V1.0

08.10.2009

43/46

Appendix

Export of WinCC / CAS Archive Data 3. Open the following window using the Messages -> Text for Multiple Messages menu.
Figure 4-5: Configuration window for user messages

35840700

Copyright Siemens AG 2009 All rights reserved

V1.0

08.10.2009

44/46

Appendix

Export of WinCC / CAS Archive Data

35840700

4. Select the ... button at the end of the user text field. The following screen appears:
Figure 4-6: Configuration window for associated values

Copyright Siemens AG 2009 All rights reserved

4.4

Creating a new user for the WinCC Runtime database


A standard assumption of this application is that the same Windows users are logged on to the source and target computer and that they use the same passwords.

Preliminary Remarks

Procedure Use this online portal link http://support.automation.siemens.com/WW/view/en/27147643 to find instructions for creating a new user in the WinCC Runtime database and a description of how the SQL connection string (Name in the macro: strConn) has to be changed to log on via this user.

V1.0

08.10.2009

45/46

History

Export of WinCC / CAS Archive Data

35840700

History
Table 5-1: History Version V1.0 Date Okt 2009 First Issue Modification

Copyright Siemens AG 2009 All rights reserved

V1.0

08.10.2009

46/46

You might also like