The initialization settings
While an EtherCAT link is being created between the hardware and the KINGSTAR Subsystem, we need to initialize some settings before the link state becomes Op. OPFlag
represents the link status. When it is false, the List Box is cleared: m_MotorList.GetCount
gets the number of axes in a List Box, and then a for
loop runs m_MotorList.DeleteString(0)
repeatedly to delete all the items in the List Box.
After that, the initialization settings are configured. The program sets the motion profile, converts the unit, enables the unit conversion, and gets the information of an axis. To display each axis, we pass the name of each axis to the CString object strSlave
, and use m_MotorList.AddString
to add them to the List Box. After all axes are displayed, we use m_MotorList.SetCurSel(0)
to select the first axis, and set OPFlag to true.
if (OPFlag == false)
{
int nSel = m_MotorList.GetCount();
for (int i = 0; i < nSel; i++)
{
m_MotorList.DeleteString(0);
}
for (int i = 0; i < KSMStatus.AxesCount; i++)
{
//Configures the motion settings of an axis.
::SetAxisMotionProfile(i, profileUnitPerSecond, ProfileSettings);
//Sets the conversion ratio of user-defined position unit to the count (pulse) unit used by the axis.
::SetAxisCountsPerUnit(i, Numerator, Denominator, Reverse);
//Enables the axis to use a real-world unit.
::EnableAxisUnitConversion(i, TRUE);
}
for (int i = 0; i < KSMStatus.AxesCount; i++)
{
//Gets the details information of an axis.
::GetAxisByIndex(i, &KSMSlaveStatus[i], &Resolution[i], &InputValue[i], &OutputValue[i]);
}
for (int i = 0; i < KSMStatus.AxesCount; i++)
{
CString strSlave(KSMSlaveStatus[i].Name);
m_MotorList.AddString(strSlave);
}
m_MotorList.SetCurSel(0);
OPFlag = true;
}