Use binding in custom properties
- Last UpdatedDec 19, 2024
- 3 minute read
Application Server object scripting supports a type called "Indirect". It enables you to bind a variable to a reference and read and write to it. This is done using the BindTo() method.
Note: The BindTo() method binds a variable to a reference as long as the graphic is shown.
For example, the local script variable ptr is defined and bound to the reference ud1_001.Int1.
dim ptr as indirect;
ptr.BindTo("ud1_001.Int1");
Within the same script you can use the indirect variable pointer to read from and write to the attribute ud1_001.Int1.
Industrial Graphics also use scripting in the same way as the scripting of Application Server.
However, as an Industrial graphic can be embedded into an InTouch window and run anonymously, the time it takes to connect to the reference can be longer than one scan cycle.
For that reason, you cannot use the indirect variable immediately after it is bound to a reference to read from and write to it.
dim ptr as indirect;
ptr.BindTo("ud1_001.Int1");
ptr = 42;
In the example, the value 42 cannot be written to the reference ud1_001.Int1 as the binding takes longer.
To avoid this problem, you can modify your Industrial graphic script, using the Industrial Graphic Script Editor to write the value after it is ensured that the binding is complete. The completion of the binding is indicated by the quality of the indirect variable.
-
Using artificial delays in the script is not recommended as this may result in script timeouts and would in turn affect UI refresh. For example, do not use a while loop that increments a variable from 1 to <60000. This could cause the runtime application (OMI or InTouch) to go blank blank or become unresponsive while the script is executing.
-
Instead of artificial delays, allow the whole script to continue execution across multiple cycles, without any artificial delays in the script, and set the script's expression to false once the quality of all the attributes is good.
Create a named script, with a trigger set to ‘While True’ and query for the quality and use the indirect variable to read from and write to the reference when its quality is good. This script will try again every second until the indirect attribute returns with good quality. If the quality is good, then the script exits from the while loop. Once the quality is confirmed, you can use the indirect variable reference in other scripts or button animations.
Note: Make sure to include an exit condition in your script, so that the script does not hang if the binding cannot be made.
The following example script shows you how to do this:
-
Expression: Create a Boolean custom property StartBind with an initial value of True.
-
Trigger: WhileTrue
-
Period: 1000 ms
dim ptr as indirect;
ptr.BindTo("ud1_001.Int1");
if IsGood(ptr)then {if quality not good}
StartBind = false;
else
LogMessage("Bidnding in progress..");
endif;

Note: Similar behavior can occur when you try to bind to a reference of an object that is hosted on a different AppEngine.