Technical Manual PD4-E-M (EtherCAT)
9 Programming with NanoJ
Note
In the NanoJ program, only global variables are permitted and they may only be initialized within
code. It then follows:
•
No
new
operator
•
No constructors
•
No initialization of global variables outside of code
Examples:
The global variable is to be initialized within the
void user()
function:
unsigned int i;
void user(){
i = 1;
i += 1;
}
The following assignment is not correct:
unsigned int i = 1;
void user() {
i += 1;
}
9.1.7 NanoJ program example
The example shows the programming of a square wave signal in object 2500
h
:01
h
.
// 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
You can find other examples at us.nanotec.com.
9.2 Mapping in the NanoJ program
Version: 1.0.1 / FIR-v1748
97