Deserialize: Deserialize (S7-1200, 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
Deserialize: Deserialize

Description

You can use the "Deserialize" instruction to convert back the sequential representation of a PLC data type (UDT), STRUCT or ARRAY of <data type> and to fill its entire contents. You can use the instruction to convert multiple serialized data areas back to their deserialized representation form.

If you only want to convert back a single sequential representation of a PLC data type (UDT), STRUCT or ARRAY of <data type>, you can also directly use the instruction "TRCV: Receive data via communication connection".

The memory area "SRC_ARRAY" in which the sequential representation of a PLC data type (UDT), STRUCT or ARRAY of <data type> is located must have the ARRAY of BYTE or ARRAY of CHAR data type and be declared with standard access in version 1.0. The capacity of the standard memory area is 64 KB. Make sure that there is enough memory space prior to the conversion. Optimized memory areas are also permitted as of version 2.0.

When the "SRC_ARRAY" memory area is filled using the "Serialize" instruction, any required filling bytes are automatically inserted. If you fill the "SRC_ARRAY" memory area by other means, you need to insert any required filling bytes yourself. Filling bytes are ignored during deserialization, regardless of whether "SRC_ARRAY" is in an optimized or a standard memory area.

It is recommended to define the low limit of the ARRAY with "0", because then the index within ARRAY corresponds to the value of the POS parameter, e.g. ARRAY[0] = POS 0. The description and example below have been formed based on this.

Size of the memory area

The alignment rules mean that simple structures in the optimized memory area do not contain filling bytes. This results in a structure in the optimized memory area being smaller than in the standard memory area. ARRAYs of structures and nested structures contain filling bytes. There is no general rule as to the memory area in which a composed structure requires more space.

Applies to CPUs of the S7-1500 series:

For a block with the block property "Optimized block access", the BOOL has a length of 1 byte. A structure that consists largely of the data type BOOL can therefore be larger in the optimized memory area than in the standard memory area. Composed structures with a low proportion of BOOL data types are smaller in the optimized memory area than in the standard memory area.

Note

Serialize several structures on a CPU S7-1200

If you want to serialize several structures in a buffer on a CPU S7-1200 and want to communicate with them (for example, with a control system or a CPU S7-1500), then you must check whether the return value (index at the POS parameter) is even. If this is not the case, then you must increment the return value by 1 before serializing the second structure because the first structure is not filled with a filling byte. 

Example:

Structure consisting of 1 DWORD and 1 BYTE

The start address for the next serialized structure in the buffer is 5. Add +1 so that the start address is even.

Optimized memory area

To deserialize larger structures, you can declare the memory area for sequential representation with optimized access for a CPU of the S7-1200 series as of firmware version >= 4.2, and for a CPU of the S7-1500 series as of firmware version >= 2.0. The content of the sequential representation remains unchanged, as for a standard memory area. Only symbolic access to the bytes in the ARRAY is possible.

Parameters

The following table shows the parameters of the "Deserialize" instruction:

Parameters

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

SRC_ARRAY

Input

ARRAY[*] of BYTE 1)

or

ARRAY of CHAR

I, Q, D, block interface of an FB (the sections Input, Output, Static and Temp are possible).

No I/O data

ARRAY of BYTE or ARRAY of CHAR in which the data stream which is to be deserialized is saved.

S7-1500:

For optimum performance, do not provide the parameter with a VARIANT pointer.

DEST_VARIABLE

InOut

all data types

I, Q, D, block interface of an FB,

No I/O data

Tag to which the deserialized data is to be written.

S7-1500:

For optimum performance, do not provide the parameter with a VARIANT pointer.

POS

InOut

DINT

I, Q, M, D, L

The operand at the POS parameter stores the index of the first byte based on the number of bytes occupied by the converted customer data. The POS parameter is calculated zero-based.

RET_VAL

Output

INT

I, Q, M, D, L

Error information

1) Possible for a CPU of the S7-1200 series as of firmware version >= 4.2, and for a CPU of the S7-1500 series as of firmware version >= 2.0.

RET_VAL parameter

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

Error code*
(W#16#...)

Explanation

0000

No error

80B0

The memory areas for the SRC_ARRAY and DEST_VARIABLE parameters overlap.

8136

The tag at the SRC_ARRAY parameter is not in a block with standard access.

8150

The VARIANT data type at the SRC_ARRAY parameter contains a ZERO pointer.

8151

No valid reference at the SRC_ARRAY parameter

8153

There is not enough free memory available at the SRC_ARRAY parameter.

8154

Invalid data type at the SRC_ARRAY parameter

8250

A NULL pointer was transferred at parameter DEST_ARRAY.

8251

No valid reference at the DEST_VARIABLE parameter

8382

The value at the POS parameter is outside the limits of the array.

* 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".

Special features as of firmware version 4.2 (S7-1200) and 2.0 (S7-1500):

The following error code has a different meaning:

Error code*
(W#16#...)

Explanation

8136

Access to the memory area at the SRC_ARRAY parameter is invalid.

* 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".

Special features as of firmware version 2.8 (S7-1500):

To improve the performance of the "Deserialize" instruction (Version 2.1), do not provide the SRC_ARRAY and DEST_VARIABLE parameters with a VARIANT pointer but with a specific data type instead.

Note that the error response to the instruction changes as a result: In individual error scenarios, the CPU does not output any error codes but changes to STOP with an access error. To avoid this, use the local error handling with the instructions "GET_ERROR" and "GET_ERR_ID".

Special features as of firmware version 2.2 (S7-1200/S7-1500):

With the "Deserialize" instruction (version 2.2), it is no longer permissible to interconnect an element of a technology object (e.g. TO_SpeedAxis.Statusword) to input or output parameters (SRC_ARRAY/DEST_VARIABLE).

Special features as of firmware version 2.1 (S7-1200/S7-1500):

The optimized version of the "Deserialize" instruction (as of version V2.1) requires more work memory than its predecessor version due to the complexity of the processed data.

Example

The following table shows the declaration of the operands:

Operand

Data type

Declaration

DeliverPos

INT

In the "Input" section of the block interface of an FB or FC.

BufferPos

DINT

In the "Temp" section of the block interface of an FB or FC.

Error

INT

Label

STRING[4]

The following table shows the declarations of the PLC data types:

Name of the PLC data types

Name

Data type

Article

Number

DINT

Declaration

STRING

Colli

INT

Client

Title

INT

First name

STRING[10]

Surname

STRING[10]

The following table shows the declaration of the data blocks:

Name of the data blocks

Name

Data type

Target

Client

"Client" (PLC data type)

Article

Array[0..10] of "Article" (PLC data type)

Bill

Array[0..10] of INT

Buffer

Field

Array[0..294] of BYTE

The following example shows how the instruction works:

Network 1:

The "Move value" instruction moves the value "0" to the #BufferPos operand. The "Deserialize" instruction deserializes the sequential representation of the customer data from the "Buffer" tag and writes it to the "Target" tag. The #BufferPos operand stores the index of the first byte based on the number of bytes occupied by the converted customer data.

Network 2:

The "Deserialize" instruction deserializes the sequential representation of the separator sheet, which was stored in the sequential representation after the customer data, from the "Buffer" tag and writes the characters to the #Label operand. The characters are compared using comparison instructions "arti" and "Bill". If the comparison for "arti" = TRUE, these are article data that have been deserialized and written to the "Target" tag. If the comparison for "Bill" = TRUE, these are billing data that have been deserialized and written to the "Target" tag.