Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

Application Server

Bind to off-engine attributes

  • Last UpdatedJul 22, 2024
  • 2 minute read

Reference binding is inherently an asynchronous process. This means that a reference to an attribute hosted on the same engine is immediately available, but off-engine references can require additional scan cycles to bind. In scripting binding to off-engine attributes, we recommend you check indirect variables for quality before using them.

You can use the following guidelines when binding to off-engine attributes:

  • Declare the indirect variables in the declarations section of the script. This retains the value across scan cycles.

  • Implement a mechanism to define different states of the script to distinguish between the normal execution cycle and waiting for bound references to resolve.

  • In the execution or assignment state, use BindTo() to bind the indirect variables. After BindTo, change the state to "waiting for references" to check these in the next scan.

  • In the "waiting for reference" state, use IsGood() to check the quality of the indirect variables. When all references show good quality, change to the normal execution state. The variables then are usable.

  • You can implement a TimeOut state if required. For example, the remote engine might be Off Scan.

The following script examples illustrate these guidelines.

dim bindedRef1 as indirect;

dim bindedRef2 as indirect;

dim scriptState as integer;

' Script States

' 0 = normal execution

' 1 = wait for remote references

if (scriptState==0) then;

' normal script logic

' perform normal tasks

' ...

' for this example, change the binding to remote engine

if (System.DateTime.Now.Second mod 10 == 0) then;

LogMessage("Change binding (1)");

bindedRef1.BindTo("ApplicationObject_001.SimValue01");

bindedRef2.BindTo("ApplicationObject_001.SimValue02");

scriptState = 1;

endif;

if (System DateTime.Now.Second mod 10 == 5) then;

LogMessage("Change binding (2)");

bindedRef1.BindTo("ApplicationObject_001.SimValue2");

bindedRef2.BindTo("ApplicationObject_001.SimValue1");

scriptState = 1;

endif;

endif;

if (scriptState==1) then;

' wait for remote references

' in this example we want two valid references

if (IsGood(bindedRef1) and IsGood(bindedRef2)) then;

LogMessage("Binded references are good.");

scriptState = 0;

endif;

endif;

As an alternative, you can use a WHILE-triggered script to allow evaluation at every scan cycle. Generally, WHILE loops are not recommended, but can be used to ensure execution.

In Declarations:

 

dim x as indirect;

dim y as boolean;

 

In Execute (while true: me.z):

 

if not y then

'This could also be done in the startup script

x.BindTo("Object1.attribute1");

y = true;

endif;

 

if IsGood(x) then

LogMessage(x);

me.z = false;

endif;

TitleResults for “How to create a CRG?”Also Available in