QualityTrack.g

QualityTrack.g — writes the quality of a point as the value of another point.

Code

[Note]

The code for this and other example scripts can be found in the DataHub distribution archive, typically at one of these locations:

    C:\Program Files\Cogent\OPC DataHub\scripts\

    C:\Program Files\Cogent\Cascade DataHub\scripts\

Please refer to Section 3.1, “How to Run a Script” for more information on using scripts.

/*
 * This script polls the quality of an "input" point and writes the quality
 * as the value of another "output" point.
 * The input point is typically an actual point from an OPC server.  The output
 * point is a synthetic point that can be used to trigger email and ODBC events.
 * 
 * To alter this script, just edit the QualityTrack.constructor to change the
 * parameters of the .Track() call.  The parameters are:
 *   poll_secs - the polling rate.  This can be fractional, as in 0.5
 *   input - the name of the input point as a symbol
 *   output - the name of the output point as a symbol
 * 
 * You can add as many .Track() calls as you need to monitor multiple points.
 * 
 * In an email or ODBC Condition configuration, the quality of a point can be
 * compared to the OPC quality constants:
 * 		OPC_QUALITY_BAD
 * 		OPC_QUALITY_COMM_FAILURE
 * 		OPC_QUALITY_CONFIG_ERROR 
 * 		OPC_QUALITY_DEVICE_FAILURE
 * 		OPC_QUALITY_EGU_EXCEEDED 
 * 		OPC_QUALITY_GOOD
 * 		OPC_QUALITY_LAST_KNOWN
 * 		OPC_QUALITY_LAST_USABLE 
 * 		OPC_QUALITY_LOCAL_OVERRIDE
 * 		OPC_QUALITY_MASK 
 * 		OPC_QUALITY_NOT_CONNECTED
 * 		OPC_QUALITY_OUT_OF_SERVICE 
 * 		OPC_QUALITY_SENSOR_CAL
 * 		OPC_QUALITY_SENSOR_FAILURE 
 * 		OPC_QUALITY_SUB_NORMAL
 * 		OPC_QUALITY_UNCERTAIN
 */

require ("Application");
require ("Time");

class QualityTrack Application
{
}

method QualityTrack.CheckQuality(input, output)
{
    local info = PointMetadata(input);
    set (output, info.quality);
}

method QualityTrack.Track(poll_secs, input, output)
{
    datahub_command(format("(create %a 1)", output));
    .TimerEvery(poll_secs, `(@self).CheckQuality(#@input, #@output));
}

method QualityTrack.constructor ()
{
    // Change the poll_secs and the two point names here.  The # in front
    //of the point name is necessary.
    .Track(1, #$default:my_real_opc_point, #$default:my_synthetic_trigger);
	
    // Add more calls to .Track() here
}

ApplicationSingleton (QualityTrack);