OPCReconnect.g

OPCReconnect.g — disconnects and reconnects an OPC DA server.

Code

[Note]

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

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

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

/* Sample script that disables the OPC DA connection labeled 
 * "OPC000", waits 2 seconds, then re-enables the connection.  
 * The result will be that the DataHub instance disconnects 
 * from the server for 2 seconds and then reconnects.
 */

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

class OPCReconnect Application
{
}

/* Create an object that references an existing OPC DA connection 
 * that we have configured through the user interface.  Its label 
 * is the first argument to setServer below.  Once we have the OPC 
 * connection object, we can call enable() with t or nil in the 
 * argument to enable or disable this connection.
 */
method OPCReconnect.enable(enabled)
{
    local	opcclient = new OPCConnection();
    opcclient.setVerbose(t);
    opcclient.setServer("OPC000");
    opcclient.enable(enabled);
}

method OPCReconnect.constructor ()
{
    .enable(nil);
    .TimerAfter(2, `(@self).enable(t));
}

ApplicationSingleton (OPCReconnect);