25. BUFFER Management
25.1. _BUFFER_CLEAR
Type Function : BOOL
Input PT: POINTER TO BYTE (address of the Bufer )
SIZE: UINT (size of the bufer)
Output BOOL (Returns TRUE)
The function _BUFFER_CLEAR initialize any array of Byte with 0. When cal-
led, a pointer to the array and its size in bytes is passed to the function.
Under CoDeSys is the call: _BUFFER_CLEAR(ADR(Array), SIZEOF(Array)),
where array is the name of the array to be manipulated. ADR() is a stan-
dard function which identifes the pointer to the array and SIZEOF() is a
standard function, which determines the size of the array. The function
only returns TRUE. The array specifed by the pointer is manipulated di-
rectly in memory.
This type of processing arrays is very efcient because no additional me-
mory is required and no surrender values must be copied.
Example: _ARRAY_CLEAR(ADRs(bigarray), SIZEOF(bigarray))
initialized bigarray with 0.
25.2. _BUFFER_INIT
Type Function : BOOL
Input PT: POINTER TO BYTE (address of the Bufer )
SIZE: UINT (size of the bufer)
INIT: BYTE (initial value)
Output BOOL (Returns TRUE)
The function _BUFFER_INIT initializes any array of Byte with value INIT.
When called, a pointer to the array and its size in bytes is passed to the
function. Under CoDeSys the call reads: _BUFFER_INIT(ADR(Array), SI-
ZEOF(Array), INIT), where array is the name of the array to be manipula-
ted. ADR() is a standard function which identifes the pointer to the array
and SIZEOF() is a standard function, which determines the size of the ar-
ray. The function only returns TRUE. The array specifed by the pointer is
manipulated directly in memory.
This type of processing arrays is very efcient because no additional me-
mory is required and no surrender values must be copied.
Example: _BUFFER_INIT(ADR(bigarray), SIZEOF(bigarray),3)
initializes bigarray with 3.
25.3. _BUFFER_INSERT
Type Function : INT
Input STR: STRING ( string to be copied)
POS: INT (position from which the string is copied into the buf-
fer)
PT: POINTER TO BYTE (address of the Bufer )
SIZE: UINT (size of the bufer)
Output INT (position in bufer post included string
The function _BUFFER_INSERT copies a string in any array of Byte and mo-
ves the rest of the array to the length of the string. The string is stored
from any position POS in the bufer. The frst element in the array has the
position number 0. When called, a pointer to the array and its size in bytes
is passed to the function. Under CoDeSys the call reads:
_BUFFER_INSERT(ADR(Array), SIZEOF(Array)), where array is the name of
the array to be manipulated. ADR() is a standard function which identifes
the pointer to the array and SIZEOF() is a standard function, which deter-
mines the size of the array. The function returns the string copied from the
bufer as STRING. The array specifed by the pointer is manipulated direct-
ly in memory.
This type of processing arrays is very efcient because no additional me-
mory is required and no surrender values must be copied.
Example: _BUFFER_INSERT(STR, POS, ADR(bigarray), SIZEOF(bigarray))
25.4. _BUFFER_UPPERCASE
Type Function : BOOL
Input PT: POINTER TO BYTE (address of the Bufer )
SIZE: UINT (size of the bufer)
Output BOOL (Returns TRUE)
The function _BUFFER_UPPERCASE interprets each byte in the bufer as
ASCII characters and converts it to uppercase. When called, a pointer to
the array and its size in bytes is passed to the function. Under CoDeSys
the call reads: _BUFFER_INIT(ADR(Array), SIZEOF(Array), INIT), where array
is the name of the array to be manipulated. ADR is a standard function,
which identifes the Pointer the array and SIZEOF is a standard function,
which determines the size of the array. The function only returns TRUE. By
the Pointer given array is manipulated directly in memory.
This type of processing arrays is very efcient because no additional me-
mory is required and no surrender values must be copied.
Example: _BUFFER_UPPERCASE(ADR(bigarray), SIZEOF(bigarray))
25.5. _STRING_TO_BUFFER
Type Function : INT
Input STR: STRING ( string to be copied)
POS: INT (position from which the string is copied into the buf-
fer)
PT: POINTER TO BYTE (address of the Bufer )
SIZE: UINT (size of the bufer)
Output INT (returns the position in bufer post the imported string
)
The function _STRING_TO_BUFFER copies a string in any array of Byte.
The string is stored from any position POS in the bufer. The frst element
in the array has the position number 0. When called, a pointer to the array
and its size in bytes is passed to the function. Under CoDeSys the call
reads: _STRING_TO_BUFFER(STR, POS, ADR(Array), SIZEOF(Array)), where
array is the name of the array to be manipulated. ADR() is a standard
function which identifes the pointer to the array and SIZEOF() is a stan-
dard function, which determines the size of the array. The function returns
the string copied from the bufer as STRING. The array specifed by the
pointer is manipulated directly in memory.
This type of processing arrays is very efcient because no additional me-
mory is required and no surrender values must be copied.
Example:
_STRING_TO_BUFFER(STR, POS, ADR(bigarray), SIZEOF(bigarray))
25.6. BUFFER_COMP
Type Function : INT
Input PT1: POINTER (address of the frst Bufer )
Size1: INT (size of the frst bufer)
PT2: POINTER (address of the second Bufer )
SIZE2: INT (size of the second bufer)
START: INT (search begin from start)
Output INT (position found)
The function BUFFER_COMP checks whether the content of the array PT2
occurs in the array PT1 from position START. If PT2 is found in PT1, so the
function returns the position in PT1, starting from 0. If PT2 is not found in
PT1, -1 is returned. BUFFER_COMP can also be used for comparison of two
equally sized arrays.
When called, a Pointer to the array and its size in bytes is passed to the
function. In CoDeSys the call reads: BUFFER_COMP(ADR(BUF1),
SIZEOF(BUF1), ADR(BUF2), SIZEOF(BUF2)), where BUF1 and BUF2 are the
names of the arrays to be manipulated. ADR() is a standard function which
indentifes the Pointer to the array and SIZEOF() is a standard function,
which determines the size of the array. The function only returns TRUE.
The array specifed by the Pointer is manipulated directly in memory. This
type of processing arrays is very efcient because no additional memory
is required and no surrender values must be copied.
Example:
BUFFER_COMP(ADR(BUF1), SIZEOF(BUF1), ADR(BUF2), SIZEOF(BUF2))
25.7. BUFFER_SEARCH
Type Function : INT
Input PT: POINTER (address of the Bufer)
SIZE: UINT (size of the bufer)
STR: STRING (search string)
POS: INT (from the position being sought)
IGN: BOOL (Search is case-sensitive)
Output INT (position of the string was found)
The function BUFFER _ SEARCH search any array of Bytes on the contents
of a string and reports the position of the frst character of the string in the
array when a matching is found. The Bufer is searched from any position
POS. The frst element in the array is at position number 0. When called, a
Pointer to the array and its size in bytes is passed to the function. Under
CoDeSys the call reads: BUFFER_SEARCH (ADR (Array), SIZEOF (ARRAY),
STR, POS, IGN), where ARRAY is the name of the array. ADR() is a standard
function which identifes the pointer to the array and SIZEOF() is a stan-
dard function, which determines the size of the array. The function returns
the string copied from the bufer as STRING. This type of processing arrays
is very efcient because no additional memory is required and no surren-
der values must be copied. If IGN = TRUE both upper- and lowercase let-
ters are found as a match, while STR must be present in uppercase letters.
If IGN = FALSE case sensitive is searched.
Example: BUFFER_SEARCH(ADR(aArray), SIZEOF(Array), 'FIND', 0, TRUE)
Locates 'FIND', 'Find', 'fnd' .... in the array.
Example: BUFFER_SEARCH(ADR(Array), SIZEOF(ARRAY), 'FIND', 0, FALSE)
Only fnds 'FIND' in the array.
25.8. BUFFER_TO_STRING
Type Function : STRING
Input PT: POINTER TO BYTE (address of the Bufer )
SIZE: UINT (size of the bufer)
START: UINT (position from which the String will be from the
bufer
copied)
STOP: UINT (end of Strings in the bufer)
Output STRING (a string that was copied from the bufer)
The function BUFFER_To_STRING extracts a String from any array of Byte.
The String is copied from any position START from the bufer and ends at
the STOP position. The frst element in the array is at position number 0.
When called aPointer to the array and its size in bytes is passed to the
function. Under CoDeSys the call reads: BUFFER_TO_STRING (ADR (Array),
SIZEOF (ARRAY), START, STOP), ARRAY is the name of the array. ADR() is a
standard function which identifes the pointer to the array and SIZEOF() is
a standard function, which determines the size of the array. The function
returns the string copied from the bufer as STRING. This type of proces-
sing arrays is very efcient because no additional memory is required and
no surrender values must be copied.
Example: BUFFER_TO_STRING(ADR(Array), SIZEOF(ARRAY), START, STOP)