LGF_LIFO (FB / V3.0.1)


Author: Siemens Industry Support

Short description

LIFO (Last-In First-Out / Stack buffer memory)
This function stores incoming data and outputs the latest/most recent not-yet-processed data.

Block Interface

LGF_LIFO (FB)
Bool  push error  Bool
    
Bool  pop status  Word
    
Bool  peek subFunctionStatus  Word
    
Bool  reset elementCount  DInt
    
Bool  clear isEmpty  Bool
    
Variant  initialItem   
    
Variant  item  Variant
       
Variant  buffer  Variant
       
   

Input parameter

IdentifierData typeDefault valueDescription
pushBoolfalsePush item to the buffer
popBoolfalsePop item from the buffer
peekBoolfalsePeek item from the buffer (buffer not changed/modified)
resetBoolFALSEInitializing the buffer (reset the index and the counter)
clearBoolFALSEClearing the buffer and initialize with the initial value `initialItem` (Reset index and counter).
initialItemVariant---Value with which the ARRAY of the buffer is initialized (usually: `0` / default value)

Output parameter

IdentifierData typeDescription
errorBoolFALSE: No error
TRUE: An error occurred during the execution of the FB
statusWord16#0000-16#7FFF: Status of the FB
16#8000-16#FFFF: Error identification (see following Table)
subFunctionStatusWordStatus or return value of called FB's, FC's and system blocks
elementCountDIntNumber of elements in the buffer
isEmptyBoolTRUE: Buffer is empty

In/Out parameter

IdentifierData typeDescription
itemVariantThe entry that is either returned from the ring buffer or written into the buffer
bufferVariantThe ARRAY that is used as the ring buffer. (Array of…)

Status & Error codes

Code / ValueIdentifier / Description
16#0000STATUS_NO_ERROR
Status: Execution finished without errors
16#7000STATUS_NO_CURRENT_JOBS
Status: No current jobs, initial state
16#8001ERR_BUFFER_EMPTY
Error: The buffer is empty
16#8002ERR_BUFFER_FULL
Error: The buffer is full
16#8200ERR_NO_ARRAY
Error: No array is present at the input `buffer`
16#8201ERR_WRONG_TYPE_ITEM
Error: The data type of the InOut parameter `item` does not correspond to the data type of the array elements of the input `buffer`
16#8202ERR_WRONG_TYPE_INITIAL_ITEM
Error: The data type of the input `initialValue` does not correspond to the data type of the InOut parameter `item`
16#8610ERR_CLEAR_BUFFER
Error: While clearing buffer in block `MOVE_BLK_VARIANT` - check `subFunctionStatus` code
16#8611ERR_RETURN_LAST_ENTRY
Error: While return first entry of buffer in block `MOVE_BLK_VARIANT` - check `subFunctionStatus` code (POP & PEEK)
16#8612ERR_POP_REPLACE_ITEM_BY_INIT_VALUE
Error: While replace item by initial value in block `MOVE_BLK_VARIANT` - check `subFunctionStatus` code (POP)
16#8613ERR_WRITE_ENTRY
Error: While write entry to buffer in block `MOVE_BLK_VARIANT` - check `subFunctionStatus` code (PUSH)

Functional description

NOTE
The status of called commands is output in subFunctionStatus. In this case, the output value in status indicates which command caused the error. In this case, refer to the TIA Portal Online Help section for information on the respective commands.

NOTE
I computer science the stack is also based on the LIFO principle.

With the push input, a new item is stored from the InOut parameter item in the next free position in the buffer. The output elementCount is incremented by one.

With the pop input, the latest / most recent item is output to the InOut parameter item, and this field in the buffer is replaced by the value at the parameter initialItem. The output elementCount is decremented by one.

The peek input allows the last entry in the buffer to be read out. The buffer is not changed.

With the reset input, the buffer is initialized and the index and counter are reset. The elementCount output is set to zero and the isEmpty output is set to TRUE.

With the clear input, the buffer is emptied and initialized with the initial value initialItem. Index and counter are reset. The elementCount output is set to zero and the isEmpty output is set to TRUE.

Change log

Version & DateChange description
01.00.00Siemens Industry Online Support
10.07.2018First released version
01.00.01Siemens Industry Online Support
17.08.2018Upgrade: TIA V15 Update 2
01.00.02Siemens Industry Online Support
23.11.2018Upgrade: TIA V15.1
02.00.00Siemens Industry Online Support
29.01.2019Output "done" removed (not necessary, because block works synchron)
03.00.00Simatic Systems Support
22.10.2019Code refactoring, comments added
Interface change (push, pop, peek etc.)
Set version to V3.0.0, harmonize the version of the whole library
03.00.01Simatic Systems Support
15.02.2021Insert documentation