Checking that Aggregates are Enabled in Logic Programs

If your Logic program assigns a value to a field in a database aggregate, you need to first ensure that the aggregate is enabled, that is, the $Enabled attribute of the aggregate is set to True.

Example:

The following ST logic will fail if the target point does not have the Control aggregate enabled. Execution of this program will result in an error that may cause problems, particularly if it is called from another program.

PROGRAM Set

VAR_INPUT

FullName : STRING;

END_VAR

VAR

CtrlMax AT %M({FullName}.Control.ControlMaximum) : INT;

CtrlMin AT %M({FullName}.Control.ControlMinimum) : INT;

END_VAR

VAR

iRangeMax AT %I(.Range Max) : INT;

iRangeMin AT %I(.Range Min) : INT;

END_VAR

CtrlMax := iRangeMax;

CtrlMin := iRangeMin;

END_PROGRAM

To avoid this, you should write the program to first check the $Enabled OPC attribute of the Control aggregate for the target point, as in the following example:

PROGRAM Set_If_Ctrl_Aggr_Enabled

VAR_INPUT

FullName : STRING;

END_VAR

VAR

CtrlMax AT %M({FullName}.Control.ControlMaximum) : INT;

CtrlMin AT %M({FullName}.Control.ControlMinimum) : INT;

Enabled AT %M({FullName}.Control.$Enabled) : BOOL;

END_VAR

VAR

iRangeMax AT %I(.Range Max) : INT;

iRangeMin AT %I(.Range Min) : INT;

END_VAR

IF Enabled THEN

CtrlMax := iRangeMax;

CtrlMin := iRangeMin;

END_IF

END_PROGRAM


Disclaimer

ClearSCADA 2017 R3