FP_DATA_SEARCH

Data search

This FP instruction searches for the value specified at s1 in the range specified by s2_Start and s3_End if the trigger EN is TRUE.

Parameters

Input

s1 (INT, DINT, UINT, UDINT, REAL, LREAL)

Data to be searched for

s2_Start (INT, DINT, UINT, UDINT, REAL, LREAL)

Beginning of search range

s3_End (INT, DINT, UINT, UDINT, REAL, LREAL)

End of search range

Output

d1_Count (DINT)

Number of matches found

d2_Pos (DINT)

Relative position of first match (first position is 0)

Remarks

  • Make sure that s2_Start£s3_End

  • The variables s1, s2_Start and s3_End have to be of the same data type.

  • The maximum number of data that can be searched is 30000.

Error flags

sys_bIsOperationErrorHold (turns to TRUE and remains TRUE)
  • if the area specified using the index modifier exceeds the limit.

  • if s2_Start>s3_End

  • if s2_Start and s3_End belong to different data areas.

sys_bIsOperationErrorNonHold (turns to TRUE for one scan)
  • if the area specified using the index modifier exceeds the limit.

  • if s2_Start>s3_End

  • if s2_Start and s3_End belong to different data areas.

Related topics:

Example

POU header

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
		bStart: BOOL:=FALSE;
			(*activates the fuction*)
		diSearch_value: DINT:=16#20;
			(*specifies the value to
search for*)
		adiDataField: ARRAY [0..3] OF DINT:=[16#101,16#20,16#2A04,16#20];
			(*2 matches for 16#20
data_array[2] = 1st match*)
		diNumber_matches: DINT:=0;
		diPosition1_match: DINT:=0;
	END_VAR

POU body

When the variable bStart is set to TRUE, the function is carried out.

LD body

BODY
    WORKSPACE
        NETWORK_LIST_TYPE := NWTYPELD ;
        ACTIVE_NETWORK := 0 ;
    END_WORKSPACE
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 7 ;
        NETWORK_BODY
B(B_CONTACT,,bStart,6,2,8,4,);
B(B_VARIN,,diSearch_value,11,3,13,5,);
B(B_VARIN,,adiDataField[0],11,4,13,6,);
B(B_VARIN,,adiDataField[3],11,5,13,7,);
B(B_F,FP_DATA_SEARCH!,,13,1,23,7,,?DEN?D@'s1'?Ds2_Start?Ds3_End?AENO?Cd1_Count?Cd2_Pos);
B(B_VAROUT,,diNumber_matches,23,3,25,5,);
B(B_VAROUT,,diPosition1_match,23,4,25,6,);
L(8,3,13,3);
L(1,3,6,3);
L(1,0,1,7);
        END_NETWORK_BODY
    END_NET_WORK
END_BODY

ST body

IF bStart then
    FP_DATA_SEARCH(s1 := diSearch_value, 
                   s2_Start := adiDataField[0], 
                   s3_End := adiDataField[3], 
                   d1_Count => diNumber_matches, 
                   d2_Pos => diPosition1_match);
END_IF;

Modified on: 2022-08-23Feedback on this pagePanasonic hotline