Macro_Command main( )
// The main macro code goes here
End Macro_Command
Any other sub functions must be declared before the main() function can use it, for example:
Sub SQR(int MyVar )
// sub routine code goes here
End Sub
Macro_Command main( )
// The main macro code goes here
Result = SQR(MyNum) //The sub function “SQR()” is
called
End macro command
Local and Global Variables
Local variables exist only within the function in which they are defined.
Global variables exist throughout the entire macro, and are available for any function in the macro. NOTE: If a
local variable has the same name as a global variable, the compiler will use the local variable in the function instead.
Global variables are global only within the macro file in which they exist. It is not
possible to share variables between different macro files. To share data between macro
files, read/write the data to share into the OIT’s Local Word (LW) and/or Local Bit
(LB) addresses using the macro’s GetData() and SetData()UM_PLC functions.
Creating Variable Arrays
Arrays are fixed-depth and 1-dimensional only. Arrays can contain up to 65,535 elements. The
type
is the
declaration of the array of elements, such as an array of
ints
, or
shorts
, or
bools
, etc. The
array_size
is the number of
elements to contain in the array, such as an array of [10] would contain 10 elements of the declared
type
. The first
register in an array always begins with the 0
th
element and the last register is the declared number of elements minus
1.
The format is:
[type] Array_Name[Array_Size]
For example:
char table[100]
The above declaration defines an array of 100 type ‘char’ registers named ‘table’. The first element in table is
address 0 and the last is 99, so it would be used as:
char FirstElement
char Last Element
FirstElement=table[0]
LastElement=table[99]
Using Macros Within Recipes
The macro utility can easily use the recipe memory area. There are 60,000 recipe word registers that are available to
the user for general use (addresses RW:0 to RW:59999). Recipe memory at address RW:60000 and above are
reserved and have special functions. See the Easy Builder Help section or view technical note #TN1099 for the
current reserved memory listing.
Register types: RW, RWI, and the pointer LW:9000 can be used to read or write the recipe memory area. ‘RW’
registers are used to directly address a recipe register. ‘RWI’ registers are used to indirectly address a recipe register
by using the pointer in local word memory LW:9000. If indirect addressing is used, then the direct recipe address is
determined by adding the value contained in LW:9000 to the address of the RWI register. For instance, to indirectly
point to the direct recipe address RW:20, an example would be that the macro would store the value 15 into the
1010-1001a, Rev 02
Mac ros
251
Содержание Silver HMI504T
Страница 1: ...1010 1001A Rev 02...
Страница 20: ...1010 1001a Rev 02 16 Silver Series Installation Operation Manual OIT to PC Serial Port Pin Assignments...
Страница 32: ...1010 1001a Rev 02 28 Silver Series Installation Operation Manual...
Страница 128: ...1010 1001a Rev 01 124 Silver Series Installation Operation Manual...
Страница 156: ...1010 1001a Rev 02 152 Silver Series Installation Operation Manual...
Страница 166: ...1010 1001a Rev 02 162 Silver Series Installation Operation Manual...
Страница 216: ...1010 1001a Rev 01 212 Silver Series Installation Operation Manual...
Страница 251: ...1010 1001a Rev 02 Macros 247 Set Bit Objects Attributes Dialog Project Example of Add 2...
Страница 264: ...End Macro_Command 1010 1001a Rev 02 260 Silver Series Installation Operation Manual...
Страница 268: ...1010 1001a Rev 01 264 Silver Series Installation Operation Manual...