![NANOTEC PD4-C5918M4204-E-01 Скачать руководство пользователя страница 78](http://html1.mh-extra.com/html/nanotec/pd4-c5918m4204-e-01/pd4-c5918m4204-e-01_manual_3241520078.webp)
Manual PD4-C (USB)
11 Programming with NanoJ
Version: 1.4.1 / 22.07.2016 / FIR-v1626
78
The code to be executed can then be stored in the
void user()
function.
The file names of the user programs must not be longer than eight characters and contains three
characters in the extension; for example, "main.cpp" is admissible while "alongerfilename.cpp" is not.
Example
Programming a square wave signal in the object 2500
h
:01
h
1. Copy the following text to the NanoJ Easy editor and store this file under the name "main.cpp".
// file main.cpp
map S32 outputReg1 as inout 0x2500:1
#include "wrapper.h"
// user program
void user() {
U16 counter = 0;
while( 1 ) {
++counter;
if( counter < 100 )
InOut.outputReg1 = 0;
else if( counter < 200 )
InOut.outputReg1 = 1;
else
counter = 0;
// yield() 5 times (delay 5ms)
for(U08 i = 0; i < 5; ++i )
yield();
}
}// eof
2. When the program has been properly translated:
Rename the output file "
main.usr
" to "
vmmcode.usr
".
3. Use USB to copy the file to the motor controller. The motor controller must be restarted to launch
the program; please read the "NanoJ program" section starting at step 2 for details.
11.5.3 Structure of a mapping
Introduction
This method can be used to directly link a variable in the NanoJ program with an entry in the
object directory. The mapping must be created at the beginning of the file - before the
#include
"wrapper.h"
instruction. Only a comment above the mapping is allowed.
Tip
Use mapping if you frequently need access to an object in the object
directory, such as the control word 6040
or status word 6041
h
.
The
od_write()
and
od_read()
functions are better suited for
single access to objects (see the "Access to the object directory"
section).
Declaration of the mapping
The declaration of the mapping is structured as follows:
map <TYPE> <NAME> as <input|output|inout> <INDEX>:<SUBINDEX>
The following applies:
•
<TYPE>