Adding Auto Reconnect Functionality to Device Integration Objects

Tech Note: ISS-TN116
Published Date: April 28, 2022
Primary Product: Application Server
Revision Date:

SUMMARY

When a Device Integration object gets disconnected from its data source (e.g. an AVEVA OI Server), it must be manually triggered to reconnect when the source becomes available again.  By using some basic scripting, you can configure the DI Object to automatically reconnect to the data source when the connection is lost. This tech note will instruct you on how to set up an auto reconnect feature and add additional diagnostic information that will indicate the number of disconnects the object has experienced since it last went on scan.

APPLIES TO

  • Application Server

PROCEDURE

Section 1 – Add the Auto Reconnect Functionality

First, you will create a script that will automatically reconnect to the data source when the connection is lost.

  1. In the IDE, create a derived template from the DI Object base template you will be using (in this example, we are using the $DDESuiteLinkClient). Open the derived template in the configuration editor.
  1. On the Scripts tab, click the Add Script button.
  1. Name the new script Reconnect and press Enter.
  1. Configure the Reconnect script as follows:

Aliases: locked
Declarations: locked
Execution type: Execute and locked
Basics: locked
Expression: Me.ConnectionStatus <> 2
Trigger type: WhileTrue
Trigger Period: 00:00:05.0000000
Script body: Me.Reconnect = true;

This script will attempt to reconnect every 5 seconds, when not connected to the data source.  You can adjust how often the object attempts to reconnect by modifying the Trigger Period setting.

Section 2 – Add an Attribute to Count the Disconnections

  1. On the Attributes tab, create and configure a new attribute as follows:

Name: Disconnect.Cnt
Data type: Integer
Writeability: Calculated

  1. On the Scripts tab, add a script named Disconnect.Monitor.
  1. Configure the Disconnect.Monitor script as follows:

Execution type: Execute and locked
Basics: locked
Expression: Me.ConnectionStatus <> 2
Trigger type: OnTrue
Script body: Me.Disconnect.Cnt = Me.Disconnect.Cnt + 1;

This script will increase a counter by one every time the condition is true.

Now you will add code within the same script under a different execution type that will run when the object goes on scan.

  1. While still in the Disconnect.Monitor script, change the Execution type to OnScan.
  1. In the script body, enter:
    Me.Disconnect.Cnt = 0;

This script will reset the counter to zero every time the object goes on scan.

  1. Save and Close the object.

You can now create instances of this derived template for use in runtime.  If the ConnectionStatus of the object is anything other than “2” (Connected), the script will trigger a reconnect attempt every 5 seconds until the connection has bee re-established.  The Disconnect.Cnt attribute will count the number of times this object has disconnected since it was put On Scan.


All Industrial Software Solutions Tech Notes are provided "as is" without warranty of any kind.