Copy File (COP), Synchronous Copy File (CPS)
The COP and CPS instructions copy the value(s) in the Source to the values in the Dest. The Source remains unchanged.
Available Languages
Ladder Diagram
FactoryTalk Design Studio
DSL - Ladder DiagramCOP(Source,Dest,Length);
CPS(Source,Dest,Length);
Operands
IMPORTANT:
Unexpected operation may occur if:
- Output tag operands are overwritten.
- Members of a structure operand are overwritten.
- Except when specified, structure operands are shared by multiple instructions.
Ladder Diagram
Operand | Data Type | Format | Description |
---|---|---|---|
Source | SINT INT DINT LINT USINT UINT UDINT ULINT REAL LREAL String type structure | tag | Initial element to copy |
Dest | SINT INT DINT LINT USINT UINT UDINT ULINT REAL LREAL String type structure | tag | Initial element to be overwritten by the Source |
Length | SINT INT DINT | immediate tag | Number of Destination elements to copy |
Affects Math Status Flags
No
Major/Minor Faults
None specific to this instruction. See Index through arrays for array-indexing faults.
Execution
Ladder Diagram
Condition/State | Action Taken |
---|---|
Prescan | N/A |
Rung-condition-in is false | Set Rung-condition-out to Rung-condition-in. |
Rung-condition-in is true | Set Rung-condition-out to Rung-condition-in. The instruction copies the data. |
Postscan | N/A |
Examples
Example 1
Copy an array.
When enabled, the COP instruction copies 40 bytes from array_4 to array_5.
array_4 is a DINT (4 bytes per element) and contains 10 elements (total size = 40 bytes)
array_5 is a DINT (4 bytes per element) and contains 10 elements (total size = 40 bytes).
The Length says 10 destination elements should be copied so 40 bytes are copied.
Ladder Diagram
Example 2
Copy a structure.
When enabled, the COP instruction copies the structure timer_1 into element 5 of array_timer.
timer_1 is a TIMER (total size = 12 bytes).
array_timer is a TIMER (12 bytes per element) and contains 10 elements (total size = 120 bytes).
The Length says 1 destination elements so 12 bytes are copied.
Ladder Diagram
Example 3
Copy array data while preventing the data from being changed until the copy is complete.
The project_data array (100 elements) stores a variety of values that change at different times in the application. To send a complete image of project_data at one instance in time to another controller, the CPS instruction copies project_data to produced_array. While the CPS instruction copies the data, no I/O updates or other tasks can change the data. The produced_array tag produces the data on a ControlNet network for consumption by other controllers.
project_data is a DINT (4 bytes per element) and contains 100 elements (total size = 400 bytes)
produced_array is a DINT (4 bytes per element) and contains 100 elements (total size = 400 bytes).
The Length says 100 destination elements so 400 bytes are copied.
Ladder Diagram
Example 4
Copy data to a produced tag while preventing the data from being sent until the copy is complete.
Local:0:I.Data stores the input data for the DeviceNet network that is connected to the 1756-DNB module in slot 0. To synchronize the inputs with the application, the CPS instruction copies the input data to input_buffer. While the CPS instruction copies the data, no I/O updates can change the data. As the application executes, it uses for its inputs the input data in input_buffer.
Local:O:I.Data is a DINT (4 bytes per element) and contains 2 elements (total size = 8 bytes)
input_buffer is a DINT (4 bytes per element) and contains 20 elements (total size = 80 bytes).
The Length says 20 destination elements should be copied (4 X 20 = 80 bytes). However the source can only provide 8 bytes so 8 bytes are copied.
Ladder Diagram
Example 5
Initialize an array structure, initialize the first element and the use COP to replicate it to the rest of the array.
This example initializes an array or timer structures. When enabled, the MOV instructions initialize the .PRE and .ACC values of the first array_timer element. When enabled, the COP instruction copies a contiguous block of bytes, starting at array_timer[0]. The length is nine timer structures.
array_timer is a TIMER (12 bytes per element) and contains 15 elements (total size = 180 bytes)
The Length says 10 destination elements so 120 bytes are copied.
Ladder Diagram
Example 6
Copy different sized arrays.
When enabled, the COP instruction copies bytes from SINT array_6 to DNT array_7.
array_6 is a SINT (1 byte per element) and contains 5 elements (total size = 5 bytes)
array_7 is a DINT (4 bytes per element) and contains 10 elements (total size = 40 bytes).
The Length says 20 destination elements should be copied (4 X 20 = 80 bytes). However the dest can only accept 40 bytes and the source can only provide 5 bytes so 5 bytes are copied.
Ladder Diagram
Provide Feedback