FB_MemRingBuffer
The FB_MemRingBuffer function block allows data records of varying lengths to be written into a ring buffer, or for data records that have previously been written there to be removed from the ring buffer . The buffer operates as a FIFO; data records are read from it in the same sequence in which they were first written into the ring buffer. This means that the oldest entries are the first ones that are read. The buffer storage is provided to the function block via the input variables pBuffer / cbBuffer. Writing and reading the data records is controlled by action calls. The function block features the following tasks:
- A_AddTail (Write a new data record into the ring buffer.)
- A_GetHead (Reads the oldest data record from the ring buffer, but does not remove it.)
- A_RemoveHead (Reads and removes the oldest data record from the ring buffer.)
- A_Reset (Deletes all the data records in the buffer.)
VAR_INPUT
VAR_INPUT
pWrite : DWORD;
cbWrite : UDINT;
pRead : DWORD;
cbRead : UDINT;
pBuffer : DWORD;
cbBuffer : UDINT;
END_VAR
pWrite: 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: The number of value data bytes that are to be written. (In the case of string variables this includes the final null).
pRead: The address of the PLC variables 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 record that is to be read.
cbRead: 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 record that is to be read is returned at the cbReturn output.
pBuffer: Address of PLC variable (e.g. ARRAY[...] OF BYTES ) that is to be used by the function block as buffer storage. The address can be determined with the ADR operator.
cbBuffer: The maximum size, in bytes, of the PLC variables that is to be used as buffer storage. The size can be determined by the SIZEOF operator.
VAR_OUTPUT
VAR_OUTPUT
bOk :BOOL;
nCount :UDINT;
cbSize :UDINT;
cbReturn :UDINT;
END_VAR
bOk: Supplies TRUE if a new data record was inserted/deleted successfully. Supplies FALSE if a buffer overflow occurs or if no more entries do exist in the buffer.
nCount: Supplies the current number of buffered data records.
cbSize: Supplies the current number of stored data bytes in the buffer. The number of occupied data bytes is always bigger than the actual number of written value data.Each data record is complemented by addtional information to be localised later.
cbReturn: 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 the cbRead length is too small.
Requirements
Development environment | Target system type | PLC libraries to be linked |
---|---|---|
TwinCAT v2.10.0 Build > 1313 | PC or CX (x86, ARM) | TcUtilities.Lib |