Example user functions, E example user functions – Delta RMC151 User Manual
Page 387
5 Programming
MyOutputVar
: REAL :=4;
MyArray
:
Array
[0..3]
OF
REAL := [10, 10, 0];
END_VAR
VAR
MyVar
: REAL := 100;
YourVar
:
Array
[0..9]
OF
DINT;
END_VAR
Declaring Arrays
Array bounds are specified in brackets [], with two intermediate periods (..). The array
bounds can be any integer value, including negative values. For most applications, the
lower bound is zero. The maximum length of an array in a user function is 32 elements.
Parentheses can be used a repetition factor when assigning an initial value. The value
preceding the parentheses specifies the number of repetitions. For example, [4(0)] is
equivalent to [0,0,0,0], and [1,3(99),1] is equivalent to [1,99,99,99,1].
Example
This declaration creates an output array of length 5, with initial values of [-1,1,0,0,0].
VAR_OUTPUT
MyArray
:
Array
[0..4]
OF
REAL := [-1,1, 3(0)];
END_VAR
5.14.3.3. Example User Functions
The text from the following example user functions can be copied and pasted into the User
Example 1
Converts inches to millimeters.
Usage
MyPos
:=
inch2mm
(
_Axis[0].ActPos
);
Declaration
(*
Converts inches to millimeters.
*)
FUNCTION
inch2mm
: REAL
VAR_INPUT
Inches
: REAL;
END_VAR
inch2mm
:=
Inches
* 25.4;
END_FUNCTION
Example 2
Returns the average of 4 values.
Usage
deltamotion.com
367