Applies To:
  • CitectSCADA 5.40, 5.41, 5.42, 5.50, 6.x, 7.x

Summary:
The IFDEF macro was added to Citect in version 5.40, and there is little documentation available for it in Citect 5.40 to 5.42. How do you use this feature? 

Solution:

For the same type of equipment, Genies allow you to draw and configure an object once and use it many times. However, not all of the equipment may be identical. For example, a pump may or may not have a Thermal Overload trip indication. Previously, two or more versions of the genie would be needed. With this enhancement, only one genie is required. The Thermal Overload indication could simply be hidden if its variable tag does not exist. This enhancement eliminates compile errors and allows the project to run even though the tag does not exist.

For example, a genie is displaying various motor information, including the state of a motor overload. The 'On Symbol When' expression is: Motor101_OL. To avoid compile errors if the overload tag does not exist, change the expression to: IFDEF("Motor101_OL", , 0). If the tag is defined, it will be used. Otherwise the expression will evaluate to 0. The Appearance (Visibility) 'Hidden When' expression of the object should be set to: IFDEF("Motor101_OL", 0, 1) so the symbol set is hidden if the tag does not exist.

The IFDEF(sTag, sTrue, sFalse) compiler macro (label) is defined in the Citect Include project to return either the true string or the false string, depending on whether the specified tag exists when the project is compiled. If the sTrue argument is blank, it will default to the tag name used for the sTag argument. Any tagnames should be enclosed in quotation marks so Citect does not display a 'Tag not found' error message.

By adding the following System Labels (macros) to your project, this feature can be enhanced so that there are default values for sTrue and sFalse, the tag's value may be returned automatically, and Is Not Defined logic may be used to make some statements clearer.

Label Name: _ISDEF(sTag,sTrue=1,sFalse=0)
Expression: $9
Comment: If Tag Is Defined macro

 

Label Name: _ISNDEF(sTag,sTrue=1,sFalse=0)
Expression: IFDEF(sTag,sFalse,sTrue)
Comment: If Tag Is Not Defined macro
Label Name: _IFDEF(sTag,sFalse=0)
Expression: IFDEF(sTag,sTag,sFalse)
Comment: If Defined macro

Macro Usage:

To check if a tag is defined, use the _ISDEF macro. If the specified tag exists, either TRUE or the sTrue value is returned, otherwise either FALSE or the sFalse value is returned.

_ISDEF(sTag, sTrue, sFalse)
sTag The variable tag to check for. The name must be enclosed in quotation marks
sTrue A variable tag name enclosed in quotes or a value. This value is returned if sTag exists (default value: 1)
sFalse A variable tag name enclosed in quotes or a value. This value is returned if sTag does not exist (default value: 0)

To check if a tag is not defined, use the _ISNDEF macro. If the specified tag does not exist, TRUE or the specified value is returned, otherwise FALSE or the other value is returned.

_ISNDEF(sTag, sTrue, sFalse)
sTag The variable tag to check for. The name must be enclosed in quotation marks
sTrue A variable tag name or value enclosed in quotes. This value is returned if sTag does not exist (default value: 1)
sFalse A variable tag name or value enclosed in quotes. This value is returned if sTag exists (default value: 0)

To use a tag if it is defined, use the _IFDEF macro. If the tag exists, that tag is returned, otherwise FALSE or the sFalse value is returned.

_IFDEF(sTag, sFalse)
sTag The variable tag to check for. The name must be enclosed in quotation marks
sFalse A variable tag name or value enclosed in quotes. This value is returned if sTag does not exist (default value: 0)

Example:

A numeric display object defined to display the expression: _IFDEF("Motor101")

If the Motor101 tag is defined in the variable tags list, the value of Motor101 will be displayed, otherwise 0 (the default value for the sFalse parameter) will be displayed.

Since you probably do not want to display anything if the tag is not defined, set the object's Appearance (Visibility) tab's 'Hidden When' expression to: _ISNDEF("Motor101")

The arguments for these macros are evaluated when the project is compiled, and the entire statement is replaced with either the sTrue or sFalse value (with the quotation marks removed).

These macros may cause compile errors if used for writing to tags like: _IFDEF("Motor101_SP") = ArgValue1
The recommended method is to use the TagWrite function, like: TagWrite("Motor101_SP", ArgValue1)

If Motor101_SP does not exist it won't cause a 'tag does not exist' compile error, but executing the command in the runtime would cause a hardware alarm. The input command should be disabled by setting the object's Access (Disable) tab's 'Disable When' expression to: _ISNDEF("Motor101_SP"); Or, the 'Hidden When' expression could be used as shown above.

A constant value may be used for the sTrue or sFalse argument instead of a variable. For example: _ISDEF("Motor101_SP", 5, 10)

These macros are especially useful in templates or genies using genie syntax. For example, if Motor101_SP was being passed to a genie as %Tag%, that tag could be displayed in the genie with an expression like: _IFDEF("%Tag%")

This feature is not compatible with Super Genie syntax. For example, IFDEF("?1?", 1, 0) will always return 0 since Citect checks if the sTag argument is a valid tag when you compile. When creating a genie to associate tags with the super genie, you do not need any special syntax. Just put the ErrSet(1) command before any association commands. This eliminates hardware alarms when one or more tags do not exist. For example:

ErrSet(1);
AssPopup("sg1", "%Tag%");

If a non-existent tag is associated with a Super Genie, text objects will display it as #ASS and graphic objects will have black dots on them. These objects may be hidden by setting the Appearance (Visibility) tab's 'Hidden When' expression to: AssInfo(1,0) = "". This checks if association number 1 is linked to a valid variable tag. See the AssInfo help page for details. In CitectSCADA 7.00 and later, AssInfo() has been replaced by AssInfoEx().

See also "Getting the Most out of Your Genies - Part 3" by Tim Munro in the Technical Hints section of the MyCitect News July/August 2003 issue.

 

Keywords:
 

Attachments