Query historical data

The OPC HDA client establishes connection to each assigned HDA server and reads status information periodically. Historical queries can be triggered via the data point interface. The result of the historical query can be stored on response data points. Different response data points can be used for different queries to compare the results of several queries. A query can only contain one item. If several items shall be queried for the same range, you have to use consecutive queries.

The HDA client can retrieve items provided by the server via a browsing interface. The OPC HDA example panel is provided to demonstrate the data point interface.

Internal Data points

Browsing the server

The servers can be browsed via the internal data point element _OPCHDAServer.Browse.GetBranch. Depending on the defined mode, either the item Ids or the node Ids are returned and written on the internal data point element _OPCHDAServer.Browse.DisplayNames.

Example

ReqID_01

TestNode01

2

Historical query

To start a historical query the appropriate parameters (Item ID, start time, end time, etc.) must be written on the Command.HistoryRead element of the server data point.

Example

Request_0001

TestOPCHDANode1/Element_int1

2015.08.02 08:00:00.000

2015.08.05 16:00:00.000

20

0

ResponseDP1

The OPC HDA client stores the result (values, time stamps, etc.) of the historical query on the defined response data point of type "_OPCHDAHistoryReadResponse". The response data point must be created manually.

OPC HDA Client example panel

The OPC HDA Client example panel (/panels/examples/OPCHDA_DemoExample.pnl) provides the following functionality:

  • Browse the server items and display them

  • Run historical queries with user defined parameters

  • Display the data in a table or trend view

  • Export the result of historical queries to a CSV file

  • Write the result of historical queries to the WinCC OA archive of a specific data point element as correction value

Figure 1. OPC HDA Client example panel

Settings

Client

This combobox allows to select one of the available OPC HDA clients.

Server

Lists all OPC HDA servers which are available for the selected OPC HDA client.

Get Item ID

Opens the following panel and allows to select the item to query its historical values.

Item

Shows the selected item including the path.

Server state

Shows the current server state.

Value number

Defines how many historical values shall be queried starting from the defined start time.

Start

Defines the start time for the historical query.

End

Defines the end time for the historical query.

With bounds

Defines if boundary values shall be included in the query (refer to the OPC HDA 1.20 specification for more information).

Run query

This button triggers the historical query with the defined parameters.

Response data point

Allows to select one of the existing response data points of type _OPCHDAHistoryReadResponse.

Create response data point

Creates a data point of type _OPCHDAHistoryReadResponse.

Results

Table View

This table displays the queried values with timestamps and state.

Trend View

Displays the queried values in form of a trend view.

Return Code

Return value of the query. Following values are possible:

Value Description
0 Query successful
-2 No connection to the server
-3 Problems when requesting a server handle
-4 Error reading the data
-5 Not enough parameters defined (at least two of the parameters StartTime, EndTime and Number of Values must be defined)
-6 Server returns an error for this query

Count

Number of queried values

Export data to a CSV file

Via this button the table can be exported to an existing CSV file.

Write historical values to WinCC OA archive

The queried values can be written to the archive of a data point selected via the data point selector.