Buffered Breakpoint 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) { // Resource variables u8 boardID = 1; // Board identification number u8 axis = NIMC_AXIS1; // Axis number u8 buffer = 1; // Buffer number // Modal error handling variables u16 commandID; // The commandID of the function u16 resourceID; // The resource ID i32 errorCode; // Error code u16 csr = 0; // Communication status // Buffer resources i32 breakpointPositions[] = {1000, 1100, 1200, 1300, 1400, 1500, 1600}; u16 numberOfPoints = 7; // Number of breakpoints f64 actualInterval; // Required in the function call but not being used f64 requestedInterval = 10.0; // Required in the function call but not being used u32 backLog; // Number of space available in buffer u16 bufferState; // Buffer state u32 pointsDone; // Number of breakpoints done or consumed // Configure the buffer for buffered breakpoint err = flex_configure_buffer(boardID, buffer, axis, NIMC_BREAKPOINT_DATA, numberOfPoints, numberOfPoints, NIMC_TRUE, requestedInterval, &actualInterval); CheckError; // Write the breakpoint position to the buffer err = flex_write_buffer(boardID, buffer, numberOfPoints, NIMC_REGENERATION_NO_CHANGE, breakpointPositions, 0xFF); CheckError; // Configure the breakpoint to be buffered breakpoint err = flex_configure_breakpoint(boardID, axis, NIMC_ABSOLUTE_BREAKPOINT, NIMC_PULSE_BREAKPOINT, NIMC_OPERATION_BUFFERED); CheckError; // Enable the breakpoint err = flex_enable_breakpoint(boardID, axis, NIMC_TRUE); CheckError; // Poll the status of the buffer, if you more breakpoint positions // to write, insert flex_write_buffer call here. do { // Check the buffer status err = flex_check_buffer_rtn(boardID, buffer, &backLog, &bufferState, &pointsDone); CheckError; Sleep(50); } while ((pointsDone != numberOfPoints) || (bufferState != NIMC_BUFFER_DONE)); // Clear the buffer err = flex_clear_buffer(boardID, buffer); CheckError; return; ///////////////////////////////////////////////////////////////////////// // Error Handling // nimcHandleError; //NIMCCATCHTHIS: // Check to see if there were any Modal Errors if (csr & NIMC_MODAL_ERROR_MSG){ do{ // Get the command ID, resource and the error code of the modal // error from the error stack on the board flex_read_error_msg_rtn(boardID,&commandID,&resourceID,&errorCode); nimcDisplayError(errorCode,commandID,resourceID); // Read the Communication Status Register flex_read_csr_rtn(boardID,&csr); }while(csr & NIMC_MODAL_ERROR_MSG); } else // Display regular error nimcDisplayError(err,0,0); return; // Exit the Application }