FB_MemRingBuffer
The function block FB_MemRingBuffer 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 function block features the following tasks:
- A_AddTail (writes a new data set into the ring buffer.)
- A_GetHead (reads the oldest data set in the ring buffer, but does not remove it.)
- A_RemoveHead (reads and removes the oldest data set from the ring buffer.)
- A_Reset (deletes all data sets in the ring buffer.)
Inputs
VAR_INPUT
pWrite : POINTER TO BYTE;
cbWrite : UDINT;
pRead : POINTER TO BYTE;
cbRead : 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). |
pRead | BYTE | The address of the PLC variable or of a buffer variable into which the value data that has been read is to be copied. The address can be determined with the ADR operator. The programmer is himself responsible for dimensioning the buffer variable in such a way that it can accept cbRead data bytes. The size of the buffer variables in bytes must be greater than or equal to the size of the data set that is to be read. |
cbRead | UDINT | The number of value data bytes to be read. If the buffer size is too small, data is not copied. The function block reports a buffer underflow error (bOk = FALSE), and the buffer size required for the next data set that is to be read is returned at the cbReturn output. |
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;
nCount : UDINT;
cbSize : UDINT;
cbReturn : 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. |
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. |
cbReturn | UDINT | The number of value data bytes successfully read. If a read buffer underflow error has occurred, this output supplies the necessary read buffer size in bytes. In this case is the cbRead length is too small. |
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) |