NB Macro FAQ's and Tips

This article addresses common questions when creating and using macros in the NB HMI.
The macro function of the NB HMI is a powerful tool that allows the user to create and execute simple and original programs. The macro function provides a programming method to expand the basic functions of the NB HMI as well as reduce the PLC data processing load. There are several common questions and tips included in this article that provide a better understanding of macro creation and processing.
This is not an exhaustive resource to all NB macro topics, but rather a collection of frequently asked questions and other related macro issues. Some content is subject to change upon newer software versions after 1.31.
This article contains the following topics.
Why do I see the message "Failed to set macro compiler path"?

A message reading "Failed to set macro compiler path!" may appear when attempting to run NB-Designer. This occurs if the program has not been designated to run with administrator rights in Windows.

It is recommended to run NB-Designer software in Administrator Mode. Right-click the NB-Designer.exe file in the folder specified during installation and either; select execute as administrator or set the Privilege Level to "Run this program as an administrator" in the compatibility tab of the file properties.


This message may also appear when using NB-Designer and/or saving projects over a network drive. If this occurs, try operating NB-Designer on the local machine. 


Why am I experiencing problems with a ModBus macro?

Creating a macro to communicate with ModBus slaves is possible* but there is a specific conditions that can cause communication problems. Calling addresses of slave units directly within the macro can cause slow communications and macro errors. If the NB cannot access a ModBus slave address, the macro will not be executed. Instead of directly referencing ModBus slave addresses within a macro, use the NB's internal addresses as variables for the macro. Then use the Data Transmission function or the Data Transmission option in the Timer for exchanging data.

*NOTE: There are some limitations when using a macro to communicate to ModBus slaves. Contact your local Omron representative for more information.


Which macro is causing a macro error to appear?

If there is a problem with the execution of a macro, a macro code error will be displayed.

The macro code error provides a reference to the macro number that caused the error (0002 above but this can be useless if the macro has been given a name that is missing the original macro number. It is recommended to leave the macro number in the name when renaming or creating a new macro. For example, a new macro file name is suggested by NB-Designer as "macro_2.c" as shown below.

It is acceptable to rename this, but leave the "_2" at the end of the name as a reference (i.e. "division_2.c"). This will aid in referencing which macro is causing the error.


What C libraries does the NB support?

When a new macro is created, NB-Designer automatically embeds two default libraries into its code; "Macrotypedef.h" and "Math.h". "Macrotypedef.h" embeds functions and structured data such as memory access and graphic drawing and "Math.h" embeds fixed parameters and functions for mathematic calculation. These are the only two libraries that are supported by NB-Designer currently. There is some functionality when using standard C library files but this is not officially supported by Omron at this time. Contact your local Omron representative for more information.


Why is the WriteLocal macro function causing an error? 

The NB macro function WriteLocal causes the HMI to write values to a specified local address within the NB, such as the RW area. There is a known limitation to the amount of memory locations that can be written when using this macro function. If the number of addresses exceeds 4096, there can be a macro error as seen below.


The following macro function is problematic due to the value of 5000.

WriteLocal("RW", 0, 5000, (void*)buf, 0);

The following macro function will work when the nRegs parameter is less than 4096 as shown.

WriteLocal("RW", 0, 4096, (void*)buf, 0);


Why do I get a "link macro file...failed" compilation error?

The NB-Designer software uses a compiler to validate macro codes before transferring to the HMI and this compiler is installed with NB-Designer. If another GCC (GNU Compiler Collection) is present or added to the system, it may interfere with the normal compiler function of NB-Designer.  In this situation, Windows may have an incorrect path setting for the required compiler. Examine the Environment Variables found in the Windows System Properties for interfering GCC libraries.


Why does my NB HMI freeze and become unresponsive?

There is a macro implementation that may disrupt the responsiveness of the NB HMI. If a macro program uses the Real Time Clock (RTC) NB memory areas (10000-10006) as read/write variables, freezing or unresponsiveness may occur. This may also reduce the accuracy of the NB RTC.


For example, some applications require synchronization of the NB RTC with the host PLC. Rather than using a custom macro to achieve this, use the Data Transmission component instead. The "Use External Clock" option found in the PT property area may also be incorporated into this solution. Or, change the variable types to Read Only if a macro is required.




Other Tips
  • - Since the read variables do not read the memory value during executing the macro, the read value remains the same as the one when the macro read during operating. Even if the memory value is modified from the external device during the macro executing, result of the operation is not being affected.
  • - Even if the memory value is written with a value from the external device during the macro executing, the memory value will be updated to the result of the execution of the macro after the macro completed.
  • - The read variable is read only and the write value is writing only. Therefore, writing the value to the read variable or reading the writing variable by using the macro is not possible. Similarly, when one address is used for reading and writing at the same time, use two different names by contrast for the variables.
  • - The global variables or the static variables are not available in the macro. If the data should be retained using the global variables, use the HMI internal memories such as LW or LB.
  • - The values which output the result of the macro should be prepared.
  • - Try to use HMI's internal addresses as variables for a macro. If there is a need for exchanging data between the touch panels and slave Unit communication components, resort to the data transmission function of the timer or data transmission components.
  • - The specification of the macro operation is as follows: Before the program is executed, the value from the memory will be assigned to Read variables, then macro will be executed. Later, after macro function returns, the value of variable will be written. Therefore, the variables of the macro perform like the copy of the memory and even if the variables are modified, the value of the memory is not being changed.
  • - There is no interrupt possible when a macro is running. Also when calling the macro again you must wait for it to be finished to avoid problems.
  • - There are status addresses available that gives you information about the running macro such as 9118 (Macro Operation). See section 3 of the NB-Designer Operation Manual (Cat. No. V106).
  • - When writing code of a macro, if a large of number of address variables of the PLC or slave Unit is defined, the execution speed of the HMI may suffer. When executing a macro program, the processor picks up the variable addresses defined first, executes the macro, then carries out output. If the macro is executed at a high frequency, a large amount of time is used to perform communication with the slave Unit, thus affecting the execution speed of the HMI as a whole.



In summary, the NB macro function is a powerful tool included in the NB-Designer software that provides an opportunity to add functionality to an NB application. This article provides tips and answers to frequently asked questions as a supplement to the NB-Designer Operation Manual for a better understanding of the macro function.

*These details and references were made at the time of software version 1.31. Newer versions may operate and function differently. Contact your local Omron representative for more information.