faq 03/2017 wincc tagcollector for sipat - siemens · faq 03/2017 wincc tagcollector for sipat ......

14
https://support.industry.siemens.com/cs/ww/en/view/109746353 FAQ 03/2017 WinCC Tagcollector for SIPAT SIMATIC PCS 7 V8.2 / SIPAT V5.0

Upload: truongkhanh

Post on 03-May-2018

307 views

Category:

Documents


6 download

TRANSCRIPT

https://support.industry.siemens.com/cs/ww/en/view/109746353

FAQ 03/2017

WinCC Tagcollector for SIPAT SIMATIC PCS 7 V8.2 / SIPAT V5.0

WinCC SIPAT Entry-ID: 109746353, V1.0, 03/2017 2

S

iem

en

s A

G 2

01

7 A

ll ri

gh

ts r

ese

rve

d

This entry is from the Siemens Industry Online Support. The general terms of use (http://www.siemens.com/terms_of_use) apply.

Security informa-tion

Siemens provides products and solutions with industrial security functions that support the secure operation of plants, systems, machines and networks. In order to protect plants, systems, machines and networks against cyber threats, it is necessary to implement – and continuously maintain – a holistic, state-of-the-art industrial security concept. Siemens’ products and solutions only form one element of such a concept. Customer is responsible to prevent unauthorized access to its plants, systems, machines and networks. Systems, machines and components should only be connected to the enterprise network or the internet if and to the extent necessary and with appropriate security measures (e.g. use of firewalls and network segmentation) in place. Additionally, Siemens’ guidance on appropriate security measures should be taken into account. For more information about industrial security, please visit http://www.siemens.com/industrialsecurity.

Siemens’ products and solutions undergo continuous development to make them more secure. Siemens strongly recommends to apply product updates as soon as available and to always use the latest product versions. Use of product versions that are no longer supported, and failure to apply latest updates may increase customer’s exposure to cyber threats. To stay informed about product updates, subscribe to the Siemens Industrial Security RSS Feed under http://www.siemens.com/industrialsecurity.

Table of content 1 Introduction ........................................................................................................ 3

2 WinCC Tagcollector for SIPAT ......................................................................... 5

2.1 Adding the desired tags to taglogging .................................................. 5 2.2 Writing the snippet ................................................................................ 5 2.3 Implementing the snippet in a SIPAT method .................................... 10

3 Glossary ........................................................................................................... 13

4 Related literature ............................................................................................. 14

1 Introduction

WinCC SIPAT Entry-ID: 109746353, V1.0, 03/2017 3

S

iem

en

s A

G 2

01

7 A

ll ri

gh

ts r

ese

rve

d

1 Introduction In this FAQ we’ll demonstrate an example of the interoperability between WinCC and SIPAT, namely the exchange of taglogging data via a so-called “extended calculation”.

Univariate data, such as flow measurements, are usually not directly connected to SIPAT, but can be made available from the PCS 7 or WinCC system.

The most common case to exchange data between WinCC (or PCS 7) and SIPAT would be to use the WinCC’s OPC server. For this, a simple OPC DA collector must be added, which points towards the “OPCServer.WinCC” on the WinCC server:

1 Introduction

WinCC SIPAT Entry-ID: 109746353, V1.0, 03/2017 4

S

iem

en

s A

G 2

01

7 A

ll ri

gh

ts r

ese

rve

d

However if fast polling rates for the univariate data or bigger amounts of data are needed, it’s recommended to first buffer the data within WinCC taglogging and subsequentially retrieve the values over the time-range of interest all at once via an extended calculation. The OleDB interface to the WinCC taglogging will be used for this.

The resulting data is stored as a multivalue (time and values matrix) in SIPAT and can very efficiently be used for further processing.

One of the additional advantages is that the SQL communication and security is used, which avoids the difficulties of DCOM related to OPC.

Prerequisites

SIPAT V5 is installed (including “extended calculations”) and working

WinCC V7.4 or PCS 7 V8.2 is installed and working

The packages can run either on the same or separate servers.

The SIPAT execution service user must have access to the WinCC’s database as we’ll use integrated security. This can be easily checked by opening the WinCC SQL instance with the SQL management studio running on the SIPAT machine. Alternatively a dedicated user can be set up for this communication.

2 WinCC Tagcollector for SIPAT

WinCC SIPAT Entry-ID: 109746353, V1.0, 03/2017 5

S

iem

en

s A

G 2

01

7 A

ll ri

gh

ts r

ese

rve

d

2 WinCC Tagcollector for SIPAT In this FAQ the SIPAT base station and RITS server is named “SIPATCENTRAL” and the WinCC server is named “PCS7V82VM”.

2.1 Adding the desired tags to taglogging

In WinCC, add the relevant tags to the taglogging and make the desired settings. All possible options of taglogging, including swinging door, can be used.

For instance the taglogging tag “CONTINUOUS_DATA/SINUS.PV#Value” in archive “SystemArchive”:

All values from the WinCC taglogging and alarmlogging can be retrieved via an OleDB interface. Details can be found here https://support.industry.siemens.com/cs/ww/en/view/109736226.

2.2 Writing the snippet

A general overview and some basic examples of SIPAT snippets can be found in the “SIMATIC SIPAT 5.0 User Manual”.

In the snippet, a database connection is made to the linked database “LnkRtDb_WinCCOLEDB”, which resides on the WinCC server. Once the

connection is made, a query is launched to retrieve the actual data (“'select *

from OPENQUERY”), and finally the data is passed as outputs of the function.

Copy the following code in a text-editor (code that needs to be modified for the specific use-case is highlighted in red) and save it as “WinCCSnippet.vb” on the desktop.

NOTE The snippet is tested and released for SIPAT V5.0 Upd1.

2 WinCC Tagcollector for SIPAT

WinCC SIPAT Entry-ID: 109746353, V1.0, 03/2017 6

S

iem

en

s A

G 2

01

7 A

ll ri

gh

ts r

ese

rve

d

'--- Referenced Assemblies

' System.Data.dll;System.Xml.dll

'---------- CONSTANTS ---------------------------------------------------

Const cDatabaseName = "master" 'name of the sql server database containing the

custom data

Const cServerName = "PCS7V82VM\WINCC" 'name of the sql server running above

mentioned database as well as the linked server

Const cTimestampColumn = "Timestamp"

Const cValueColumn = "RealValue"

Const cLogInTrace = True

Try

'Don't forget to update outputs of this script manually in SIPAT

configuration

'These parameters ca either be constants or defined as input for the

snippet

Dim tagString As Strin = "SystemArchive\CONTINUOUS_DATA/SINUS.PV#Value"

'Keep in mind that all dates are stored in UTC format in the database

and need to be in SQL datetimeformat

Dim strStartDate As String = "2017-1-09 09:00:00"

'startDate.ToString("yyyy-M-d HH:mm:ss")

Dim strEndDate As String = "2017-1-09 12:00:00" 'endDate.ToString("yyyy-

M-d HH:mm:ss")

' create connection

Dim bld As New System.Data.SqlClient.SqlConnectionStringBuilder()

bld.DataSource = cServerName

bld.InitialCatalog = cDatabaseName

bld.IntegratedSecurity = True

Dim tsColNr As Int32 = -1

Dim valColNr As Int32 = -1

Dim baseTime As DateTime

Dim values As New System.Collections.Generic.Dictionary(Of Single, Single)

Using conn As New System.Data.SqlClient.SqlConnection(bld.ToString)

conn.Open()

Using comm As New System.Data.SqlClient.SqlCommand()

comm.CommandText = String.Format("exec('select * from

OPENQUERY(LnkRtDb_WinCCOLEDB,''Tag:R,''''{0}'''',''''{1}'''',''''{2}'''''')')"

, tagString, strStartDate, strEndDate)

If cLogInTrace Then Trace("SnippetTrace: CommandText: "+

comm.CommandText)

comm.Connection = conn

Using rd = comm.ExecuteReader

While rd.Read

If cLogInTrace Then Trace("SnippetTrace:

Starting to read in the data for tag " + tagString + ".")

2 WinCC Tagcollector for SIPAT

WinCC SIPAT Entry-ID: 109746353, V1.0, 03/2017 7

S

iem

en

s A

G 2

01

7 A

ll ri

gh

ts r

ese

rve

d

If tsColNr.Equals(-1) Then

tsColNr =

rd.GetOrdinal(cTimestampColumn)

valColNr = rd.GetOrdinal(cValueColumn)

baseTime = rd.GetDateTime(tsColNr)

values.Add(0,

Convert.ToSingle(rd.GetDouble(valColNr)))

Else

Dim ts As DateTime =

rd.GetDateTime(tsColNr)

Dim val As Single =

Convert.ToSingle(rd.GetDouble(valColNr))

Dim elapsed As Single =

Convert.ToSingle((ts - baseTime).TotalSeconds)

values.Add(elapsed, val)

End If

End While

End Using

End Using

Dim cnt = 0

Dim matrix(values.Count - 1, 1) As Single

For Each kvp As System.Collections.Generic.KeyValuePair(Of

Single, Single) In values

matrix(cnt, 0) = kvp.Key

matrix(cnt, 1) = kvp.Value

cnt += 1

Next

'set the output of the snippet

SetOutput("WinCCResult", matrix) 'this is the output of the snippet

'Close connnection

Conn.Close()

End Using

Catch ex As Exception

'Raise alarm

RaiseAlarm("Calc", "Snippet script generated an error. See the station

log for more details. " + ex.Message)

Trace("SnippetError (Unhandled Exception): " + ex.ToString)

End Try

The actual retrieval of data happens in this line:

comm.CommandText = String.Format("exec('select * from

OPENQUERY(LnkRtDb_WinCCOLEDB,''Tag:R,''''{0}'''',''''{1}'''',''''{2}

'''''')')", tagString, strStartDate, strEndDate)

2 WinCC Tagcollector for SIPAT

WinCC SIPAT Entry-ID: 109746353, V1.0, 03/2017 8

S

iem

en

s A

G 2

01

7 A

ll ri

gh

ts r

ese

rve

d

This line will retrieve the data from tag “tagString” between the start and end timestamp. Other possible queries are given in section “0 WinCC OleDB”.

We reference to the variables “tagString”, “strStartDate” and “strEndDate”, which can be either hardcoded, computed in the script or defined as inputs for the snippet.

Note that the tagname should include the archivename as well, in the format <archivename>\<tagname>, where the tagname is the taglogging name and the default archivename is “SystemArchive”.

The time must be expressed in SQL format (YYYY-MM-DD hh:mm:ss) and in UTC as WinCC stores all values in UTC format. This applies to both input parameters and output timestamps! Proper conversion to UTC and local time, if desired, is still needed. Use the .net functions “ToUniversalTime()” and “ToLocalTime()” for this.

Alternative inputs and outputs are of course possible, for example a batchname as input and then retrieving the start and end time via the Simatic Batch database.

SIPAT method variables can be interaction with over the functions:

MethodVariableExist("<SIPATTag >",<ScriptVal>): reads the value of tag “SIPATTag” and stores it in the scriptvariable “ScriptVal”. The variable should have been declared and needs to have the proper type. MethodVariableExist should best be used in an IF statement, as it will return a 0 if the varaible doesn’t exist

SetMethodVariable("<SIPATTag>", <ScriptVal>): copies to value of scriptvariable “ScriptVal” to the SIPAT tag “SIPATTag”

Inputs and outputs of the snippet are used as follows:

<InputVal> = GetInput("<InputVar>"): to read input fields

SetOutput(<OutputVar>, <OutputVal>): to set output fields

For this particular snippet, System.Data.dll and System.Xml.dll are used, which come with Microsoft .net V4.0 and can be found in folder “C:\Windows\Microsoft.NET\Framework\v4.0.30319”.

2 WinCC Tagcollector for SIPAT

WinCC SIPAT Entry-ID: 109746353, V1.0, 03/2017 9

S

iem

en

s A

G 2

01

7 A

ll ri

gh

ts r

ese

rve

d

WinCC OleDB queries and details

All values from the WinCC taglogging and alarmlogging can be retrieved via an OleDB interface. Details can be found here https://support.industry.siemens.com/cs/ww/en/view/109736226.

By default the linked server “LnkRtDb_WinCCOLEDB” in the WinCC SQL instance can be used to execute the queries on. Use the following statement for this:

select * from OPENQUERY(LnkRtDb_WinCCOLEDB, <QUERY>)

The following figure shows the queries for retrieving taglogging data:

2 WinCC Tagcollector for SIPAT

WinCC SIPAT Entry-ID: 109746353, V1.0, 03/2017 10

S

iem

en

s A

G 2

01

7 A

ll ri

gh

ts r

ese

rve

d

2.3 Implementing the snippet in a SIPAT method

After storing the query in a VB file, make a new extended calculation “WinCCTagRetrieve” in SIPAT:

In the setting, first write “System.Data.dll;System.Xml.dll” in “Referenced assemblies”, then embed the vb file you saved earlier.

If all goes well, it should not throw an error. If there is an error in the script, the error will be shown in the SIPAT client.

2 WinCC Tagcollector for SIPAT

WinCC SIPAT Entry-ID: 109746353, V1.0, 03/2017 11

S

iem

en

s A

G 2

01

7 A

ll ri

gh

ts r

ese

rve

d

Now go to the outputs tab and make a new multivalue called “WinCCResult”.

Place the calculation in testing:

You can now use the snippet in a method. Click on “Calculation” and then “Preconfigured Calculation / Model”.

Select “Extended Calculation” and then the “WinCCTagRetrieve”, press “Next”.

Leave the inputs blank and keep the default name (“WinCCResult”) for the output. Add a multivalue feedback to the method to verify the result. The method should look as follows:

2 WinCC Tagcollector for SIPAT

WinCC SIPAT Entry-ID: 109746353, V1.0, 03/2017 12

S

iem

en

s A

G 2

01

7 A

ll ri

gh

ts r

ese

rve

d

Finally, place the method in Testing and run it.

3 Glossary

WinCC SIPAT Entry-ID: 109746353, V1.0, 03/2017 13

S

iem

en

s A

G 2

01

7 A

ll ri

gh

ts r

ese

rve

d

3 Glossary Snippet: a snippet is an extended calculation or evaluation rule, written in VB

.NET, which allows writing powerful custom functions. They even allow using external .NET framework class libraries. Snippets are called as a function in a SIPAT method and can exchange data with the latter via the inputs and outputs.

Univariate data: one-dimensional datapoint in time, for instance temperature reading

Multivariate data: multi-dimensional datapoint in time, for instance a spectrum from an NIR analyzer

4 Related literature

WinCC SIPAT Entry-ID: 109746353, V1.0, 03/2017 14

S

iem

en

s A

G 2

01

7 A

ll ri

gh

ts r

ese

rve

d

4 Related literature

Topic

\1\ Siemens Industry Online Support

https://support.industry.siemens.com

\2\ WinCC Connectivity Pack System Manual

https://support.industry.siemens.com/cs/ww/en/view/109736226

\3\ SIMATIC SIPAT 5.0 User Manual (on SIPAT DVD)