For example, we can create a script so that whenever a Modbus register in device A has a specific value, the Titan writes a different value in a Modbus register in device B. Or, we can send an SMS; change a relay, etc. when a Modbus register in device A has a specific value.

The “Titan Scripts”, given they are editable by the user, allow we to create an infinite number of different applications with little effort. Below we have a guide showing the syntax of the “Titan Scripts” along with the available commands; however, the best way to learn how to use them and to see their potential is by understanding the examples.

Structure of the “Titan Scripts”

The Titan routers allow we to input up to 10 different scripts. The 10 possible scripts have the same structure, each with three text boxes, as shown below:

The first text box (IF) indicates the condition; that is, the Titan device will evaluate the logical expression contained here. The second text box (action1) is the action to be executed when the IF condition is true. The third text box (action2) is the action to be carried out when the IF condition is false. In pseudocode:

If what the first text box says is trueExecute the action in the second text boxIf what the first text box is not trueExecute the action in the third text box

Even though we still do not know the commands available, let’s see an example:

This example will be interpreted as follows:

If the sum of [register 10 of the Modbus device with the address 1] and [register 11 of theModbus device with address 1] is greater than 100Write [the value “1” in register 20 of the Modbus device with address 1]If the sum of [register 10 of the Modbus device with the address 1] and [register 11 of theModbus device with address 1] is not greater than 100Write [the value “0” in register 20 of the Modbus device with address 1]

Commands Supported by the “Titan Scripts”

Below we can see the commands currently supported, showing what we can do with them. The best way to understand the workings of each of them is by reading the examples in this section of the manual.

“Modbus Read” command:

Syntax: MR[modbusAddress,modbusRegister]

Description: reads a Modbus RTU device register. Can be used on the IF field, or the ACTION1 or ACTION2 fields

Syntax of the “Titan Scripts”

The “Titan Scripts” syntax is very similar to that of Java. In each condition’s “IF” field, we must specify a sentence that has a result of TRUE or FALSE, so that ACTION1 is executed if the IF condition is TRUE, and ACTION2 is executed if the IF condition is FALSE.

In the IF field, we can use all the standard operators in Java to create the condition:

&&: AND logic condition

||: OR logic condition

+ – * /: add, subtract, multiply, divide operators

==: “equal to” condition

>= “more than” condition

<: “less than” condition

>=: “more than or equal to” condition

<=: “less than or equal to” condition

(): parenthesis to encompass expressions

In the ACTION1 and ACTION2 field, we must use the MW, SR, SS action commands, although we can also use MR for more flexibility (this will become clearer in the examples that will come later). We can also use the operator && if we want ACTION1 and ACTION2 to carry out several actions. For example, we can make ACTION1 carry out two actions: write a Modbus register and send an SMS.

&&: concatenation of ACTION commands

Action Commands Execution Mode

