MEMCMP

MEMCMP 1:

The function MEMCMP allows the values of PLC variables in two different memory areas to be compared.

MEMCMP FUNCTION: DINT

MEMCMP 2: Inputs

VAR_INPUT
    pBuf1 : PVOID;
    pBuf2 : PVOID;
    n     : UDINT;
END_VAR

Name

Type

Description

pBuf1

PVOID

Start address of the first memory area (the first data buffer).

pBuf2

PVOID

Start address of the second memory area (the second data buffer).

n

UDINT

Number of bytes to be compared.

The function compares the first n bytes in the two data buffers and returns a value that corresponds to their ratio.

Return parameter

Ratio of the first byte that is different in the first and second data buffers

-1

pBuf1 lower than pBuf2

0

pBuf1 identical to pBuf2

1

pBuf1 greater than pBuf2

0xFF

Incorrect parameter values. pBuff1 = 0 or pBuff2 = 0 or n = 0

Example of a call in FBD:

PROGRAM MAIN
VAR
    Buffer1   : ARRAY[0..3] OF BYTE;
    Buffer2   : ARRAY[0..3] OF BYTE;
    CmpResult : DINT;
END_VAR

MEMCMP 3:

In this example, 4 bytes of data in Buffer2 are compared with those in Buffer1. The first differing byte is larger in Buffer1 than it is in Buffer2.

Requirements

Development environment

Target system type

PLC libraries to include (Category group)

TwinCAT v3.1.0

PC or CX (x86, x64, ARM)

Tc2_System (System)