Skip to main content

7.11.1 COPY

Function

COPY is called copying array elements and can move data in a storage area (original range) to another storage area (target range). Use COUNT to specify the number of elements that will be moved into the target range. The width of the element to be moved is determined by the width of the first element in the source area

LD graphics

alt text

Parameter description

Interface variableDeclarationData typeDescription
COUNTVar_InputUDINTNumber of elements
SOURCEvar_IN_OUTAny_elementary without STRINGStarting element of the array to be copied
DESTvar_IN_OUTAny_elementary without STRINGThe first element in the target range to which the contents of the original range are to be copied
Function nameReturn valueBOOLReturns the instruction status, TRUE means the instruction is executed correctly, FALSE means the instruction execution error

Corresponding syntax

  • COUNT: Number of copied elements
  • SOURCE: source storage area
  • DEST: target storage area

Example

  • LD sample pictures are shown below: alt text

  • ST example is shown in the following code:

r:=COPY(COUNT:=1,SOURCE:=sarr[0],DEST:=darr[5]);
info
  • The difference between COPY_UB and COPY is that the COPY_UB function can prevent data from being changed during the copy operation. That is, during the execution of the COPY_UB function, it cannot be interrupted by other high-priority user TASKs. There is no limit to COPY
  • When the function is called, this instruction can only be executed when the data types of the source variable (SOURCE) and the target variable (DEST) are exactly the same (implicit conversion is not supported), and the actual parameters of SOURCE and DEST can only be array member variables (otherwise Compilation error). COUNT represents the number of array members to be copied
  • If COUNT exceeds the number of elements in the source array based on the starting element of the source array (SOURCE), or COUNT exceeds the number of elements in the target array based on the starting element of the target array (DEST), the return value (function name) will be reset to FALSE, and data is not copied