FILL Function

FILL(to, value, length)

Sets length registers starting at the to address to the specified value (value). Typically used to fill an array with values. A maximum of 32 registers can be filled.

Parameters

to(Address)

The address to begin filling at. Typically an array element.

value(REAL, DINT, or DWORD)

The value to set the elements to.

length(DINT)

The number of elements to fill. A maximum of 32 registers can be filled.

Return Value

The FILL function does not return a value.

Remarks

The FILL function is typically used to fill an array with the same value, for example, setting all array items to zero. The to location can be any location in the Variable Table or an element in a local array.

If the to location is a local array or an element of a local array, then if length exceeds the end of the local array, the task will fault, an error will be logged in the Event Log and the user program running on the task will stop.

If the to location is in the Variable Table, length values will be written, even if it exceeds the end of an array. If length exceeds the end of the Variable Table, the task will fault, an error will be logged in the Event Log and the user program running on the task will stop.

A maximum of 32 registers can be filled. To fill more than 32 registers, use multiple FILL statements.

Examples

Set each of the first 4 elements in an array to one (1):

FILL(MyArray, 1, 4);

 

Set all elements in an array to zeroes:

FILL(MyArray, 0, LENGTH(MyArray));

 

Set each of elements 5 to 9 in an array to 100:

FILL(MyArray[5], 100, 5);

 

Fill an array of unknown size:

This example assumes the following variable have been declared in the Variable Table:

 

This example is limited to arrays of length 128. To increase the max size, simply duplicate the last 4 lines in the expression as many times as necessary.

Caution: It is possible to exceed the allotted execution time for the step. However, the Verify will catch this prevent downloading to the RMC. If you do exceed the loop time, you will need to spread the code over several steps, in which case the variable i needs to be defined in the Variable Table, not locally in the step.

 

Copyable Text for the Expression Above:

FILL(MyArray,FillValue,MIN(LENGTH(MyArray),32));

i:=32;

IF LENGTH(MyArray) > i THEN

FILL(MyArray[i],FillValue,MIN(LENGTH(MyArray)-i,32));

END_IF;

i:=i+32;

IF LENGTH(MyArray) > i THEN

FILL(MyArray[i],FillValue,MIN(LENGTH(MyArray)-i,32));

END_IF;

i:=i+32;

IF LENGTH(MyArray) > i THEN

FILL(MyArray[i],FillValue,MIN(LENGTH(MyArray)-i,32));

END_IF;

 

 

See Also

Functions Overview | Arrays | LENGTH Function


Send comments on this topic.

Copyright © 2024 Delta Computer Systems, Inc. dba Delta Motion