How do you copy memory areas and structured data in STEP 7 (TIA Portal)?
The following examples show how to copy the contents of a source memory area into a target memory area. You can also copy structured data with the "MOVE" instruction. Information about this is available in Entry ID 78678760.
Example 1: Copy contents of array variables from one data block to another
If you have to copy data areas from one data block to another, you create the data blocks with variables of the "Array" data type. Using the Array variables and the "MOVE_BLK" instruction, for example, you can move parts or the complete memory area from one data block to another. With the "COUNT" parameter you define the number of the elements from which you wish to move data from the source area to the target area.
Fig. 1 shows the call and parameterization of the "MOVE_BLK" instruction with two DB variables.
- The formal parameter "IN" is parameterized with the array element of the DB variable "Block.send".
- The formal parameter "OUT" is parameterized with the array element of the DB variable "Data.receive".
- The actual parameter "Control.count" provides with the value "5" the number of copy repeats.
In this way the data is copied from "Block.send...Block.send" into the memory area "Data.receive...Data.receive".
Example 2: Copy structured data from one data block to another each with a different PLC data type
The "Copy" function copies from the "Source" data block the contents of the structured variable "variable" (PLC data type: "Speed") into the structured variable "value" (PLC data type: "Drive") of the "Target" data block. The two memory areas do not have the same PLC data type.
Fig. 4 shows the program in the "Copy" function with the call and parameterization of the two instructions "Serialize" and "Deserialize". The "Serialize" instruction converts a PLC data type into a sequential display type and stores the structured data in the buffer memory "tempStore". In the second network the "Deserialize" instruction converts the sequential data from the buffer memory "tempStore" back into a PLC data type.
Note on the two instructions "Serialize" and "Deserialize"
To use the two instructions "Serialize" and "Deserialize" in blocks with optimized block access, you need the firmware V4.0 or higher for the S7-1200 and the firmware V2.0 or higher for the S7-1500. Furthermore, the project engineering of the block version V2.0 and higher is required for the two instructions "Serialize" and "Deserialize" if you also program the instruction "MOVE" as in the example described above.
If there are any deviations, we recommend one of the following two remedies:
In the project tree you right-click the block.
In the pop-up menu you select "Properties".
Switch to the "Attributes" tab.
Disable the option "Optimized block access".
Configure an FB instead of an FC.
Save the array ("tempStore") as a static variable.
For the array ("tempStore"), in the "Retain" column you enable the function "Set in IDB ".
In the example below (Fig. 5), the input areas (IB0, IB1) and output areas (data block "DBrange") are defined with the PLC data type "DataRange". This structured grouping of the input and output addresses in a higher-level PCL variable makes it easier to program your program.
Using this method you can also copy input areas larger than 64 bytes into a data block. You need firmware V4.1 or higher for the S7-1200 CPU modules.
The above-mentioned instructions are available in the "Basic Instructions" task card:
- Either in the "Move" folder;
- Or you drag-and-drop the "Empty box" from the "General" folder into your network. Then move the cursor on the yellow triangle in the empty box until the symbol for opening the drop-down list appears. In the drop-down list box you select the command.
More information is also available in the STEP 7 (TIA Portal) Online Help.
Information on the topic of "Pointer addressing" is available in Entry ID 42603286.
The screens in this FAQ response were created with STEP 7 (TIA Portal) V13 SP1.