Configure a Script Tag

Script tags are one of the standard types built into VTScada. The script tag links a VTScada script code module to another tag's value. It is used to go beyond the power of in-tag expressions to allow the use of the full VTScada scripting language inside a tag.

The module for a script tag must have two parameters, as follows:

(
  PointObj         { object value of AI to monitor      };
  ScriptObj        { Script Object                      };
)

PointObj is the tag whose value is monitored and used by the Script tag. This matches the first field, "In Tag Scope", found in the Execute tab of the Script tag's configuration panel.

ScriptObj is used internally to link to your script tag. Whatever calculation is performed in your module must assign a value to ScriptObj\value. This enables the module to pass its calculated value back to your Script tag.

Create a filtering tag

This uses the V12 Training Simulator application. (Workspace for Expressions)

A first-order filter is used to smooth out noise from a value that tends not to change rapidly. Over time, it will match the value of whatever tag it is watching. It will lag changes, but transient spikes will have little effect on the value.

In the following example, the parameters PointObj and ScriptObj must be present by definition for use in a script tag. PointObj will match the tag selected for In Tag Scope parameter. ScriptObj points to the script tag that this module will be used in. This provides hooks between the Script tag and your code.

Note that, in this example, the calculation is done every two seconds, and that calculation exists in a script block, therefore running only a single time each two seconds. You could write this as a Watch() on the PointObj tag's value if you wanted code that executed on change rather than on time. Another feature to note is the ability to declare variables, in which you can save information from one iteration to the next.

  1. Copy the following code into a new file.
  2. Save the file as FilterFor.SRC in the SimulatedApp folder.
  3. Declare the module in the Plugins section of the AppRoot.SRC file.
  4. Import File Changes.
  5. Create a new script tag in the application.
  6. When configuring, select a tank level or a pump flow as the scope tag.
  7. Draw your script tag near whatever it is watching. Run the application.
{============================ Filter Module =======================}
{ This module is used to do a First order Filter of an input point }
{ Current Value = .1 * new value + .9 * previous value             }
{ The result is stored into the script point's value variable      }
{==================================================================}
(
  PointObj { object value of AI to monitor };
  ScriptObj { Script Object };
)
[
  PreviousValue { Previous Value };
]
Filtering [
  { ..every two seconds... }
  If AbsTime(1, 2, 0);
  [
    { Ensure there is a valid value first time through }
    PreviousValue = PickValid(PreviousValue, PointObj\Value);
    { Work out filtered value }
    ScriptObj\Value = .1 * PointObj\Value + .9 * PreviousValue;
    { Save for next time }
    PreviousValue = ScriptObj\Value;
  ]
]{ End of Filter Module }