System startup
Before using the function library, call the function string NRC_GetNexMotionLibVersion()
to obtain the version of the NexMotion library. This API returns the version information of the NexMotion library. Then, proceed with the initialization process.
The simplest way is to call the function int NRC_StartController(int netPort = 4)
to start the system. The netPort parameter represents the port number of the network interface that connects to the servo. The default value is 4, which should be set according to the specific model of the industrial control computer. You can call the function NRC_GetControlInitComplete()
to check if the system initialization is complete. The return value indicates whether the system initialization is complete: 0 means incomplete, 1 means complete. Before initialization is complete, do not call any other functions. System initialization takes time, and calling other functions before it is completed may result in a return of TARGET_NOT_EXIST.
C++ demo program for system startup
#include <iostream>
#include "nrcAPI.h"
#include<stdio.h>
using namespace std;
void msgHook()
{
NRC_Messsage tmp; //Define a message structure object, see section 3.7 for details
NRC_GetMesssage(1, tmp); //Assign the earliest message in the message queue to the object tmp
printf("msgHooklocalTime=%d:%d::%d,0x%x,0x%x,text=%s,size=%d\n", tmp.localTime.minute, tmp.localTime.second, tmp.localTime.milliseconds, tmp.kind, tmp.robot, tmp.text.c_str(), NRC_GetMesssageSize());
NRC_Delayms(200);//Output message content
}
void SystemStartup()
{
std::string NRC_GetNexMotionLibVersion();//Get the version information of NexMotion library
cout << "Library version:" << NRC_GetNexMotionLibVersion() << endl;//Output the version information of NexMotion library
NRC_StartController(); //Start the control system
while (NRC_GetControlInitComplete() != 1) //Check if the control system has been initialized
{
NRC_Delayms(100); //Delay 100ms
}
NRC_ClearAllError();//Clear all errors
cout << "StartController Success" << endl;
NRC_Delayms(200);
NRC_SetMsgHappenCallback(msgHook);//Set the callback function to be called when the message occurs
}
int main()
{
SystemStartup();//System startup, for program simplicity, adopt a call form
while(1)//Keep the program running
{
NRC_Delayms(1000);
}
}