Delta RMC151 User Manual
Page 384
RMC70/150 and RMCTools User Manual
•
Input/Output
e. Click OK.
To adjust the order of the parameters, use the Up and Down
arrows. To
delete parameters, use the Delete
button.
6. Click OK.
7. The new function will be added to the User Functions list, and will appear in the editor.
Editing a User Function
User Function Description
The initial comment in the user function is the function description, enclosed by green
parentheses with an asterisk:
(* *)
. This description will appear when browsing the
functions in the Expression Editor.
Enter a description that describes what the function does. It is good practice to clearly
describe the parameters and return value. You do not need to describe the parameter
data types, as this is automatically displayed in the Expression Editor.
Function Name
The function name and return data type is defined by the keyword FUNCTION. To
change the function name or data type, change the text following the FUNCTION
keyword. The entire function must also end with the END_FUNCTION keyword.
For example, mm2inch is this function's name, which returns a value of type REAL:
FUNCTION
mm2inch
: REAL
Variable Declarations
Functions can have input variables, output variables, input/output variables, and local
variables. For details, see Declaring Variables in User Functions.
Editing the Function Body
The function body contains the code that the function executes when it is called. The code
in the function body must follow the same syntax as the code used in the Expression
(113) command. For details, see the assignment expressions topic. The function body can
use all the same operators, functions, user functions, and keywords as used in
assignment expressions.
Values can be passed into and out of a function via parameters. All variables of type
Input, Output, or Input/Output that are declared in the function will be the parameters of
the function. See Declaring Variables in User Functions for more details.
The following limitations apply to the user function body:
•
Output variables can only be assigned to. That is, Output variables can only be used
on the left-hand side of assignment expressions.
•
Input variables cannot be assigned to.
Accessing Controller Tags
The code in a user function can directly reference controller tags, such as variables in the
Variable Table, axis tags, etc. However, in order to keep a user function portable between
RMCTools projects, it is good practice to limit direct referencing of controller tags and
instead pass values in and out via the Input, Output, and Input/Output function
parameters.
Function Return Value
Each function must have a return value. This is done by assigning a value to the name of
the function. For example, consider a function named Average3. The return value could
be expressed as:
Average3
:= (
Var1
+
Var2
+
Var3
) / 3;
Managing User Functions
364
Delta Computer Systems, Inc.