Skip to main content
InSource Solutions

TN IT243 InTouch Script Types

InSource_Logo_Transparent.png

Description

 

This article from InSource shows the different script types available in InTouch, and tries to explain the differences between them.

  • Author: Dillon Perera
  • Published: 12/26/2016
  • Applies to: InTouch 7.1 and up

Details

InTouch WindowMaker allows users to write multiple types of scripts.  The following gives information about these script types, as well as some general guidance on their usage.

 

Script Type Trigger Examples of when to use Notes

Application

WindowViewer starting.

WindowViewer shutting down.

While WindowViewer is running, with a periodic execution.

- On Startup determine the PC name and display content appropriately.

- On Startup create a log entry indicating the software is starting up.

- On Startup create a connection to a database for recipe data.  On Shutdown close the database connection.

On Shutdown scripts may not finish execution depending on how quickly InTouch finishes shutting down.  Because of the script execution cannot be guaranteed, it should only be used for simplistic tasks.

Window

Window first being displayed on screen.

Window being closed.

Window displayed, with a periodic execution.

- When a login window is displayed hide all other windows.

- While a window is displayed refresh a table every minute. 

On Show scripts execute as a Window is still being displayed, and may run before all elements on the screen have completed rendering.

For InTouch components this is not a problem, but often ActiveX controls are not fully loaded by the time the OnShow script runs.  Because the ActiveX is not completely loaded, OnShow scripts should not attempt to interact with ActiveX controls, as they will typically encounter an error.  Instead, a While Showing or ActiveX Event script can be used.

Condition

Condition listed in the Expression field is:

First met.

Continues to be met.

Is first no longer met.

Continues to no longer be met.

- At midnight ($Hour==0), save some values to a CSV file.

- If an EStop has been pressed, display a Window allowing the user to enter a downtime reason.

- If a security Timeout Warning ($TimeoutWarning) occurs, alert the user that they may get logged out.

The Expression in a Condition script does allow for multiple tag conditions to be chained together by using the AND and OR operators.  If many tags are chained together with both ANDs and ORs, parenthesis should be used to help other programmers understand the expression.

If chaining many AND and OR statements together, be aware that InTouch will not "Short-Circuit" while evaluation the expression.  Instead it will evaluate all components.

Data Change

Whenever a tag's value changes

- When a BatchID changes, reset other values.

- When a connection to a SQL database is lost, attempt a reconnect.

- If the logged in user changes, close windows and redisplay the initial navigation screens.

Data Change scripts should be used primarily for tags which will change infrequently.  For example, if used on a MotorSpeed Real tag, which changes in the decimal range, this script could potentially try to execute multiple times a second.

Key

When a Key Combination is pressed.

Continuously as a Key Combination is pressed.

When a Key Combination is released.

- When CTRL+A is clicked by the operator, display an Admin screen allowing users to log in or out.

- When F5 is pressed display the Home window.

 

When selecting a key combination for use in your script, it would be helpful to lookup the common key combinations used in Windows.  For example, CTRL+C is typically used to copy something to the Windows Clipboard.  Using this for a Key Script in WindowViewer may not be intuitive to users familiar with the Windows usage.

ActiveX Event

This is a special category of script, and is dependent on the type of ActiveX control that is used.  Each ActiveX control will have it's own list of allowed triggers.

- When a row in an Alarm Display is double clicked, acknowledge that alarm.

- When a new alarm is received play a sound file.

 

 

General Recommendations:

  • When first building a script, the programmer should attempt to write each script with the mindset that WindowViewer should evaulate the trigger as infrequently as possible.  
    • Example: We want a script that executes when the tag Boiler1_NuclearRodTemp >= 500.  We could create this as a While Running Application Script, a Data Change Script, or an OnTrue Condition Script.  For the Application Script and the Data Change script we would need to implement an IF statement to run our code only when >=500.  A Condition Script would only run when we specifically ran into this situation.  Because the condition script would only need to be ran once, instead of every few seconds or when the tag changed, our system will run smoother due to fewer scripts needing to be run at any moment.
  • InTouch is intended to be a supervisory layer for your process.  The actual control of the process should be handled by the Controller.  In the event that Windows/InTouch were to crash, the process should ideally be able to continue, at least the current batch, until the HMI is restored.  Critical logic should be placed in the Controller.  InTouch can also contain this critical logic, but the Controller is typically more stable.
  • "While" scripts (While Running, While Showing, etc.) can run periodically, but should be used minimally due to the overhead of running the script repeatedly.  When considering the use of a While script, consider whether this is something that could be done in the Controller, or could be done through a Condition or DataChange script.
  • QuickScripts can be used to create a reusable block of code, similar to a Function.  If you find that a common piece of code is used in multiple scripts, consider converting to a QuickScript.  The benefit of a QuickScript comes from standarization and reusability.  
    • An example of this would be converting from Celsius to Fahrenheit.  If this calculation is done in multiple places, creating a QuickFunction will make the functionality quicker to implement in other scripts.  As well, because there is now a single location for the code, it will prevent users from accidentally making mistakes when typing in the script to do the conversion manually.  Similarly, if a mistake is found in the QuickFunction, the programmer now only has to change the one QuickFunction and all scripts that utilize it will automatically be updated, instead of manually searching for it all scripts.