WriteToArrayDB: Write to ARRAY data block (S7-1500) - STEP 7

FBD (S7-1200, S7-1500)

ft:publication_title
FBD (S7-1200, S7-1500)
Product
STEP 7
Version
V20
Publication date
11/2024
Language
en-US
WriteToArrayDB: Write to ARRAY data block

Description

The instruction "Write to ARRAY data block" is used to write the element to which the index references to a data block of the ARRAY DB block type.

An ARRAY data block is a data block that consists of exactly one ARRAY of <Data type>. The elements of the ARRAY can be of PLC data type or any other elementary data type. Counting of the ARRAY always begins with the low limit "0".

Enable output ENO returns the signal state FALSE if one of the following conditions applies:

  • Enable input EN returns the signal state FALSE.

  • If an error occurs during the execution of the instruction.

Parameters

The following table shows the parameters of the "Write to ARRAY data block" instruction:

Parameter

Declaration

Data type

Memory area

Description

EN

Input

BOOL

I, Q, M, D, L or constant

Enable input

ENO

Output

BOOL

I, Q, M, D, L

Enable output

DB

Input

DB_ANY

I, Q, M, D, L

Data block to which data is written

INDEX

Input

DINT

I, Q, M, D, L, P or constant

Element in the DB to which data is written. The specification can be a constant, a global tag or an indexed value.

VALUE

Input

VARIANT

L (The declaration is possible in the "Input", "InOut" and "Temp" sections of the block interface.)

Value to be written

RET_VAL

Output

INT

I, Q, M, D, L, P

Error information:

If an error occurs during execution of the instruction, an error code is output at the RET_VAL parameter.

You can find additional information on valid data types under "See also".

Parameter RET_VAL

The following table shows the meaning of the values of the RET_VAL parameter:

Error code*

(W#16#...)

Explanation

0000

No error

80B4

The element data type stored in the ARRAY data block does not match the element data type transferred in the VARIANT.

80B5

The copying was interrupted.

8132

The data block does not exist, is too short, or is located in load memory.

8134

The data block is write protected.

8135

The data block is not an ARRAY data block.

8154

The data block has the incorrect data type.

8282

The value at the INDEX parameter is outside the limits of the ARRAY.

8350

The data type VARIANT at parameter VALUE provides the value "0".

8352

Code generation error

8353

There are two possible causes of the error:

  • The size of the VALUE parameter does not match the element length in the ARRAY data block.

  • The two tags are not in a memory area with optimized access. For additional information on the memory area access types, refer to: Basics of block access

* The error codes can be displayed as integer or hexadecimal values in the program editor. You can find information on switching the display formats under "See also".

Example

The following example shows how the instruction works:

The following table shows how the instruction works using specific operand values:

Parameters

Operand

Value

DB

ArrayDB

The "ArrayDB" operand is an ARRAY DB of the data type Array [0 to 10] of INT.

INDEX

2

2nd element of the "ArrayDB"

VALUE

SourceField

The "SourceField" operand is a global tag of the data type INT.

If the "TagIn1" operand returns signal state "1", the instruction is executed. The value of the "SourceField" operand is written to the 2nd element of the ARRAY DB. If the instruction is executed without errors, the enable output ENO has the signal state TRUE and the "TagOut" output is set.