Using a #define from the C-application in EmWi

Description:

In some case its necessary to get information, defined in the C-code of your application in the Chora code of your EmWi project. This article describes a way how this can be realized.

 

Solution:

The only way to access a value from the C-application is in native code. It doesn’t matter whether the value comes from a #define or from a variable.

1.  In the unit where we want to access a value from C-code we need to include the header file with the definition or declaration of the access function or definition. Get an "Inline Code"-brick from the Default Gallery into this unit and set your include e.g.

 

 #include “Environment.h”

 

Note: It is recommended to change the order of the members of your unit to have the inline code back most. The order determines the sequence for the code generation starting from bottom to top. This ensures that the #include is inserted in the generated code at the beginning of the file.

2. No we assume that there is a definition in the header file Environment.h e.g.

 

#define ENVIRONMENT_NO_OF_CI_SLOTS 2

 

To access this value we drag a new method in the class where we want to access the #define, rename the method to GetNoOfCiSlots() and set the return value to int32. In the editor window we can now implement the native code.

 

var int32 result = 0;
$if !$Prototyper
native( result ){
  result = ENVIRONMENT_NO_OF_CI_SLOTS;
}
$endif
return result; 

 

See also:

[HT-012-Exchange_data_with_EmWi.pdf]

FAQ Article: Usageof EmWi macros in the generated C-code

 

Keywords:

Macro, #define, C-code, Chora, native

 

Last update on 2010-08-19 by Mario Stefanutti.

Go back