32-bit table data search
The function searches for the value specified at input s1 in a block of 32-bit areas whose beginning is specified at input s2_Start and whose end is specified at input s3_End.
Input
32-bit area or equivalent constant to store the value searched for
starting 32-bit area of the block
ending 32-bit area of the block
The number of data items that match s1 is stored in special data register DT90037 (sys_iNumberOfFoundMatches).
The relative position of the first matching data item, counting from the starting 32-bit area s2_Start, is stored in special data register DT90038 (sys_iPositionOfFirstMatch).
The adresses of the variables at inputs s2_Start and s3_End must be of the same adress 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;
data_table: ARRAY [0..3] OF DINT:=[-44,222222,-44,12345];
number_matches: INT:=0;
position_1match: INT:=0;
END_VAR
When the variable start is set to TRUE, the function is carried out.
Instead of using an input variable in this example, a constant (-44) is assigned to input s1. The result is stored in special data registers DT90037 and DT90038. The two E_MOVE functions copy the results to the two variables number_matches and position_1match.BODY
WORKSPACE
NETWORK_LIST_TYPE := NWTYPELD ;
ACTIVE_NETWORK := 0 ;
END_WORKSPACE
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 6 ;
NETWORK_BODY
B(B_F,F97_DSRC!,Instance,8,0,15,6,,?DEN?Ds1?Ds2_Start?Ds3_End?AENO);
B(B_VARIN,,start,6,1,8,3,);
B(B_VARIN,,-44,6,2,8,4,);
B(B_VARIN,,data_table[0],6,3,8,5,);
B(B_VARIN,,data_table[3],6,4,8,6,);
L(1,0,1,6);
END_NETWORK_BODY
END_NET_WORK
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 5 ;
NETWORK_BODY
B(B_F,E_MOVE!,Instance,8,1,14,5,,?DEN?D?AENO?C);
B(B_VAROUT,,number_matches,14,3,16,5,);
B(B_VARIN,,start,6,2,8,4,);
B(B_VARIN,,DT90037,6,3,8,5,);
L(1,0,1,5);
END_NETWORK_BODY
END_NET_WORK
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 5 ;
NETWORK_BODY
B(B_F,E_MOVE!,Instance,8,1,14,5,,?DEN?D?AENO?C);
B(B_VAROUT,,position_1match,14,3,16,5,);
B(B_VARIN,,start,6,2,8,4,);
B(B_VARIN,,DT90038,6,3,8,5,);
L(1,0,1,5);
END_NETWORK_BODY
END_NET_WORK
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 5 ;
NETWORK_BODY
L(1,0,1,5);
END_NETWORK_BODY
END_NET_WORK
END_BODY
IF start then
F97_DSRC( s1:= -44 ,
s2_Start:= data_table[0] ,
s3_End:= data_table[3] );
number_matches:=DT90037;
position1_match:=DT90038;
END_IF;