8 Programming with NanoJ
Tip
Nanotec recommends:
●
Use mapping if you need to access an object in the object dictionary frequently, e.g., controlword
6040
h
or statusword 6041
h
.
●
The od_write() and od_read() functions are better suited for accessing objects a single time,
see Accessing the object dictionary.
8.2.1 Declaration of the mapping
The declaration of the mapping is structured as follows:
map <TYPE> <NAME> as <input|output|inout> <INDEX>:<SUBINDEX>
Where:
●
<TYPE>
The data type of the variable; U32, U16, U08, S32, S16 or S08.
●
<NAME>
The name of the variable as it is used in the user program.
●
<input|output|inout>
The read and write permission of a variable: a variable can be declared as an input, output or
inout. This defines whether a variable is readable (input), writable (output) or both (inout) and the
structure by means of which it must be addressed in the program.
●
<INDEX>:<SUBINDEX>
Index and subindex of the object to be mapped in the object dictionary.
Each declared variable is addressed in the user program via one of the three structures: In, Out or InOut
depending on the defined write and read direction.
8.2.2 Example of mapping
Example of a mapping and the corresponding variable accesses:
map U16 controlWord as output 0x6040:00
map U08 statusWord as input 0x6041:00
map U08 modeOfOperation as inout 0x6060:00
#include "wrapper.h"
void user()
{
[...]
Out.controlWord = 1;
U08 tmpVar = In.statusword;
InOut.modeOfOperation = tmpVar;
[...]
}
8.2.3 Possible error at od_write()
A possible source of errors is a write access with the od_write() function (see System calls in a NanoJ
program) of an object in the object dictionary that was simultaneously created as mapping. The code listed in
the following is incorrect:
map U16 controlWord as output 0x6040:00
Version: 2.0.1 / FIR-v1650 99