How Can We Help?
< All Topics
Print

How to Use Triggers Document


Purpose of this article

This article aims to show what is and how to use the Triggers Document.

1. What is Triggers Document?

The Triggers document is a task that runs in the background, running logical programs (using the built-in scripting language C#), in which execution can be Condition, Trigger, Calendar and interval. Some example uses of the Document Triggers include:

  • Run a Script to generate a report (Daily, weekly or yearly)
  • Run a script after changing a tag
  • Run a script after an alarm is triggered
  • Run a Script whenever an expression is true

It is also possible using a Document Triggers to run a Document Services.

Note: The performance of running the Triggers Documents will depend on the processing of the computer on which ADISRA SmartView is installed. Services documents and triggers have the same execution performance. Both run the scripts in RunTime mode.

Document Triggers is located in the navigation tree. To create a new Document Triggers, follow the steps below:

  • Right-click on the Triggers document located in the navigation tree.
  • Click New Document.

A new document will be shown:

Document Triggers is divided into two areas:

  • Document Settings, which contains a field to enable or disable the document.
  • Triggers Items, which contains all trigger items inserted in the document.

Use the Document Settings parameters in this document as follows:

  • Enable: Enables or disables Document Services. You can also use a boolean tag to enable or disable the document.

The Triggers Document is organized by triggers item. Each document can have several triggers, which can be configured separately. To insert or remove a trigger item, click the “Insert Trigger” or “Remove Trigger” button located in the upper left menu.

Below is an item of triggers inserted in the document. Each triggers item contains a field called “Type”, which defines the trigger type.

2. Types of Execution

2.1 Condition Type

The Condition type executes the trigger item if the condition is “true”. However, it is not possible to set the execution interval as in Document Services. By default the execution interval is 300ms.

Therefore, if we compare the Condition Type of the two Service and Trigger documents, it is possible to notice that the Condition of the Triggers Document will consume three times more CPU processing than the Condition of the Services Document. That’s because the script is running every 300ms. Therefore, if the script does not need to be executed very quickly, it is recommended to use the execution of a longer time interval, so as not to overload the application.

The condition type trigger item has several fields, and these must be filled in according to the type of execution being specified. The fields are:

  • Type: Defines the type of execution (Condition, Trigger, Interval or Calendar).
  • Condition: If the field is true, the trigger item will be executed. In this field it is possible to place a tag, expression or keep it in “true”.
  • Action Type: Defines what will be executed. An expression or a services document can be executed.
  • Expression field: Defines which expression will be executed after the condition field is true.
  • Action field: Defines which Service will be executed after the condition field is true.
  • Alias: Defines a name for the trigger item, so that it can be used by SVEvent functions.

SmartView allows you to create, delete, and view a trigger item using SVEvent functions in RunTime mode. For this, it is necessary to identify each trigger item with an alias, to be used in the parameter of the functions below.


2.1.1 Script Example (Incrementing tag)

According to the example below, whenever the condition “@tagtest == 5” is true, the script will be executed every 300ms.


2.1.2 Script Example (Running a Services Document)

According to the example below, whenever the condition “@tagtest == 5” is true, the Services1 Document will be executed every 300ms.

Note that, if the trigger item executes an expression, it is possible to open a window for script development, clicking on the “…” button.

it is also possible to validate the developed script by clicking on the “Validate” button.


2.1.3 Script Example (Using Alias)

According to the example below, when the command button is clicked in RunTime mode, a script will be executed in the Mouse Up event.

The Script is composed of a function SVEvent.SaveEvent. To use this function, it is necessary to pass the following parameters:

  1. Function to create a new trigger item.
  2. Name of the existing trigger document. If the document does not exist, it will be created.
  3. Trigger item alias.
  4. The type of the new trigger item. 1 to Condition, 2 to Interval or otherwise to Trigger.
  5. The action type of the trigger item. 1 to Service or otherwise to Expression.
  6. The action value of the trigger item. For example, the name of the service for action type Service or the script for the action type Expression.
  7. A string which represents the Condition field of the trigger item.

    After clicking the button above in RunTime mode, the trigger item will be created in the application and accessing the engineering environment, we will find the new trigger item created, shown in the image below.

2.2 Trigger Type

The trigger type executes the trigger item if the trigger tag changes from “False” to “True” or from “True” to “False”.


2.2.1 Script Example (Incrementing tag)

According to the example below, whenever the “@TagBool” tag changes its value, the expression will be executed. In this example, the tag “TagIncrement” will be incremented.


2.2.2 Script Example (Running Function)

According to the example below, whenever the “TagBool” tag changes its value, the expression will be executed. In this example, the SVReport Function will be executed.

2.3 Calendar Type

The “Calendar” type executes a trigger item if the defined DateTime is satisfied. The trigger item can be executed “daily”, weekly or “monthly”. The “Recur to every” field allows executing the trigger item repeatedly every “X” days if it is filled with a value above one.


2.3.1 Script Example (Running function daily)

According to the example below, whenever the datetime is satisfied, the trigger item will be executed daily.


2.3.2 Script Example (Running function weekly)

According to the example below, whenever the datetime is satisfied, the trigger item will be executed weekly, on Monday and Friday.


2.3.3 Sript Example (Running function monthly)

According to the example below, whenever the datetime is satisfied, the trigger item will be executed monthly, in the months January, July and October.

In the “Days” option, it is possible to choose which day of the month the script will be executed.
In the “On” option, it is possible to specify the day of a specific week.

2.4 Interval Type

The “Interval” type delays the execution of a script, that is, we can consider it as a timer.


2.4.1 Script Example (Incrementing a tag every 10 seconds)

According to the example above, every “10 seconds” the trigger item will be executed.



Leave a Reply

Your email address will not be published. Required fields are marked *

Table of Contents