Persistent Variables

Normally variable values are kept in RAM, which means that their value will be lost whenever VTS is stopped such as in the event of a power failure. This is usually not a problem for most values since they will be read in automatically from the plant I/O devices when the program is restarted. However, certain values such as process set points must be maintained during such events. The use of persistent variables resolves this problem.

Persistent variables (formerly known as "static" variables in some early versions of VTS) function identically with any variables except that a copy of their value is kept on disk. All of the persistent variables in a module will be stored in a file with the same name as the module and a .VAL extension. When VTS is restarted, the persistent values will be read from the .VAL file(s). This means that the value will always be maintained regardless of whether or not the program has been stopped.

Any variable may be defined as being a persistent variable by prefixing its definition with the keyword "Persistent". For arrays, all elements of the array become persistent values if the array itself is defined to be persistent.

The penalty to pay for making a variable persistent is that it requires a substantial amount of time to change its value. It requires a noticeable fraction of a second compared to a fraction of a millisecond for other variables. Therefore, persistent variables should not be used carelessly. They should only be used for values which are only updated occasionally such as operator-entered set points.

It does not require any additional time to reference or use the value in a persistent variable since a copy of its value is also kept in RAM.

Persistent numeric variables are always kept to their full precision on disk, but there is a limit on the number of characters kept on disk for persistent variables which hold text values; the default is 5 characters. This limit may be increased when the variable is defined (up to 65500 characters):

Persistent 15 UserName;

This will cause up to 15 characters of the variable UserName to be saved on disk. Any characters beyond the 15th will simply be discarded. The limit should be kept as small as practical since the use of large limits will increase the file space required as well as the update time for the variables. Persistent text values are always kept with no characters lost while in RAM, so it is only when VTS is stopped and restarted that the (limited) persistent value is assigned to the variable.

The limit you specify on text values is rounded to the next largest space that will hold that many characters. The space in the file is allocated in chunks of five characters each. For example, if you chose a limit of 42 characters, space would be allowed for Ceil (42 / 5) * 5 = 9 * 5 = 45 characters.

Persistent variables are automatically considered to be shared as well. This cannot be changed by the system designer.

Persistent variables values on disk are erased if the module where they are defined is compiled, or any part of that module is compiled. For this reason, persistent values are less useful for holding setup information. This role is usually filled by a disk file, or by using default values.

With the integration of Retained variables (see Retained Variables), the behavior of Persistent variables has changed as follows:

      Any data values supported by Pack may now be saved to disk (e.g. arrays, streams, link lists, etc.).

      The persistent size used for text string limits is no longer necessary. Any text string can be persisted, regardless as to its length.

      Recompiling a module does not delete the persistent variables.

Note: If you have an array (e.g. "A=New[10];"), and one element changes (e.g. "A[0] = 1;"), the modified value will not be known until the module has been stopped, as "A" itself did not change (its element did).