Assert block

Short summary

Name

Assert

→POU type

→function

Category

IEC-block, UtilEnh functions, block with internal error diagnostic

Graphical interface

images/download/thumbnails/414782976/Assert-version-1-modificationdate-1535107655367-api-v2.png

Available since

  • version 1.50.0 (for logi.CAD 3) – initial variant

  • version 2.0.8 (for library Standard) – enhancement: output line within the message

Functionality

Use the Assert block in order to make a statement about the state of an element in the application (e.g. a variable). Hence, you are able to recognize logical errors in your application and/or to check the compliance with specifications.

If the block input C is evaluated with the value FALSE (or an equivalent), this block traces a message. Moreover, the output ENO of the calling →POU and of the Assert block itself is set to value FALSE (or an equivalent).

The message of the Assert block is displayed in the following locations:

  • within the console of the →runtime system
    The console of the runtime system is a command prompt that is opened when the runtime system is started and it displays the messages of the runtime system.

  • within the PLC Logging view of logi.CAD 3 – The advantage of this view is that its content is listed in tabular form.

Format of the message: Assertion failed in [calling POU,line]: condition

The information for [calling POU] and condition are output in the format of the generated C-code. If the length of the message exceeds 1024 characters, only Assertion failed will be traced.

Inputs


Identifier

→Data type

Description

Inputs:

C

BOOL

condition; expected to be TRUE
If the condition is evaluated with the value FALSE, the message is traced.

Input EN and output ENO are available when →calling the block. See "Execution control: EN, ENO" for information on input EN and output ENO.

Internal error diagnostic for block

Depending on the block input C, the output ENO of the block is set to value FALSE (or an equivalent).

Example for usage within ST-editor

FUNCTION_BLOCK TestAssertOutput
VAR
testInt : INT := 5;
testStr : STRING[5] := 'hello';
testReal : REAL := 3.14;
testTime : TIME := T#1s;
testArray : ARRAY[1..5] OF INT;
testStruct : TestStruct;
END_VAR
Assert(FALSE);
Assert(testInt > 10);
Assert(testStr = 'world');
Assert(testReal = 1.41);
Assert(testTime = T#2s);
Assert(testInt + 1 = 7);
Assert(ADD(testInt, 1) = 7);
Assert(testArray[testInt] = 3);
Assert(testStruct.element1 = 2);
END_FUNCTION_BLOCK

The following messages are traced for this example:

TID00005054: Assertion failed in [lcfu___TESTASSERTOUTPUT,21]: LC_EL_false
TID00005054: Assertion failed in [lcfu___TESTASSERTOUTPUT,27]: (LC_TD_BOOL)(LC_this->LC_VD_TESTINT > (LC_TD_INT)10)
TID00005054: Assertion failed in [lcfu___TESTASSERTOUTPUT,33]: (LC_STRING_EQ(LC_this->LC_VD_TESTSTR,"world",LC_STR_CMP_MODE_STRING))
TID00005054: Assertion failed in [lcfu___TESTASSERTOUTPUT,39]: (LC_TD_BOOL)(LC_this->LC_VD_TESTREAL == (LC_TD_REAL)1.41)
TID00005054: Assertion failed in [lcfu___TESTASSERTOUTPUT,45]: (LC_TD_BOOL)(LC_this->LC_VD_TESTTIME == LC_TIME_VALUE(RT_CC_CONST_LL(2),RT_CC_CONST_LL(0)))
TID00005054: Assertion failed in [lcfu___TESTASSERTOUTPUT,51]: (LC_TD_BOOL)((LC_TD_INT)(LC_this->LC_VD_TESTINT + (LC_TD_INT)1) == (LC_TD_INT)7)
TID00005054: Assertion failed in [lcfu___TESTASSERTOUTPUT,61]: (LC_TD_BOOL)(lFunction_ASSERT__C__leftOp_ADD.LC_VD_ADD == (LC_TD_INT)7)
TID00005054: Assertion failed in [lcfu___TESTASSERTOUTPUT,67]: (LC_TD_BOOL)(LC_SUBSCRIPT_ARRAY(LC_this->LC_VD_TESTARRAY,LC_this->LC_VD_TESTINT,(LC_TD_DINT)1,(LC_TD_DINT)5) == (LC_TD_INT)3)
TID00005054: Assertion failed in [lcfu___TESTASSERTOUTPUT,73]: (LC_TD_BOOL)(LC_this->LC_VD_TESTSTRUCT.LC_VD_ELEMENT1 == (LC_TD_INT)2)

When creating your application within the ST-editor, enter a call of a block by typing the text as requested by the syntax or use Content Assist.