laitimes

Siemens Portal (TIA Portal) Will you use variable-length arrays?

author:iHM industrial control

Preamble

Do you encounter the following problems every time, for example, create FB/FC function blocks of different lengths to set different lengths for array operations of different lengths, so as to ensure that the input array is consistent with the pin parameters of the function block, and the size and length of the array are the same. By changing the length of the array, the workload can be greatly reduced.

Siemens Portal (TIA Portal) Will you use variable-length arrays?

1. Comparison between mutable arrays and immutable arrays

1. Traditional array_function block variables

The input/output variables of the function block must be the same as the DB block variables.

Function block 1 variables:

Siemens Portal (TIA Portal) Will you use variable-length arrays?

Function block 2 variables:

Siemens Portal (TIA Portal) Will you use variable-length arrays?

DB block variables:

Siemens Portal (TIA Portal) Will you use variable-length arrays?

For traditional immutable array operations and arrays of different lengths, independent FB/FC function blocks must be created.

2. Variable-length array_ function block variable

The input/output variables of the function block do not need to be the same as those of the DB data block, and the length of the DB data block can be specified

Function block 1/2 variables:

Siemens Portal (TIA Portal) Will you use variable-length arrays?

DB block variables:

Siemens Portal (TIA Portal) Will you use variable-length arrays?

Variable array operation, arrays of different lengths, no need to create a new independent FB/FC function block.

2. Explanation of variable arrays

1. Create a new FC block

Siemens Portal (TIA Portal) Will you use variable-length arrays?

2. The FC function block inserts the following variables

Siemens Portal (TIA Portal) Will you use variable-length arrays?

3.FC function block inserts the following programs

Siemens Portal (TIA Portal) Will you use variable-length arrays?
//获取数组下限
#数组下限 := LOWER_BOUND(ARR := #输入数组, DIM := 1);
//获取数组上限
#数组上限 := UPPER_BOUND(ARR := #输入数组, DIM := 1);
//赋值前清零
#输出和_Temp := 0;
//数组求和
FOR #Temp_1 := #数组下限 TO #数组上限 BY 1 DO
    // Statement section FOR
    #输出和_Temp += #输入数组[#Temp_1];
END_FOR;
//数组求和值中转
#输出和 := #输出和_Temp;           

4. Create a new DB block

Siemens Portal (TIA Portal) Will you use variable-length arrays?

Insert the following variables 5.DB the data block

Siemens Portal (TIA Portal) Will you use variable-length arrays?

6. Insert the variable array FC function block twice into the OB1 function block

Siemens Portal (TIA Portal) Will you use variable-length arrays?

3. Program demonstration

Siemens Portal (TIA Portal) Will you use variable-length arrays?

Extended knowledge: PLC-Recorder professional data acquisition and analysis software can collect data in Siemens PLC at high speed, and the speed is also 20ms, 8ms, and 2ms different cycles.

Siemens Portal (TIA Portal) Will you use variable-length arrays?

In the later stage, we will dedicate more PLC engineering tips from time to time. Add attention and don't get lost.