Unit Conversion complete code

This page contains the complete code of Unit conversion.

In AxisConfiguration.cpp, your unit conversion code should be as follows:

Copy
#include "RT_Project_01.h"
#include "AxisConfiguration.h"
using namespace std;

VOID PositionUnitConversion(int Index)
{
    RtPrintf("Convert the unit to degrees.\n");

    int Resolution = 0;
    KsError nRet = errNoError;
    SlaveStatus Sts = { 0 };

    //Get the information from an axis.
    nRet = GetAxisByIndex(Index, &Sts, &Resolution, NULL, NULL);
    if (nRet != errNoError)
        RtPrintf("GetAxisByIndex failed: %x\n", nRet);

    //Set a conversion ratio.
    nRet = SetAxisCountsPerUnit(Index, Resolution, UNITS_PER_REVOLUTION, FALSE);
    if (nRet != errNoError)
        RtPrintf("SetAxisCountsPerUnit failed: %x\n", nRet);

    //Enable the unit conversion.
    nRet = EnableAxisUnitConversion(Index, TRUE);
    if (nRet != errNoError)
        RtPrintf("EnableAxisUnitConversion failed: %x\n", nRet);

    RtPrintf("\n");
}