MOULDLKnowledge BaseElectrical Knowledge Base3D Model DownloadsMembership
中文版Model Store »
Knowledge Base › Electrical Knowledge Base › What are the ways to move data in blocks on an S7-1200?
HomeModels
Table of contents

On this page

PLC & Programming (100 articles)

Quick Reference

  • PLC & Programming
  • Electrical & Electronic Basics (monthly)(每月更新中)
  • Electrical Control & Drawings (monthly)(每月更新中)
  • Drives & Actuators (monthly)(每月更新中)
  • Sensors & Detection (monthly)(每月更新中)
  • Industrial Communication & Networks (monthly)(每月更新中)
  • HMI & Host Systems (monthly)(每月更新中)
  • Industrial Robots & Motion Control (monthly)(每月更新中)
  • Mechatronic System Integration (monthly)(每月更新中)
  • Fault Diagnosis & Standards (monthly)(每月更新中)

What are the ways to move data in blocks on an S7-1200?

Moving a block of data from one place to another on an S7-1200 can be done in more than one way. Pick the wrong one and the code becomes either long-winded or liable to fail at runtime when a length changes. The sections below set out the common block-move methods by data shape and scenario, with the basis for choosing between them.

1. MOVE, MOVE_BLK and MOVE_BLK_VARIANT

Use MOVE for a single value, MOVE_BLK for a fixed-length array, and MOVE_BLK_VARIANT when the length or the source/destination type is only known at runtime, together with a VARIANT and an array index. First decide whether the data is "one value" or "a stretch", then whether the length changes at runtime.

2. FILL and block initialisation

FILL fills an array or a memory area with a single value, which suits clearing to zero, setting defaults and writing one pattern into a whole stretch. It works in the opposite direction to MOVE: MOVE brings data across, FILL spreads one value out. For initialising an array it is far clearer than assigning element by element, and harder to leave a gap in.

3. Compatible replacements for BLKMOV

On an S7-1200, the classic BLKMOV (SFC20) is not directly available and is normally replaced by MOVE_BLK or MOVE_BLK_VARIANT. Programs ported from S7-300/400 have to be rewritten to these two instructions, and you must watch the parameter order and the way overlapping source and destination are handled, otherwise the move may not match the original behaviour.

4. Pointer and area copying

When an area has to be copied by variable address, use PEEK/POKE to access it byte by byte, word by word or double word by double word, or use a VARIANT with the array start index and length. This is flexible, but the boundaries are yours to work out; running past them reads unrelated data or raises an error, so validate the index and length first.

5. Reading and writing blocks over communication

If a batch of data is exchanged with a remote station or a VFD, reading and writing several records in one communication call is far more efficient than moving each one. Watch the length of each record and the response time of the station, though: if a batch is too large it may exceed the time available in one scan and time the communication out.

6. Block-move methods and their use cases at a glance

MethodData shapeUse caseNote
MOVESingle valueParameter passing, setting a valueNo type conversion
MOVE_BLKFixed-length arrayBlock move of a known lengthElement type must match
MOVE_BLK_VARIANTDynamic-length arrayLength changes at runtimeNeeds a VARIANT and index
FILLWhole stretch, one valueClearing, initialisingFills one value only
PEEK/POKEAccess by addressNon-structured area accessCheck boundaries yourself
VARIANT plus indexType not fixedInside a generic subroutineTest the type before calling
Communication readRemote station dataDistributed I/O, VFDsLimit the batch size
Whole data block copyDB to DBRecipes, parameter backupWatch optimised block access
Loop element by elementSmall blocksEvery element is processedKeep the loop count under control

7. Notes

To choose a block-move method, ask three questions first: how much is moved at once, does the length change, and must every element be processed. Once answered, the method is almost settled. Fixed length means MOVE_BLK, variable length means MOVE_BLK_VARIANT, and per-element work means an honest loop.

8. References

Instruction semantics and the definitions of arrays and data types follow GB/T 15969.3, Programmable controllers, Part 3: Programming languages (equivalent to IEC 61131-3). The communication-related device descriptions follow GB/T 25105 (PROFINET, equivalent to IEC 61158). The exact instruction names and availability depend on the manual of the CPU version in use.

9. Points to watch

⚠️ Three common traps:
1. MOVE_BLK with mismatched source and destination lengths, moving too many or too few elements and leaving stale data at the tail of the array that nobody notices;
2. Moving a large array element by element in a loop, so moving too much at once lengthens the scan cycle and triggers a scan overrun;
3. Accessing an optimised-access data block by absolute address with PEEK/POKE, where the addresses do not line up and everything read is wrong.

Confirm that source and destination lengths match before a block move, and verify key elements afterwards. Debug large cross-device reads and writes during a shutdown or a light-load period so real-time tasks are not affected.

Related reading

Related 3D models: Ready to build it? Download free 3D models & CAD drawings at MOULDL »
MOULDL · Electrical Knowledge Base · free self-study reference for electrical & automation engineers, 3D CAD models at MOULDL