Technical Manual PD4-E-M (EtherCAT)
9 Programming with NanoJ
With this method, a variable in the NanoJ program is linked directly with an entry in the object
dictionary. The creation of the mapping must be located at the start of the file here, even before the
#include "wrapper.h"
instruction. A comment is permitted above the mapping.
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.
9.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.
9.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;
[...]
}
Version: 1.0.1 / FIR-v1748
98