7.11.5 SERIALIZE
Function
The serialization instruction converts multiple PLC data types (UDT), STRUCT or ARRAY of (data type) into sequential identifiers without losing structural parts
warning
- The serialization instruction temporarily saves multiple structured data items of the user program into a serialized array (the data type must be ARRAY[] of BYTE or ARRAY[] of CHAR) and sends it to other CPUs
- The maximum capacity of the serialized array is 64KB. It is recommended to define the lower limit of ARRAY as "0" because the subscript in ARRAY corresponds to the POS parameter value. For example, ARRAY[]= POS0. The explanations and examples below are based on this formula. The operand at parameter POS contains information about the number of bytes occupied by the converted data. After the instruction is executed, POS=POS+the number of bytes occupied by the data
LD graphics
Parameter description
| Interface variable | Declaration | Data type | Description |
|---|---|---|---|
| SOURCE_VAR | VAR_Input | ANY_TYPE | Variable to be serialized |
| POS | VAR_IN_OUT | DINT | The variable to be serialized is stored in the relative subscript position of the array calculated by the POS parameter. The POS parameter will be calculated starting from 0, corresponding to the starting index position of the array. After the instruction is executed, POS = POS + the number of bytes occupied by the data |
| DEST_ARRAY | VAR_IN_OUT | ARRAY of BYTE or ARRAY of CHAR | The ARRAY variable name used to store the generated data stream |
| Function name | Return value | INT | Error message |
Return value error code
| Error code (hexadecimal code) | Description |
|---|---|
| 0000 | No error |
| 80B0 | The storage areas of parameters SOURCE_VAR and DEST_ARRAY overlap |
| 8150 | The data type in the SOURCE_VAR parameter contains a ZERO pointer |
| 8151 | Invalid reference in SOURCE_VAR parameter |
| 8236 | Illegal variable at DEST_ARRAY parameter |
| 8250 | NULL pointer passed at DEST_ARRAY parameter |
| 8251 | Invalid reference in DEST_ARRAY parameter |
| 8253 | The variable at parameter DEST_ARRAY does not provide enough space to contain the contents of the variable at parameter SOURCE_VAR. Due to the input value of the variable at the POS parameter, the available storage space will be reduced. The input value at the POS parameter determines the starting position in the variable at the DEST_ARRAY parameter |
| 8254 | The data type in the DEST_ARRAY parameter is invalid |
| 8382 | The value of the POS parameter exceeds the limit of the array |
Example
-
LD sample pictures are shown below:

-
ST sample code is as follows:
ss:=SERIALIZE(SOURCE_VAR:=sarr[13],POS:=darr[0],DEST_ARRAY:=dd);