Understanding C language (ANSI C89) Syntax / Functions in Macro Function of the NB HMI IntroductionThe purpose of this article is to provide information about how to program C language (ANSI C89) Operators and how do they work within a Macro Function in a NB HMI. Background InformationMacro is an advanced HMI control method, which makes the function of the HMI more powerful. The HMI can have the same logic and arithmetic functions with the PLC through the Macro programming. Using Macro flexibly can realize more powerful functions that can not be realized by the common component, and make the HMI more perfect. NB-Series PT provides the new Macros different from the Macro scripting language mode in the other HMIs, and the Macro is compatible with the standard C language (ANSI C89) completely. Content
1. What can a Macro Function do A Macro Function can do the following (supported) items:
2. How to create a Macro Press the (Add Macrocode) icon in the database toolbar as shown below, or click [Macrocode…] in the [Option] menu. 3. Macro Variables Macro variables are classified into two types: internal variables and external variables. Internal variables: Refers to the HMI’s own register units. Internal variables can be defined in [Macrocode Variable Window] and also can be used in [Macrocode Editing Window]. External variables: Refers to the register units read or written by the HMI from external controllers. External variables must be defined in [Macrocode Variable Window] beforehand, and then can be used in [Macrocode Editing Window]. 4. Data types used in Macro Variable The data types used in Macro Variable are shown in the table below. 5. C Language (ANSI C89) Syntax After creation a Macro Function contains the following C Language (ANSI C89) code: Macro:
#include "macrotypedef.h" #include "math.h" The Macro Function adds two pre-defined libraries to its code; "Macrotypedef.h" and "Math.h". "Macrotypedef.h" embedds functions and structured data such as memory access and graphic drawing. While "Math.h" embedds fixed parameters and functions for mathematic calculation. The following button shows the embedded functions that are supported in the NB HMI. Included Functions:
Furthermore, the syntax is an important aspect while writing commands in the Macro Function. NB-Designer only has a built-in compiler; this means that NB-Designer does not check the syntax on the fly. However during compilation NB-Designer will check for errors and / or warnings. The following code represents several syntax examples such as the usage of ; at the end of a code line, usage of the 'if' statement and how to create comments. Syntax examples:
int MacroEntry() { c = a + b; if ( c == 0 ) { c = 1; } return; // Put your comment here /* Put your comment here */ } 6. How to trigger a Macro A Macro can be triggered in different ways. A Macro can be used upon start-up of the NB, it can be used with a trigger such as a Timer, Function Key and many more functions within the NB. The figure below displays how to trigger a Macro, a Multiple State Setting Component is used as an example. 7. Example syntax 'NB HMI Operators' The attachment: 'NB HMI Operators' is a sample program to show the syntax of Operators including a description for each operator. Note: This program does not describe C language programming instead it only concentrates on the syntax of C programming of Operators and several 'nice to know' functions. Note: Two warnings occur during compilation. These warnings are related with the pointer function, please refer Macro code for more information. Important Notes
ReferenceNB Series NB-Designer Operation Manual - chapter 3-9 Macro Function Tutorial about C-programming
Link: |
Comments | ||
|