MEMCMP block

Short summary

Name

MEMCMP

→POU type

→function

Category

IEC-block, MemoryEnh, block with internal error diagnostic

Conform to →IEC-standard

images/s/b2ic8e/9012/1ca6q62/_/images/icons/emoticons/add.svg not defined in IEC-standard

Graphical interface

images/download/thumbnails/414781830/MEMCMP-version-1-modificationdate-1535027003138-api-v2.png

Available since

  • version 1.35.0 (for logi.CAD 3) – initial variant

  • version 1.38.0 (for logi.CAD 3) – adjusted return values

  • version 2.0.9 (for library Standard) – graphical interface with in-out variables

Functionality

The block compares bytes of one input value with the bytes of another input value and returns an appropriate value as information about the comparison (see the following table under "Return value").

You enter the first input value at input IN1 and the second input value at input IN2. At input LEN, enter the numer of bytes to be compared.
By default, value 0 is specified for the number of bytes.

Special cases:

  • In case of LEN = 0, the block automatically calculates the number of bytes to compare for IN1 and IN2.

  • If the value for LEN is > than the maximally possible size of the input values IN1 and IN2, the block compares until the maximally possible size of the input value. In this case, the output ENO is set to value FALSE.

  • If a STRING element with a length is connected to IN1 or IN2 , the length of the STRING buffer is used. The length of the STRING buffer is determined by the declaration.
    STRING elements with a length are STRING variables declared by you; see " Declaration of STRING variables (incl. access)".

  • If a STRING element without a length is connected to IN1 or IN2 , the length of the STRING buffer is also used. However, the length of the STRING buffer is determined by the resulting value.
    STRING elements without a user-defined length are resulting, if you are using STRING functions or →character string literals.

  • If you are using the MEMCMP block to compare an initialized structure variable with a variable which has been initialized identically by using the MEMSET block, the comparison of MEMCMP returns that both structures are different.

Inputs, outputs, return value


Identifier

→Data type

Description

In-outs
(VAR_IN_OUT):

IN1

REAL, LREAL, USINT, UINT, UDINT, ULINT, SINT, INT, DINT, LINT, TIME, BOOL, BYTE, WORD, DWORD, LWORD, STRING, CHAR, DATE_AND_TIME, DATE, TIME_OF_DAY or a →user-defined data type
Restriction: In case of →array data types, only one-dimensional arrays are allowed.

input value 1

IN2

REAL, LREAL, USINT, UINT, UDINT, ULINT, SINT, INT, DINT, LINT, TIME, BOOL, BYTE, WORD, DWORD, LWORD, STRING, CHAR, DATE_AND_TIME, DATE, TIME_OF_DAY or a →user-defined data type
Restriction: In case of →array data types, only one-dimensional arrays are allowed.

input value 2

Inputs:

LEN

UDINT

value for initialization; default value = 0

Return value:

-

SINT

0, if IN1 = IN2-1, if IN1 < IN21, if IN2 > IN1

Input EN and output ENO are available when →calling the block. See "Execution control: EN, ENO" for information on input EN and output ENO.

See:

Internal error diagnostic for block

The block checks the value connected to the inpu ts before it is executed.
If the value for LEN is > than the maximally possible size of the input values IN1 and IN2 , the output ENO of the block is set to value FALSE (or an equivalent).

Example for usage within ST-editor

PROGRAM Test
VAR
Var1, Var2 : BYTE := 0;
Var3 : DINT := 0;
Var4 : DINT := 10;
result1, result2, result3 : SINT;
END_VAR
result1 := MEMCMP(IN1 := Var1, IN2 := Var2, LEN := 1); (* The variable 'result1' evaluates to '0'. *)
result2 := MEMCMP(IN1 := Var3, IN2:= Var4, LEN := 3); (* The variable 'result2' evaluates to '-1'. *)
result3 := MEMCMP(IN1 := Var4, IN2:= Var3, LEN := 3); (* The variable 'result3' evaluates to '1'. *)
END_PROGRAM

When creating your application within the ST-editor, enter a call of a block by typing the text as requested by the syntax or use Content Assist.