Chapter 13 - Macros
Using Macros
The “macro” language in EasyBuilder allows the programmer to perform simple transfers of data and/or simple to
complex conditional logic and transfers.
Macros are high-level language programs that can run inside the OIT to perform various data transfers and can
perform conditional logic. They are useful for doing tasks that are not supported in a standard object or feature of
the OIT. The macro language combines syntax elements of C, C++ and a little of its own style.
Previous experience in programming with C or C++ would be helpful when developing macros. It is not the scope
of this document to explain concepts of high-level language programming and the basics such as: variable data
types, arrays, conditional logic, and variable passing. However, it is the scope of this document to discuss the
commands and command structures that are required in building macros.
Macro Sam ple and Implementation
Macros can be used for customizing an application or when a special operation is needed that the normal OIT
objects (set bit, data transfer, etc) do not provide. A few possibilities are listed:
·
Unusual or non-linear scaling of data
·
Displaying the result of arithmetic operations on 2 or more PLC register values
·
Indirect addressing (where a PLC register holds the address of the desired data)
·
Lookup tables
·
Transferring Data once, instead of periodically
·
Writing data to the PLC in a specific sequence
·
Timed splash screens
A macro is written using the “macro” utility found in the ‘Tools’ menu list of Easy Builder. The ‘Add’ button will
create a new worksheet to program a new macro. The programmer first gives the macro a name in the top right
corner. Then programming can be added. After the code is finished, it needs compiled. If the code compiles
correctly there will be no errors and the macro name will be added to the top list. If the macro does not compile
correctly it will display error codes. If the programmer should cancel out from creating the macro before a
successful compile, it will put the macro into the bottom panel of the macro list and it will not be available as a
usable macro, but the text will remain to be edited later.
The macros are triggered by a setting a bit. The bit is specified in the ‘PLC Control Object’ list. The bit may be a
local bit ‘LB’ or it may be a PLC bit. Each macro created will have a unique name and bit.
When a specified bit is set high so it executes a specific macro, the macro will be entered into and its variables
initialized. The macro will run its sequence of events and will exit when finished. The bit that called the macro into
execution should be cleared by the macro before it exits, otherwise the macro will immediately be entered again
upon exit. If this immediate re-entry should happen, this could form an endless loop and will certainly cause a
taxing of the CPU time and cause slow screen refreshing and communications.
A sample macro is listed below which reads two local word registers and adds them together and stores them into
another register location:
Macro_Command main( )
short num1
short num2
short result
bool AllDone = 0
GetData(num1 ,LW_Binplc ,0,1) // get two registers to
add (LW:0 & LW:1)
GetData(num2 ,LW_Binplc ,1,1)
result = num1 + num2 // add the two registers
SetData(result ,LW_Binplc ,2,1) // store the result (LW:2)
1010-1001a, Rev 02
Macros
245
Содержание 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...