188
14.5.1 Function Blocks
Function Blocks are useful for reducing repetitive code, must be defined before use and can use any variable and statement
type. A function block is called by putting its name followed by parameters, in parenthesis, in the Main Macro Function. After
the function block is executed, it returns the value to the Main Function where it is used as an assignment or condition.
Note:
Macro Functions cannot be nested or interleaved.
The Syntax is as follows:
Sub type <name> [(parameters)]
Variable Declarations
[Statements]
[Return [value]]
End Sub
Syntax description:
Sub
Must be used to begin the Function Block
type
Required. This is the data type of value that the function returns.
<name>
The name of the Function. It is used in the Main Macro to call the function.
(parameters)
Optional. The parameters hold values that are passed to the function by the Main Macro.
The passed parameters must have their type declared in the parameter field and
assigned a variable name. For example: Sub int MyFunction (int x, int y). x and y would
be integers passed to the function by the Main Macro. This function is called by a
statement that looks similar to this: “z = MyFunction(123, preset)” Notice that the calling
statement can pass hard coded values or variables to the function. After the function is
executed, an integer value is returned to “z”.
Variable
Declarations
Variables that are used in the Function Block must be declared first. This is in addition to
passed parameters. In the above example x and y are variables that the function can
use. Global variables are also available for use in Function Blocks.
[Statements]
Statements to execute.
[Return [value]]
Used to return a value to the calling statement. The value can be a constant or a
variable. Return also ends Function Block execution.
End Sub
Must be used to end a Function Block.
14.5.2 Built in Function Blocks
EasyBuilder has two built in Function Blocks for retrieving and transferring data to the PLC. They
are accessed by pressing the
GET/SET FN
button in the Macro Editor.
14.5.2.1 GetData Function
The GetData Function retrieves data from the PLC and puts it
into a variable for the Macro to use. To access the
GetData
Function, Click on a blank line in a Statement area of the macro
then click on the
GET/SET FN
button. The
Macro Functions
dialog pops up.
Select
GetData
as the
Function Name
.
Macro Address
Device Type
: The variable type that receives the data. This
automatically changes to match the variable selected in the
Device Address
.
Device Address
: This dropdown list displays the declared variables of the Macro. Select the variable to hold the PLC data.
Array Item
: If an array is selected for the
Device Address
, the particular item of the array must be designated.
Summary of Contents for MMI-1500
Page 2: ...ii...