Script Code Examples

Here, you will find a set of examples of VTScada script code modules that you can add to your applications. In nearly all cases where you want to extend the features of an existing application, you will need to create a new module and declare it in the correct section of your application's AppRoot.SRC file. There are two exceptions that should be noted before starting:

  • Before writing any code, explore the features of VTScada. Many times, people have started to write code only to discover that existing features can be adapted to their needs.
  • If the goal is to add new user interface elements, add your code to the .SRC file of an existing page or custom widget.

 

Otherwise, if your goal is to extend a VTScada application by adding a new tag, driver, report, data-entry wizard, etc. then do the following:

  1. Using a text editor, create a new file in the application folder.
    The new file should be given a name that matches what you intend to call your module, and must have the extension, ".SRC".
  1. Write your VTScada code in that new file.
  2. Using a text editor, open AppRoot.SRC in the application's folder.
  3. Select the correct class group and declare your module within it as follows. (A guide to selecting the correct class group is provided after these steps.)
[ (PLUGINS) {===== Modules added to other base system modules =====}
   MyCustomReport  Module "15MinSnap.SRC";
]
  1. Use the application's Import File Changes tool in the VTScada Application Manager. When prompted, add the new file to your application.

Importing new files

Class Declarations for Modules

Modules are declared within class groups in AppRoot.SRC. These control how the module will be treated by the application. For example, all pages must be declared within the [ (PAGES) ...] class. All user-defined tag-types are declared in the [ (POINTS)... ] class, where "point" is another term for "tag".

Use the following list to decide where to declare your new modules. In each case, the text in bold should be used as the class designation, according to the following example:

[ (PAGES) Overview Module "\Pages\Overview.SRC"; ]

(65282)

User-Defined widgets. VTScada will populate this list automatically with each new widget that you create.

(POINTS)

User-defined tag templates. Similar to user-defined widgets, each time that you run Create New Type on a Context tag, a new module declaration will be added to this class for you.

(GROUPS)

Modules that are collections of tag types such as "Analogs" and "Digitals". It is extremely unusual to declare your own tag groups, but if doing so, the module for that group definition must be declared in this class.

(LIBRARIES)

Modules that contain a listing (library) of widgets. This is a legacy feature. Rather than explore it, you are advised to use custom folders in the Widgets palette.

(GRAPHICS)

Modules that are shared widgets for tag types. Trihedral does not document how to create custom widgets from code. You are advised to create custom widgets using the Idea Studio, then modify the resulting .SRC file if needed.

(PAGES)

Application pages. VTScada will automatically add a module declaration to this class for every new page that developers create in the application.

(SERVICES)

Service modules start when the application starts, and then run continuously. As an example, a custom security service would be declared in this class. See: HideVAM Based on Security Privileges

(PLUGINS)

By far, the most commonly used class for user-defined modules. Examples include custom reports, custom tag configuration panels, modules for use with Script tags, etc.

(PRIORITYSTART)

Modules that are to be started before the application loading process finishes. The VTScada Time Synchronization Service is an example. It is unlikely that you will have a reason to add modules to this class.

(TSERVICES)

Modules that are to be run as threaded services. For use only by advanced VTScada programmers.

(SHUTDOWN_HOOK)

Any module in this class will run automatically when during the application shutdown process. These may be used to write extra information to disk, send a notification, or perform any other task before the shutdown process completes.

Note: In the case of a shutdown caused by the time limit of a trial license expiring, the shutdown_hook module can delay shutdown by up to ten minutes, but cannot prevent that shutdown.