MEMCMP
The function MEMCMP allows the values of PLC variables in two different memory areas to be compared.
FUNCTION MEMCMP : INT
VAR_INPUT
pBuf1 :DWORD;
pBuf2 :DWORD;
n :UINT;
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 |
Sample of a call in FBD
VAR
Buffer1 : ARRAY[0..3] OF BYTE;
Buffer2 : ARRAY[0..3] OF BYTE;
CmpResult : INT;
END_VAR
In this sample, 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.