BLOG / PLC

Arrays and Indirect Addressing on S7-1500: Modern Patterns, No Pointers Required

20 Ekim 2022 S7-1500ArraysSCLProgramming

S7 folklore is full of ANY-pointer rituals from the S7-300 era. On S7-1500 with optimized blocks, nearly all of it collapses into two civilized concepts: arrays and VARIANT.

The modern toolkit

Array of UDT in a DB is the workhorse: sixteen stations = Array[1..16] of typeStation; code touches station[#i] symbolically and one FOR loop in SCL services all sixteen. Ladder callers can pass #i from HMI selection or sequence position — indexed access is native, readable, and diff-able.

Array DBs and the MOVE_BLK family cover bulk operations (shift registers of product data along a line, batch copies) without a pointer in sight. VARIANT plus instructions like VariantGet handle the genuinely generic cases — one FB serving multiple UDT versions — while staying type-checked at the edges.

The honesty tax: index math must be guarded. Every computed index gets a limit check (or the block traps in OB121 eventually, on a Friday). Our pattern: indices validated at the single entry point, plausibility alarms rather than silent clamping, and array bounds declared via constants so growth is a one-line change plus recompile — not a hunt.

What we still refuse

Overlapping AT views to reinterpret memory, byte-offset arithmetic into optimized DBs (it does not even work), and “clever” generic blocks whose behavior depends on runtime type sniffing beyond what VARIANT declares. Generic is good; unreadable is not.

FAQ

Performance of FOR loops over big arrays? Fast on 1500s, but budget interrupt OBs carefully — bulk work belongs in OB1-class cycles, chunked if needed.

Is PEEK/POKE ever justified? At protocol boundaries with genuinely raw buffers, rarely — isolated in one documented parsing block, never as a general style.


Zone Otomasyon refactors pointer archaeology into typed arrays during code modernization. Cleaner code, fewer ghosts.