using RSI.RapidCode.dotNET;
using System;
using System.Threading;
{
class HomingWithDS402drive
{
static void Main(string[] args)
{
const int AXIS_NUMBER = 0;
const int offsetIndex = 0x607C;
const int offsetSubindex = 0x0;
const int offsetByteSize = 4;
const int offsetValue = 0;
const int methodIndex = 0x6098;
const int methodSubindex = 0x0;
const int methodByteSize = 1;
const int methodValue = 24;
const int targetSpeedIndex = 0x6099;
const int targetSpeedSubindex = 0x1;
const int targetSpeedByteSize = 4;
const int targetSpeedValue = 2;
const int originSpeedIndex = 0x6099;
const int originSpeedSubindex = 0x2;
const int orignSpeedByteSize = 4;
const int originSpeedValue = 10;
const int accelerationIndex = 0x609A;
const int accelerationSubindex = 0x0;
const int accelerationByteSize = 4;
const int accelerationValue = 100;
const int modeOfOpIndex = 0x6060;
const int modeOfOpSubindex = 0x0;
const int modeOfOpByteSize = 1;
const int modeOfOpValueToHOME = 6;
const int modeOfOpValueToDEFAULT = 8;
const int axisControlWordIndex = 0;
const int CONTROL_WORD_TO_PREP_HOMING = 15;
const int CONTROL_WORD_TO_START_HOMING = 31;
const int ACCEPTABLE_DELAY_IN_MS = 20;
const int STATUS_WORD_TARGET_REACHED_BIT = 0x400;
const int STATUS_WORD_HOMING_ATTAINED_BIT = 0x1000;
const int STATUS_WORD_HOMING_ERROR_BIT = 0x2000;
try
{
axis.
NetworkNode.
ServiceChannelWrite(offsetIndex, offsetSubindex, offsetByteSize, offsetValue);
axis.NetworkNode.
ServiceChannelWrite(methodIndex, methodSubindex, methodByteSize, methodValue);
axis.NetworkNode.
ServiceChannelWrite(targetSpeedIndex, targetSpeedSubindex, targetSpeedByteSize, targetSpeedValue);
axis.NetworkNode.
ServiceChannelWrite(originSpeedIndex, originSpeedSubindex, orignSpeedByteSize, originSpeedValue);
axis.NetworkNode.
ServiceChannelWrite(accelerationIndex, accelerationSubindex, accelerationByteSize, accelerationValue);
Thread.Sleep(ACCEPTABLE_DELAY_IN_MS);
axis.NetworkNode.
ServiceChannelWrite(modeOfOpIndex, modeOfOpSubindex, modeOfOpByteSize, modeOfOpValueToHOME);
Thread.Sleep(ACCEPTABLE_DELAY_IN_MS);
Thread.Sleep(ACCEPTABLE_DELAY_IN_MS);
UInt16 statusWordValue;
bool cancelHome = false;
while ((!cancelHome) && ((statusWordValue & STATUS_WORD_TARGET_REACHED_BIT) == 0))
{
}
if ((statusWordValue & STATUS_WORD_HOMING_ATTAINED_BIT) == 1)
{
Console.WriteLine("Axis homed.");
}
else if ((statusWordValue & STATUS_WORD_HOMING_ERROR_BIT) == 1)
{
Console.WriteLine("Error Occured during homing.");
}
axis.NetworkNode.
ServiceChannelWrite(modeOfOpIndex, modeOfOpSubindex, modeOfOpByteSize, modeOfOpValueToDEFAULT);
Thread.Sleep(ACCEPTABLE_DELAY_IN_MS);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
}
}