Function block - Manages a "first in / first out" list
PUSH : BOOL Push a new value (on rising edge)
POP :
BOOL Pop a new
value (on rising edge)
RST : BOOL Reset the list
NEXTIN : ANY Value to be pushed
NEXTOUT : ANY Value of the oldest pushed value - updated after
call!
BUFFER :
ANY Array for storing
values
EMPTY : BOOL
TRUE if the list is empty
OFLO : BOOL
TRUE if overflow on a PUSH
command
COUNT :
DINT Number of values in
the list
PREAD :
DINT Index in the buffer
of the oldest pushed value
PWRITE : DINT Index in the buffer of the next push position
NEXTIN, NEXTOUT and BUFFER must have the same data type and cannot be STRING.
The NEXTOUT argument specifies a variable that is filled with the oldest push value after the block is called.
Values are stored in the "BUFFER" array. Data is arranged as a roll over buffer and is never shifted or reset. Only read and write pointers and pushed values are updated. The maximum size of the list is the dimension of the array.
The first time the block is called, it remembers on which array it should work. If you call later the same instance with another BUFFER input, the call is considered as invalid and makes nothing. Outputs reports an empty list in this case.
In LD language, input rung is the PUSH input. The output rung is the EMPTY output.
(* MyFIFO is a declared instance of FIFO
function block *)
MyFIFO (PUSH, POP, RST, NEXTIN, NEXTOUT, BUFFER);
EMPTY := MyFIFO.EMPTY;
OFLO := MyFIFO.OFLO;
COUNT := MyFIFO.COUNT;
PREAD := MyFIFO.PREAD;
PWRITE := MyFIFO.PWRITE;
(* MyFIFO is a declared instance of FIFO
function block *)
Op1: CAL MyFIFO (PUSH, POP, RST, NEXTIN, NEXTOUT, BUFFER)
LD MyFIFO.EMPTY
ST EMPTY
LD MyFIFO.OFLO
ST OFLO
LD MyFIFO.COUNT
ST COUNT
LD MyFIFO.PREAD
ST PREAD
LD MyFIFO.PWRITE
ST PWRITE