Chapter 14
Onboard Programs
©
National Instruments Corporation
14-17
C/C++ Code
The following example code is not necessarily complete, and may
not compile if copied exactly. Refer to the
examples
folder on the
NI-Motion CD for files that are complete and compile as is.
// Main Function
void main(void)
{
u8
boardID;//
Board identification number
u8
axis; //
Axis number
u16
csr = 0;//
Communication status register
i32
constant;//
Constant multiplier
//
Variables for modal error handling
u16
commandID;//
The commandID of the function
u16
resourceID;//
The resource ID
i32
errorCode;//
Error code
///////////////////////////////
//
Set the board ID
boardID = 1;
//
Set the axis number
axis = NIMC_AXIS1;
//
constant to multiply the ADC value read to
calculate the
//
required velocity
constant = 10;
//
Initialize onboard variable 4 to 0
err =
flex_load_var
(boardID, 0, 4);
CheckError;
//
Initialize onboard variable 1 to the constant
multiplier
err =
flex_load_var
(boardID, constant, 1);
CheckError;
//
Begin onboard program storage - program number 1
err =
flex_begin_store
(boardID, 1);
//
Set the operation mode to velocity
err =
flex_set_op_mode
(boardID, axis,
NIMC_VELOCITY);
CheckError;
//
Insert Label number 1
err =
flex_insert_program_label
(boardID, 1);
CheckError;
//
Read ADC channel and store ADC value in variable 2