How to Use Services Document
Purpose of this article
This article aims to show what is and how to use the Services Document.
1. What is Services Document?
The Services 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 or Startup type. Some example uses of the Document Service include:
- Run a Script to Save a Report
- Run a script after changing a tag
- Run a script after an alarm is triggered
- Run a Script whenever the application starts
Services Document is located in the navigation tree. To create a new Services Document, follow the steps below:
- Right-click on the Services document located in the navigation tree.
- Click New Document.
A new document will be shown:
Services Document is divided into three areas:
- Document Settings, which contains a field to enable or disable the document.
- Service Settings, which contains run type information.
- Service Script, which contains the area to insert the script will be used based on the type of execution.
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.
Use the Service Settings parameters in this document as follows:
- Type: Defines the type of execution (Condition or Trigger). It is possible to use an expression in the field where “True” is set. If the expression is true, the script below will be executed.
- Interval(ms): Defines the time interval that the script execution should occur. The Time value is specified in a format of millisecond (for exemple, 1000 would be 1 second, 10000 would be 10 seconds). There is no minimum and maximum time limit.
- Description: Defines the document description.
Use the Service Script area to enter the script to be executed according to the type of execution.
Note: The performance of running Services Document will depend on the processing of the computer on which ADISRA SmartView is installed.
2. Types of Execution
2.1 Condition Type
The Condition type execute a script if the condition is true. Then, every X milliseconds, the script entered in the “Service Script” field will be executed. The time interval defined in milliseconds must be informed in the interval(ms) field.
Note: In the field set to true, a tag can be entered. If this tag is set to True, the script will be executed.
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 3000ms.
2.2 Trigger Type
The Trigger type executes a script if the value of the trigger tag changes from false to true or true to false. The trigger tag must be of type Boolean.
2.2.1 Script Example (Incrementing tag)
According to the example below, whenever the trigger tag “@tagBoolean” is true, the script entered in the “Service Script” field will be executed.
2.2.2 Script Example (Running another Services)
It is possible to run the “Service Script” from a services document, even if the chosen condition is not satisfied. For example, if a “Services1();” script is added to the Mouse Down event of a button, the script in the Services1 document will be executed whenever the button is pressed.
2.2.3 Script Example (Incrementing tag)
According to the example below, whenever the trigger tag “ShutDown_App” is true, the script entered in the “Service Script” field will be executed.
2.2.4 Script Example (Assigning value to a tag)
According to the example below, whenever the trigger tag “trigger_date” is true, the script entered in the “Service Script” field will be executed.
2.3 Startup Type
By default, the application automatically creates a Service Document called “Startup”. The script inserted in this service will be executed once every time the RunTime is started.
Note: The Startup Document cannot be removed from the application.
2.3.1 Application example
According to the example below, whenever the application is started, the script will be executed only once, being necessary to restart the application to execute the script again.