MEMCMP

MEMCMP 1:

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

FUNCTION MEMCMP : DINT

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

pBuf1: start address of the first memory area (the first data buffer).

pBuf2: start address of the second memory area (the second data buffer).

n: 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 relationship.

Return parameter

Relationship of the first byte that differs between the first and second data buffers

 -1

pBuf1 smaller 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

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

MEMCMP 2:

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

TwinCAT v2.7.0

PC or CX (x86)

PLCHelper.Lib

TwinCAT v2.8.0

PC or CX (x86)

TcSystem.Lib

TwinCAT v2.10.0 Build >= 1301

CX (ARM)

TcSystem.Lib