-
Notifications
You must be signed in to change notification settings - Fork 28
OSCAT BASIC ListProcessing
Matthias Mersch edited this page Apr 11, 2018
·
2 revisions
The lists described here are stored lists STRING (LIST_LENGTH), the ele-
ments of the list begin with the sign SEP followed by the element. The ele-
ments can contain all Strings allowable characters, and can also be an em-
pty string. An empty list is represented by the string '', the string contains
no elements. The length of a list is defned by the is the number of items
in the list, an empty list has lengths 0. The functions for processing lists
uses I/O variables, so that the long lists must note be copied at every
function call into the memory. The separation character SEP of the lists
can be freely determined by the user and is passed to the functions at the
input SEP. The separation character is always only a single character and
can be any valid character in a string.
In the following examples '§' is used as the separation character.
Empty list:
''
List with an empty element: '§'
List of 2 items '§1§NIX'
List with 6 elements one of which is empty '§1§§33§/§1§2'
Type Function: BOOL
Input SEP: BYTE (separation sign the list)
INS: STRING (New Item)
I / O LIST: STRING(LIST_LENGTH) (input list)
Output BOOL (TRUE)
LIST_ADD adds another element to the end of a list. The list consists of
Strings (elements) that begin with the separation character SEP.
Example:
LIST_ADD('&ABC&23&&NEXT', 38, 'NEW') = '&ABC&23&&NEXT&NEW'
Type Function: BOOL
Input SEP: BYTE (separation sign the list)
I / O LIST: STRING(LIST_LENGTH) (input list)
Output BOOL (TRUE)
LIST_CLEAN cleans a list of empty elements. The list consists of Strings
(elements) that begin with the separation character SEP.
LIST_CLEAN('&ABC$23&&NEXT', 38) = '&ABC&23&NEXT'
LIST_CLEAN('&&23&&NEXT&', 38) = '&23&NEXT'
LIST_CLEAN('&&&&', 38) = ''
Type Function: STRING(LIST_LENGTH)
Input SEP: BYTE (separation sign the list)
POS: INT (position of list element)
I / O LIST: STRING(LIST_LENGTH) (input list)
Output STRING (String output)
LIST_GET delivers the item at the position POS from a list. The list consists
of Strings (elements) that begin with the separation character SEP. The
frst element of the list has the position 1.
Example:
LIST_GET('&ABC&23&&NEXT', 38, 1) = 'ABC'
LIST_GET('&ABC&23&&NEXT', 38, 2) = '23'
LIST_GET('&ABC&23&&NEXT', 38, 3) = ''
LIST_GET('&ABC&23&&NEXT', 38, 4) = 'NEXT'
LIST_GET('&ABC&23&&NEXT', 38, 5) = ''
LIST_GET('&ABC&23&&NEXT', 38, 0) = ''
Type Function: BOOL
Input SEP: BYTE (separation sign the list)
POS: INT (position of list element)
INS: STRING (New Item)
I / O LIST: STRING(LIST_LENGTH) (input list)
Output BOOL (TRUE)
LIST_INSERT puts an element at the position POS in a list. The list consists
of Strings (elements) that begin with the separation character SEP. The
frst element of the list is at position 1. If a position greater than the last
element of the list is given, empty elements are added to the list until INS
is at its normal position at the end of the list. If POS = 0, the new element
will be placed to the top of the list.
Example:
LIST_INSERT('&ABC&23&&NEXT',38,0,'NEW')= '&NEW&ABC&23&&NEXT'
LIST_INSERT('&ABC&23&&NEXT',38,1,'NEW')= '&NEW&ABC&23&&NEXT'
LIST_INSERT('&ABC&23&&NEXT',38,3,'NEW')= '&ABC&23&NEW&&NEXT'
LIST_INSERT('&ABC&23&&NEXT',38,6,'NEW')= '&ABC&23&&NEXT&&NEW'
Type Function: INT
Input SEP: BYTE (separation sign the list)
I / O LIST: STRING(LIST_LENGTH) (input list)
Output INT (number of items in the list)
LIST_LEN determines the number of items in a list.
LIST_LEN('&0&1&2&3', 38) = 4
LIST_LEN('',21) = 0
Type Function: STRING
Input SEP: BYTE (separation sign the list)
RST: BOOL (Asynchronous Reset)
I / O LIST: STRING(LIST_LENGTH) (input list)
Output LEL: STRING(LIST_LENGTH) (list item)
NUL: BOOL (TRUE if list is executed or empty)
LIST_NEXT always delivers the next item from a list. The list is a STRING
whose elements are separated with the character SEP. The frst element
of the list has the position 1. After the frst call to LIST_NEXT or a reset, at
output LEL the frst element of the list is passed. For each subsequent call
the module returns the next element of the list. When the end of the list is
reached, an empty string Issued and set the output NUL = TRUE. With the
command RST = TRUE, the list can be edited again and again.
Example of application:
FUNCTION_BLOCK testll
VAR_INPUT
s1 : STRING(255);
END_VAR
VAR
Element: array [0..20] OF STRING( LIST_LENGTH) ;
list_n : LIST_NEXT;
pos : INT;
END_VAR
pos := 0;
list_n(LIST := s1, SEP := 44);
WHILE NOT list_n.NUL and pos <= 20 DO
element[pos] := list_n.LEL;
list_n(list := s1);
pos := pos + 1;
END_WHILE;
Type Function: STRING
Input SEP: BYTE (separation sign the list)
POS: INT (position of list element)
I / O LIST: STRING(LIST_LENGTH) (input list)
Output STRING(LIST_LENGTH) (string output)
LIST_RETRIEVE passes the item at the position POS from a list and deletes
the corresponding item in the list. The list consists of Strings (elements)
that begin with the separation character SEP. The frst element of the list
is at position 1. The function returns an empty string if no element is at
the position POS.
Example :
LIST_RETRIEVE('&ABC&23&&NX&, 38, 1) = 'ABC' LIST = '&23&&NX&'
LIST_RETRIEVE('&ABC&23&&NX', 38, 2) = '23' LIST = '&ABC&&NX'
LIST_RETRIEVE('&ABC&23&&NX', 38, 3) = '' LIST = '&ABC&23&NX'
LIST_RETRIEVE('&ABC&23&&NX', 38, 4) = 'NEXT' LIST = '&ABC&23&'
LIST_RETRIEVE('&ABC&23&&NX', 38, 5) = '' LIST = '&ABC&23&&NX'
LIST_RETRIEVE('&ABC&23&&NX', 38, 0) = '' LIST = '&ABC&23&&NX'
Type Function: STRING(LIST_LENGTH)
Input SEP: BYTE (separation sign the list)
I / O LIST: STRING(LIST_LENGTH) (input list)
Output STRING(LIST_LENGTH) (string output)
LIST_RETRIEVE_LAST passes the last item from a list and deletes the corre-
sponding item in the list. The list consists of Strings (elements) that begin
with the separation character SEP.