MEMCPY

MEMCPY 1:

The function MEMCPY can be used to copy the values of PLC variables from one memory area to another.

Notice

System crash or access to unauthorized memory areas

Since the function directly accesses the physical memory, special care must be taken when using it. Incorrect parameter values can result in a system crash, or in access to forbidden memory areas.

MEMCPY 2:

The behavior of MEMCPY is undefined if the destination and source memory areas overlap. This is the case, for example, when several values stored in an array are to be moved one position forward or backward. In such a case, use the function MEMMOVE.

FUNCTION MEMCPY : UDINT

MEMCPY 3: Inputs

VAR_INPUT
    destAddr : PVOID;
    srcAddr  : PVOID;
    n        : UDINT;
END_VAR

Name

Type

Description

destAddr

PVOID

Start address of the destination memory area.

srcAddr

PVOID

Start address of the source memory area.

n

UDINT

Number of bytes to be copied.

The function copies n bytes from the memory area with the start address srcAddr to the memory area with the start address destAddr.

Return parameter

Meaning

0

Incorrect parameter values. destAddr == 0 or srcAddr == 0 or n == 0

> 0

If successful, the number of bytes copied (n).

Example of a call in FBD:

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

MEMCPY 4:

In the example, 4 bytes are copied from Buffer2 to Buffer1.

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)