Skip to main content
InSource Solutions

TN Appsvr153 Example Script Using Binding in Custom Properties

insource logo large.jpg

 

Description

This article from InSource shows how to use Binding in Custom Properties using an Indirect data type enables you to reference (read and write) to other attributes data. 

 

  • Author: Michael Walker
  • Published: 09/25/2015
  • Applies to: Wonderware Application Server

 

 

Details

 

ArchestrA 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 symbol 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.
ArchestrA Symbols also use scripting in the same way as the scripting of Application Server. 
However, as an ArchestrA Symbol 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 ArchestrA Symbol script 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. You can configure a loop in the script to query for the quality and use the indirect variable to read from and write to the reference when its quality is good. 


Note: Make sure to include an exit condition in your script, so that the script doesn’t "hang" in case the binding cannot be made.


The following example script shows you how to do this:


dim ptr as indirect;
dim timeout;
ptr.BindTo("ud1_001.Int1");
while (IsGood(ptr)==0); {if quality not good}
timeout=timeout+1; {increase the timer}
if timeout>10000 then {if timer reaches threshold}
exit while; {continue script execution}
endif;
endwhile; {otherwise just loop for a while}
ptr=42; {try to write to value to the reference}


A while loop is included in the script before the first write attempt. The while loop provides additional time for the symbol to connect to the reference. If the quality is good, then the script exits from the while loop.


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