Action fields have different execution modes. Edge mode (default), continuous (@) or only in the event of changes (#). The following examples show how this works.

Edge execution (default mode):

In this case the action MW[1,10,MR[2,3]] is executed just once upon the condition MR[2,2]>=18; i.e. once Action1 has been executed, it will not be executed again until the condition MR[2,2]>=18 is false, and then when the condition is true. This is useful when the user wants to send SMS message alerts or email alerts as this avoids continuous repeated messages.

Continuous execution (@):

In this case the action MW[1,10,MR[2,3]] is executed whenever the condition MR[2,2]>=18 is true. Do NOT use this option if SMS or emails will be sent as this will result in continuous messages being sent.

Execution upon changes (#):

In this case the action MW[1,10,MR[2,3]] is executed whenever there is a change in the action to be executed with respect to the the last execution. Therefore, for this example, it will be executed every time there is a change in the value MR[2,3].

Examples of “Titan Scripts”

The best way to understand how “Titan Scripts” work is by looking at examples. Below we can see a selection of examples to assist we.

EXAMPLE 1

If [register 10 of the Modbus device with the address 1] is greater than 100Write [the value “1” in register 20 of the Modbus device with address 2]OtherwiseWrite [the value “0” in register 20 of the Modbus device with address 2]

EXAMPLE 2

If [register 10 of the Modbus device with the address 1] plus [register 11 of the Modbus device with address 1] is greater than 100Write [the value “1” in register 20 of the Modbus device with address 1]OtherwiseWrite [the value “0” in register 20 of the Modbus device with address 1]

EXAMPLE 3

If [register 5 of the Modbus device with the address 1 has the value “1”] OR [register 6 of the Modbus device with address 1] is greater than 10Write [in register 7 of the Modbus device with address 1 the current value of register 1 in the Modbus device with address 1]OtherwiseWrite [in register 7 of the Modbus device with address 1 the current value of register 2 in the Modbus device with address 1]

EXAMPLE 4

Always (since the condition 1==1 will always be true)Write [in register 10 of the Modbus device with address 2 [the current value of register 11 of the Modbus device with address 1]

EXAMPLE 5

If [register 15 of the Modbus device with address 1] is greater than or equal to 100Activate Titan device’s Relay 1OtherwiseDeactivate Relay 1 on the Titan device

EXAMPLE 6

If (( [register 10 of the Modbus device with address 1] + [register 11 of the Modbus device with address 1]) is greater than 100) OR if (( [register 12 of the Modbus device with address 1] is greater than [register 100 of the Modbus device with address 2])Write [in register 20 of the Modbus device with address 1 [the current value of register 15 of the Modbus device with address 2 multiplied by 3 plus 1]]OtherwiseWrite [in register 20 of the Modbus device with address 1 [the current value of register 15 of the Modbus device with address 2 multiplied by 2 subtract 1]]

EXAMPLE 7

If [register 10 of the Modbus device with address 1] is equal to 1Send an SMS with the text “new alarm detected” to the telephone number 666123456

EXAMPLE 8

If [register 16 of the Modbus device with address 1] is greater than 10Send an SMS with the text “new value: [value read from register 16 del of the Modbus device with address 1]” to the telephone number 666123456 AND AFTER Write [in register 17 of the Modbus device with address 1 the value 1]]OtherwiseWrite [in register 17 of the Modbus device with address 1 the value 0]]

EXAMPLE 9

If [register 10 of the Modbus device with address 1] is equal to 1Send an SMS with the text “new alarm detected” to the telephone number 666123456 AND AFTER Activate the Titan device’s internal Relay 1OtherwiseDeactivate the Titan device’s internal Relay 1

EXAMPLE 10

If [register 15 of the Modbus device with address 1] is greater than 10[Activate the Titan device’s internal Relay 1] AND AFTER [pause for 5 seconds] AND AFTER [Deactivate the Titan device’s internal Relay 1]

EXAMPLE 11

If [register 15 of the Modbus device with address 1] is greater than 10CONTINUOUSLY [Activate the Titan device’s internal Relay 1] AND AFTER [pause for 5 seconds] AND AFTER [Deactivate the Titan device’s Relay 1]

The difference between example 10 and 11 lies in the @ symbol. This indicates that the action is continuously executed. This means that in example 10, ACTION1 is executed just once when the IF condition is true, and will not be executed again until ACTION1 changes or ACTION2 is executed. In example 11 however, ACTION1 is executed continuously whenever the IF condition is true; i.e. the relay is changing all the time.

EXAMPLE 12

If [register 4 in Modbus device with address 1] is greater than 10Send an email with the text “New alarm detected. Value [value read from register 4 of the Modbus device with address 1]” to the email jgallego@matrix.es

ADDITIONAL NOTES

Remember that if the command SE[] is used to send emails, the device must be configured beforehand using the menu “Other > Email configuration”

[EN] This Web site uses cookies to improve your user experience. If you continue browsing, by doing so you are giving your consent to the use of cookies and our cookie policy. Click the link for more information.