Table data search (16-bit search)
Searches for the value that is the same as s1 in the block of 16-bit areas specified by s2_Start (starting area) through s3_End (ending area) if the trigger EN is in the ON-state.
Input
16-bit area or equivalent constant to store the value searched for
starting 16-bit area of the block
ending 16-bit area of the block
When the search operation is performed, the search results are stored as follows:
The number of data that is the same as s1 is transferred to sys_iNumberOfFoundMatches.
The position the data is first found in, counting from the starting 16-bit area, is transferred to sys_iPositionOfFirstMatch.
Be sure that s2_Start £ s3_End.
The variables s1, s2_Start and s3_End have to be of the same data type.
if the area specified using the index modifier exceeds the limit.
if s2_Start>s3_End
if the area specified using the index modifier exceeds the limit.
if s2_Start>s3_End
All input and output variables used for programming this function have been declared in the POU header. The same POU header is used for all programming languages.
VAR
start: BOOL:=FALSE;
(*activates the fuction*)
search_value: WORD:=16#20;
(*specifies the value to
search for*)
data_array: ARRAY [0..3] OF WORD:=[16#101,16#2A04,16#20,16#20];
(*2 matches for 16#20
data_array[2] = 1st match*)
number_matches: INT:=0;
position1_match: INT:=0;
END_VAR
When the variable start is set to TRUE, the function is carried out.
BODY
WORKSPACE
NETWORK_LIST_TYPE := NWTYPELD ;
ACTIVE_NETWORK := 3 ;
END_WORKSPACE
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 7 ;
NETWORK_BODY
B(B_CONTACT,,start,4,2,6,4,);
B(B_VARIN,,search_value,7,3,9,5,);
B(B_VARIN,,data_array[0],7,4,9,6,);
B(B_VARIN,,data_array[3],7,5,9,7,);
B(B_F,F96_SRC,,9,1,16,7,,?DEN?D@'s1'?Ds2?Ds3?AENO);
L(1,3,4,3);
L(6,3,9,3);
L(1,0,1,7);
END_NETWORK_BODY
END_NET_WORK
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 6 ;
NETWORK_BODY
B(B_CONTACT,,start,4,1,6,3,);
B(B_F,E_MOVE,,9,0,16,4,,?DEN?Da_Num?AENO?C);
B(B_VARIN,,DT90037,7,2,9,4,);
B(B_VAROUT,,number_matches,16,2,18,4,);
L(1,0,1,6);
L(1,2,4,2);
L(6,2,9,2);
END_NETWORK_BODY
END_NET_WORK
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 5 ;
NETWORK_BODY
B(B_CONTACT,,start,4,1,6,3,);
B(B_F,E_MOVE,,9,0,16,4,,?DEN?Da_Num?AENO?C);
B(B_VARIN,,DT90038,7,2,9,4,);
B(B_VAROUT,,position1_match,16,2,18,4,);
L(1,2,4,2);
L(6,2,9,2);
L(1,0,1,5);
END_NETWORK_BODY
END_NET_WORK
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 6 ;
NETWORK_BODY
L(1,0,1,6);
END_NETWORK_BODY
END_NET_WORK
END_BODY
IF start then
F96_SRC( s1:= search_value ,
s2_Start:= data_array[0] ,
s3_End:= data_array[3] );
number_matches:=DT90037;
position_1match:=DT90038;
END_IF;