LIFO

PLCopen motion icon

 Function Block - Manages a last in / first out list.

Inputs

Inputs

Data Type

Range

Unit

Default

Description

BUFFER

ANY

 

 

 

Array for storing values.

NEXTOUT

ANY

 

 

 

Value at the top of the stack.

Updated after call.

NEXTIN

ANY

 

 

 

Value to be pushed.

POP

BOOL

 

 

 

Pop a new value on the rising edge.

PUSH

BOOL

 

 

 

Push a new value on the rising edge.

RST

BOOL

 

 

 

Reset the list.

Outputs

Outputs

Data Type

Range

Unit

Description

EMPTY

BOOL

 

 

TRUE if the list is empty.

OFLO

BOOL

 

 

TRUE if the overflow is on a PUSH command.

Count

DINT

 

 

Number of values in the list.

pRead

DINT

 

 

Index in the buffer of the top of the stack.

pWrite

DINT

 

 

Index in the buffer of the next push position.

Remarks

  • NEXTIN, NEXTOUT, and BUFFER must have the same data type.
    • It cannot be a STRING.
  • The NEXTOUT argument specifies a variable filled with the value at the top of the stack after the block is called.
  • Values are stored in the BUFFER array.
    • Data is never shifted or reset.
    • Only read and write pointers and pushed values are updated.
    • The maximum size of the stack is the dimension of the array.
  • The first time an instance of the LIFO function block is called, that instance stores which array is passed to BUFFER.
    • If a later call to the same instance passes a different array for the BUFFER argument, the call is considered invalid and no action is performed.
    • The EMPTY output returns TRUE in this case.

FBD Language Example

FFLD Language Example

  • In the FFLD Language, the input rung is the PUSH input.
    • The output rung is the EMPTY output.

IL Language Example

(* MyLIFO is a declared instance of LIFO function block *)
Op1: CAL MyLIFO (PUSH, POP, RST, NEXTIN, NEXTOUT, BUFFER)
FFLD  MyLIFO.EMPTY
ST  EMPTY
FFLD  MyLIFO.OFLO
ST  OFLO
FFLD  MyLIFO.COUNT
ST  COUNT
FFLD  MyLIFO.PREAD
ST  PREAD
FFLD  MyLIFO.PWRITE
ST  PWRITE

ST Language Example

(* MyLIFO is a declared instance of LIFO function block. *)
MyLIFO (PUSH, POP, RST, NEXTIN, NEXTOUT, BUFFER);
EMPTY := MyLIFO.EMPTY;
OFLO := MyLIFO.OFLO;
COUNT := MyLIFO.COUNT;
PREAD := MyLIFO.PREAD;
PWRITE := MyLIFO.PWRITE;

See Also

FIFO