OPCReload.g

OPCReload.g — requests a reload of OPC server data with no disconnect.

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 requests a reload of data from a connected OPC server
 * without disconnecting from the server.  It is particularly useful
 * for automatically adding new points, and can poll for new points
 * based on a timer or on a trigger point.
 *
 * You will need to edit the following three variables to run the
 * script on your system:
 *
 *  connection_label: The name given to your OPC connection when you
 *                    defined your OPC server.  This appears in the
 *                   "Connection" column in your list of OPC Client
 *                    connections in the Properties window.
 *
 *  poll_time:        The poll rate to check for new points, in seconds.
 *
 *  trigger_point:    The name of the point you will use as a trigger.
 *
 */ 

require ("Application");
require ("OPCSupport");

class OPCReload Application
{
    connection_label = "OPC002";               // connection label in "Connection" column of OPC properties
    poll_time = 30;                            // poll rate for new points, in seconds
    trigger_point = #$domain_name:point_name;  // name of point used as a trigger
}

/* Transmit a "reload" command to the server, without disconnecting.
 * To disconnect and reload, change the paramter to opc.reload to t
 * instead of nil.
 */
method OPCReload.reload ()
{
    local   opc = new OPCConnection();
    opc.setVerbose(t);
    opc.setServer(.connection_label);
    opc.reload(nil);
}

/* Start the polling timer */
method OPCReload.constructor ()
{
    // To poll for new points periodically, use this line
    .TimerEvery (.poll_time, `(@self).reload());
	
    // To poll for new points only when a specific data point changes, use this line
    .OnChange (.trigger_point, `(@self).reload());
}

/* Instantiate the class.  This calls the constructor. */
ApplicationSingleton (OPCReload);