Function Calls And Passing Parameters; Reading & Writing External Registers In A Macro - Maple Systems Silver Plus Series Installation And Operation Manual

Hide thumbs Also See for Silver Plus Series:
Table of Contents

Advertisement

252
break
Used in looping control or select statement. It skips immediately to the end of the statement.
continue
Used in looping control statement. It quits the current iteration of a loop and starts the next one.
return
Returns to the function or module that called the current function.
Format
While [Condition]
[Statements]
Wend
Boolean ex pres sions
The value of Boolean expression is zero means FALSE.
The value of Boolean expression is not zero means TRUE.

Function Calls and Passing Parameters

A sub-function must be defined before its execution and is therefore placed before the main() macro function. If
there is an entry attempt into a function before it is first defined in the macro program will create a compiler error
'Function not defined'.
The above example code defines a sub-function called SQR(). This sub-function allows one variable to be passed
into it. The function then takes the value passed to it, multiplies its value by itself and then stores the result back
into the same variable. The result is returned back to the calling function.
Reading & Writing External Registers in a Macro
A macro program can communicate with external PLC data registers and I/O. The function GetData() receives data
from a PLC in the device table (or the OIT's local LW and LB memory). The function SetData() sends data to the
PLC (or the OIT's local LW and LB memory).
The GetData() or the SetData() can be hand typed according to the format listed below, or the "PLC API" button
located at the bottom-left of the macro editor dialog box allows the user to generate the GetData() or SetData()
function code by selecting the appropriate responses within the PLC API dialog box. Be sure to declare all variables
before using the 'PLC API' option. To set up the following functions, place the cursor after the declarations, and
then press the PLC API button. This way, all variables will be available in a drop-down menu list within the 'PLC
API' dialog.
1010-1007, Rev 05
Sub int SQR(int x)
number
x = x * x
return x
End Sub
Macro_Command main( ) // This main function calls the SQR()
function.
int I = 5
I = SQR(I)
// Write the result to a LW
End Macro_Command
Sil ver Plus Se ries In stal la tion & Op er a tion Man ual
Examples
For n = 100 Down 0 Step 3
n = n * 2
Next n
For loop = 0 To 20 Step 2
loop = (loop + 1) *2
Next loop
//This is the sub-function that squares a

Advertisement

Table of Contents
loading

Table of Contents