All read data scripts should return the following fields, accessed by index:
0 |
Timestamp |
1 |
Value. If tag value data type is digital text, this should be the text value |
2 |
Quality |
3 (optional) |
If tag value data type is digital text, this should be the numeric value |
These scripts make use of the {TagId}, {StartTime}, {EndTime} and other time-based tokens to supply values to the queries.
Value
The data type of the Value column can be either text or numeric. If the tag is defined as digital text, then the Value field should contain the string representation, and the numeric equivalent (typically integer) should be returned after the Quality field.
Quality
The Quality column should come back using an OPC HDA valid quality value (Good=&H400C0 or Bad=&H40000), or the alternative OPCDA codes (Good=192, Bad=0, Uncertain=64). If the Value column has a null then the Quality is always considered bad for that row. It is important that the values come back in ascending time order.
Timestamp
Internally, the PARCview data server conforms to the rules of an OPC-compliant Historical Data Access (OPCHDA) server. By specification, a data request between StartTime and EndTime is interpreted as containing the StartTime and up to, but not including the EndTime. In SQL terms this might lead to a query of the form:
This is slightly different than a query that uses the SQL BETWEEN operator, as that would include the EndTime. In practice, however, PARCview’s SQL.NET dataseries is tolerant of users not completely specifying their scripts according to the specifications.
In the Data Prior script, the WHERE clause should always specify Timestamp < '{StartTime}'
In the Data After script, if the Data script has used a BETWEEN clause so that EndTime is included, then the WHERE clause should always specify Timestamp > '{EndTime}'
If the Data script does not return values that include the EndTime, then the Data After script’s WHERE clause should always specify Timestamp >= '{EndTime}'
Date Format
Use the Date/Time Parameter Format section to specify how values returned from the StartTime, EndTime and other time-based tokens should be formatted before being supplied to the query.
Format |
Description |
d |
Day of the month, use single digit when possible. |
dd |
Day of the month, always use double digits. |
ddd |
Abbreviated name of the day of the week. |
dddd |
Full name of the day of the week. |
h |
The hour using a 12-hour clock, use single digit when possible. |
hh |
The hour using a 12-hour clock, always use double digits. |
H |
The hour using a 24-hour clock, use single digit when possible. |
HH |
The hour using a 24-hour clock, always use double digits. |
m |
Minute of the hour, use single digit when possible. |
mm |
Minute of the hour, always use double digits. |
M |
Month of the year, use single digit when possible. |
MM |
Month of the year, always use double digits. |
MMM |
Abbreviated name of the month. |
MMMM |
Full name of the month. |
s |
Second of the minute, use single digit when possible. |
ss |
Second of the minute, always use double digits. |
t |
Just the first character of the AM/PM label. |
tt |
The full AM/PM label. |
yy |
The year as a two-digit number. |
yyyy |
The year as a four-digit number. |
: |
The time separator. |
/ |
The date separator. |
Current
The Current script should return a single row that will represent the most recent value available.
Refresh Delay
Use the refresh delay settings to throttle down frequent requests for current values. For example, if the refresh delay is 5M, then even if a trend is updating every 10 seconds, it will only run the current query for SQL Tags using this template every 5 minutes. This avoids unnecessary loading of SQL Server data that may not change very frequently.
Data
The Data script will return historical tag values for a given tag from a given start time up to but not including a given end time.
The Data script will also be used to bring back current values if there is not a Current script defined. It will do this by using the last row returned when passed a start time and end time that represents the last hour. For performance reasons it is preferable to use the Current script.
Data Prior
The Data Prior script should return a single row that will represent the last value just prior to the StartTime. This value is used for calculating interpolated values at the start time of the query if real values do not exist.
Data After
The Data Prior script should return a single row that will represent the first value just after the EndTime. This value is used for calculating interpolated values at the end time of the query.
Projection
The Projection script returns future or projected data for use in trends. Use the {ProjTime} token to retrieve the current time in the trend for use as the start time of the data query.
For SQL.NET sources, specifying a projection script is enough for PARCview to use the projected data. For other sources, the projection script’s template name must be specified in the source configuration.
Data Plot
The Data Plot script should return a plot-reduced data set for trends. In most cases, PARCview’s OPCHDA server or the source’s native OPCHDA server will calculate the plot-reduced set. It is unlikely that a plot-reduced set will be stored in SQL or calculated using SQL queries.
This script is primarily used by IPSQL-type sources, which use SQL as the interface to access historical data.
Data Aggregate
The Data Aggregate script should return a single aggregated value given an aggregate type and step interval. In most cases, PARCview’s OPCHDA server or the source’s native OPCHDA server will calculate aggregated values. It is unlikely aggregates will be stored in SQL or calculated using SQL queries for arbitrary time intervals.
This script is primarily used by IPSQL-type sources, which use SQL as the interface to access historical data.