~~NOCACHE~~
====== LamaPLC: Simatic S7 SCL commands: Move / memory operations ======
==== BLKMOV ====
You can use the "Move block" instruction to move the content of a memory area (source area) to another memory area (destination area). The move operation takes place in the direction of ascending addresses. You use [[:simatic:typedef#any|ANY]] pointer to define the source and destination area.
|< 100% 15% 15% 15%>|
|[[:simatic:tia_knowhow#fb|_FB_]] **Retval :=** **BLKMOV (**| |[[:simatic:typedef#int|INT]]|If there is no error, **Retval** is 0. Otherwise: a summary table of the "retVal" codes can be found here: [[:simatic:errorcodes|Simatic S7 error- and statuscodes]] |
| |**SRCBLK :=** [[:simatic:typedef#variant|VARIANT]] **,**|input|**Source block:** this block will be copied. The feature does not scan data types, only the size of the area should match the size of the target. |
| |**DSTBLK =>** [[:simatic:typedef#variant|VARIANT]] **,** |output|**Destination block:** the first block is copied here (overwrites everything).|
|**);**||||
It is important to disable optimization in the DBs used by BLKMOV! \\ Check: [[:simatic:tia_knowhow#db_opt|Switch off "optimization" attribute of DBs]]
== BLKMOV call example 2 ==
[[:simatic:tia_knowhow#fc|_FB_]] RetVal := **BLKMOV** (SRCBLK := P#M12.0 BYTE 10, DSTBLK => P#DB1.DBX0.0 BYTE 10);
== BLKMOV call example 1 ==
The sample program reads the local time in [[:simatic:typedef#dt|DT]] and splits the variable into [[:simatic:typedef#byte|BYTE]]s.
The example program below can be downloaded here: {{ :simatic:blkmov_example_1.scl |blkmov_example_1.scl}}. \\
The code:
// author OB121 / Sandor Vamos
// ob121.com; 2022.04.11.
// BLKMOV example: read local time and convert byte array
//
// More information:
// https://www.ob121.com/doku.php?id=de:s7:scl_reference#blkmov
// read local time to date_and_time
#state := RD_LOC_T("BLKMOV_DB".datum_dt);
// move date_and_time to byte array
#state := BLKMOV
(SRCBLK := P#db4.dbx0.0 BYTE 8,
DSTBLK => P#db4.dbx8.0 BYTE 8,
ENO => ENO);
The DB:
{{:simatic:blkmov_example_1.png|BLKMOV}}
[[simatic:scl_commands|>> Back to LamaPLC main menu (SCL commands)]]
==== MOVE_BLK ====
Copy arrays in memory blocks.
[[:simatic:tia_knowhow#fc|_FC_]] **MOVE_BLK**
(IN:= source block;
OUT:= target block;
COUNT:= number of elements;
ENO => operation enable
);
The MOVE_BLK command can be used to move a memory area (IN) to another memory area (OUT) by a specified length (COUNT).
The command does not implicitly monitor for irregular addresses, so it is worth monitoring the (ENO) output.
The operation can be performed with the ARRAY types (in which case COUNT determines the number of items). In case of over-addressing, ENO indicates.
For pointer memory area move check: [[:simatic:scl_commands_move#blkmov|BLKMOV]].
Example of moving ARRAY with MOVE_BLK (ENO OK):
{{:simatic:move_blk_example_1.png|MOVE_BLK}}
Example of moving ARRAY with MOVE_BLK (ENO error!): \\
I overrated the source area with COUNT: = 3.
{{:simatic:move_blk_example_2.png|MOVE_BLK}}
The example MOVE_BLK program below can be downloaded here: {{ :simatic:move_blk_example.scl |move_blk_example.scl}}.
[[simatic:scl_commands|>> Back to LamaPLC main menu (SCL commands)]]
==== FILL_BLK / UFILL_BLK ====
{{anchor:fill_blk}}
{{anchor:ufill_blk}}
Fill a memory area (ARRAY) (target range) with a value. \\
\\
**UFILL_BLK:** In the case of the UFILL_BLK instruction, the difference is that the operation cannot be interrupted, it must be executed in the same call-cycle. \\
\\
The instruction can only be executed if the source range and the target range have the same data type. \\
\\
|< 100% 15% 15% 15%>|
|[[:simatic:tia_knowhow#fb|_FB_]] **FILL_BLK (**| | |
| |**IN :=** 5 **,**|**input:** Binary numbers, integers, floating-point numbers, timers, TOD, LTOD, DATE, CHAR, WCHAR|fill a memory area (target range) with the value of the **IN** input.|
| |**COUNT := ** 4 **,** |**input:** USINT, UINT, UDINT, ULINT|The number of repeated copy operations is specified with the **COUNT** parameter|
| |**OUT => ** "db_prog".intArray[2] |**output:**Binary numbers, integers, floating-point numbers, timers, TOD, LTOD, DATE, CHAR, WCHAR|The target range is filled beginning with the address specified at the **OUT** output. When the instruction is executed, the value at the input **IN** is moved to the target range as often as specified by the value of the **COUNT** parameter.|
|**);**||||
|< 100% >|
|{{:simatic:fill_blk_ex1.png|FILL_BLK example 1}}|{{:simatic:fill_blk_ex2.png|FILL_BLK example 2}}|
|call FILL_BLK: The program had to fill only 4 array elements with "5".|the result in DB|
[[simatic:scl_commands|>> Back to LamaPLC main menu (SCL commands)]]
\\
\\
\\
\\
{{tag>Simatic SCL TIA blkmov move_blk memory move}}
\\
\\
This page has been accessed for: Today: {{counter|today}}, Until now: {{counter|total}}