FB_MemRingBufferEx
The function block FB_MemRingBufferEx can be used to write data sets with different lengths in a ring buffer or to read previously written data sets from the ring buffer. The written data sets are read out according to the FIFO principle in the same order in which they were previously written to the ring buffer. This means that the oldest entries are the first ones that are read. The buffer memory is made available to the function block via the pBuffer/cbBuffer input variables. Writing/reading of data sets is controlled via action calls.
The functionality of this function block is similar to that of the FB_MemRingBuffer function block. During reading of data sets the FB_MemRingBuffer copies the data into an external buffer variable. FB_MemRingBufferEx only provides a reference for the data set (address pointer/length). The application must then copy the data itself for further processing.
The function block features the following tasks:
- A_AddTail (writes a new data set into the ring buffer.)
- A_GetHead (returns a reference: address pointer/length of the oldest data set in the ring buffer, but does not remove it.)
- A_FreeHead (reads and removes the oldest data set from the ring buffer. The returned address pointer/length is zero! The free memory segment is released for a new data set. )
- A_Reset (deletes all data sets in the ring buffer.)
- A_GetFreeSize (returns the byte size of the largest free memory segment in the buffer)
Inputs
VAR_INPUT
pWrite : POINTER TO BYTE;
cbWrite : UDINT;
pBuffer : POINTER TO BYTE;
cbBuffer : UDINT;
END_VAR
Name | Type | Description |
---|---|---|
pWrite | ARRAY OF BYTE | The address of the PLC variable or of a buffer variable that contains the value data that is to be written. The address can be determined with the ADR operator. The programmer is himself responsible for dimensioning the buffer variable in such a way that cbWrite data bytes can be taken from it. |
cbWrite | UDINT | The number of value data bytes that are to be written (In the case of string variables this includes the final null). |
pBuffer | ARRAY OF BYTE | Address of a PLC variables (e.g. ARRAY[...] OF BYTES) to be used as buffer memory by the function block. The address can be determined with the ADR operator. |
cbBuffer | UDINT | Max. byte size of the PLC variable to be used as buffer memory. The size can be determined with the SIZEOF operator. |
Outputs
VAR_OUTPUT
bOk : BOOL;
pRead : POINTER TO BYTE;
cbRead : UDINT;
nCount : UDINT;
cbSize : UDINT;
cbFree : UDINT;
END_VAR
Name | Type | Description |
---|---|---|
bOk | BOOL | Returns TRUE, if a new data set was added or removed successfully. Returns FALSE in the event of a buffer overflow or if no more entries are available in the buffer. |
pRead | BYTE | This variable returns a reference (address pointer) to the oldest data set in the ring buffer after the action: A_GetHead is called if successful (bOk=TRUE). It returns zero if no more data sets are available in the ring buffer. |
cbRead | UDINT | This variable returns the length of the oldest data set in the ring buffer after the action: A_GetHead is called if successful (bOk=TRUE). It returns zero if no more data sets are available in the ring buffer. |
nCount | UDINT | Returns the current number of buffered data sets. |
cbSize | UDINT | Returns the current number of assigned data bytes in the buffer. The number of assigned data bytes is always greater than the actual number of written value data. Each data set is complemented with additional information, so that it can be located later. |
cbFree | UDINT | Returns the byte size of the largest free memory segment in the buffer after the action: A_GetFreeSize is called. The data sets must use continuous addresses in the buffer memory, because the function block returns a reference for the data sets. This automatically leads to segmentation at the end of the buffer. This memory cannot be used if the new data set is greater than the free segment at the end of the buffer. |
Requirements
Development environment |
Target platform |
PLC libraries to be integrated (category group) |
---|---|---|
TwinCAT v3.1.0 |
PC or CX (x86, x64, ARM) |
Tc2_Utilities (System) |