TechTip: Simple Macros in Weintek HMI
Weintek HMI have a very powerful macro language enabling scripts to be written to implement control, perform calculations and much more. For those new to macros it can be quite daunting to get started. The example shown in this TechTip Article are designed as a “leg-up” to get you started with macros. Step 1 The Macro button is on the project tab within EasyBuilder Pro: Step 2 We need to create a macro by clicking “New…” Step 3 Let’s break down what you need to know to get started with writing a macro. First off we need to declare variables. These are, but not limited to “short”(16-bit number), “int”(32-bit number), “bool” (a bit). It is a good idea to comment macros (using // ) because what you write now may not make sense in the future! macro_command main() //declare variables short number1 // variable declaration for number1 short number2 // variable declaration for number2 short result // variable declaration for result Next up, in our example, we are going to get some data from the HMI local LW registers – but this could equally be a PLC or connected device register. There’s a handy wizard for this “GET/SET FN…” GetData(number1, “Local HMI”, LW, 0, 1) //Get the Value in LW0 and put it in the variable, number1 GetData(number2, “Local HMI”, LW, 1, 1) //Get the Value in LW1 and put it in the variable, number1 Then..perform action or calculation: result = number1 + number2 // perform the calculation and put the result in “result” Now our result has been calculated, we need to put that into an LW register so we can display it on the HMI: SetData(result, “Local HMI”, LW, 2, 1) // Put “result” into LW2 end macro_command Put all that together and our macro is: Click “Save & Compile” and assuming you have no errors you’re done! Step 4 A macro can be time-based and run all the time, or it can be triggered – this can be done with a button on the HMI. An example project performing addition, multiplication and division by macro can be downloaded here:
For more information on TechTip: Simple Macros in Weintek HMI talk to Lamonde Automation Ltd