Guide on how to write a Macro program
MACRO can be understood as a support program that includes control command structures and can function like a simple computer program when activated. The advantage of Macros is that they can easily represent the operating methods of an object, such as changing data, operating conditions, and sequences of operations using familiar programming commands for any programmer.
- Start up Macro, Main Macro, Event Macro, Time Macro are used for applications.
- Open Macro, Close Macro, Cycle Macro are used for screens.
- On Macro, Off Macro, object Macro are used for objects.
Depending on the specific application, the designer can choose one of the listed Macro programs.
There are 3 types of Macros: Global Macros, Component Macros, and Sub-Macros:
Global Macros : On the Background -> right-click -> screen properties -> Greneral-> select “Open Macro” or “Cycle Macro,” “Close Macro” -> the Macros window appears -> Program as required by the designer.
- Component Macros: These are Macros set internally within the object the designer is programming and can be accessed when interacting with the configured object without affecting the main program.
- Sub-Macro: A Sub-Macro program is located within another Macro program and is used with a call command. When the command is called, the main Macro program stops and starts running the Sub-Macro program. The last command in the Sub-Macro program will have a RET command to proceed to the next command in the main Macro program.
- Steps to create a Macro program:
Step 1: Create a Macro program:
- Project Manager -> Macro -> in the Macro window, give the program a name. Multiple Macros can be created within a folder. When executing the program, the designer can call the Macro program they want by using the “ON Macro” command on the control object.
Step 2: Write the Macro program.
- Macro programs contain all the commands, similar to familiar programming languages like C, C++, including If statements, for loops, jmp commands, comparison commands, transformation commands, subprograms, interrupt programs, etc. They provide convenient tools for programmers to optimize the system as efficiently as possible. Details about commands, structures, and operations can be found in the VT design manual.
- Macros support all command sets, including Move, Set, Arithmetic, Convert, Else/If, Program control, Utilities (1), and Utilities (2). Detailed information and usage can be found in the HMI manual under “Using Macros” (chapter 9).
- When the Start button is pressed, the water level in the tank rises.
- When it reaches a predetermined flow level, it stops.
- Code Macro:$U0.0 =01 // start button
///$U100 : địa chỉ ô nhớ bồn nước///
$U200=50 /// The memory holds the predetermined flow rate value
If $U100== $U200
$U0.0=00 // stop button