//--------------------------------------------------------------
// Press F1 to get help about using script.
// To access an object that is not located in the current class, start the call with Globals.
// When using events and timers be cautious not to generate memoryleaks,
// please see the help for more information.
//---------------------------------------------------------------

namespace Neo.ApplicationFramework.Generated
{
    using System.Windows.Forms;
    using System;
    using System.Drawing;
    using Neo.ApplicationFramework.Tools;
    using Neo.ApplicationFramework.Common.Graphics.Logic;
    using Neo.ApplicationFramework.Controls;
    using Neo.ApplicationFramework.Interfaces;
	using System.Threading;
    
    
    public partial class Tags
    {
		//Handles setting the motion task type after a move type is selected
		//Only supports Absolute, Relative CMD, and Relative Actual
		void MoveType_ValueChange(System.Object sender, Neo.ApplicationFramework.Interfaces.Events.ValueChangedEventArgs e)
		{
			if(Globals.Tags.MoveType.Value==0) //if MoveType=0 is "Absolute"
			{
				Globals.Tags.MT_CNTL_0.Value=0; //MT.CNTL bit0=0
				Globals.Tags.MT_CNTL_1.Value=0; //MT.CNTL bit1=0
				Globals.Tags.MT_CNTL_2.Value=0; //MT.CNTL bit2=0, Absolute
			}
			if(Globals.Tags.MoveType.Value==1) //if MoveType=1 is "Relative CMD"
			{
				Globals.Tags.MT_CNTL_0.Value=1; //MT.CNTL bit0=1
				Globals.Tags.MT_CNTL_1.Value=0; //MT.CNTL bit1=0
				Globals.Tags.MT_CNTL_2.Value=0; //MT.CNTL bit2=0, Relative to Command Position
			}
			if(Globals.Tags.MoveType.Value==2) //if MoveType=0 is "Relative Actual"
			{
				Globals.Tags.MT_CNTL_0.Value=1; //MT.CNTL bit0=1
				Globals.Tags.MT_CNTL_1.Value=1; //MT.CNTL bit1=1
				Globals.Tags.MT_CNTL_2.Value=1; //MT.CNTL bit2=1, Relative to Feedback Position
			}
		}
				
		void MT_LOAD_ValueChange(System.Object sender, Neo.ApplicationFramework.Interfaces.Events.ValueChangedEventArgs e)
		{
			Thread.Sleep(50);			
			Globals.Tags.MT_LOAD.Value=1;
			Thread.Sleep(100);
			
			//if MT.CNTL bit0=0, bit1=0, and bit2=0,then
			if((Globals.Tags.MT_CNTL_0.Value==0) && (Globals.Tags.MT_CNTL_1.Value==0) && (Globals.Tags.MT_CNTL_2.Value==0))
			{
				Globals.Tags.MoveType.Value=0;//set MoveType=0 (Absolute)
			}
			//if MT.CNTL bit0=1, bit1=0, and bit2=0,then
			if((Globals.Tags.MT_CNTL_0.Value==1) && (Globals.Tags.MT_CNTL_1.Value==0) && (Globals.Tags.MT_CNTL_2.Value==0))
			{
				Globals.Tags.MoveType.Value=1;//set MoveType=1 (Relative CMD)
			}
			//if MT.CNTL bit0=1, bit1=1, and bit2=1,then
			if((Globals.Tags.MT_CNTL_0.Value==1) && (Globals.Tags.MT_CNTL_1.Value==1) && (Globals.Tags.MT_CNTL_2.Value==1))
			{
				Globals.Tags.MoveType.Value=2;//set MoveType=2 (Relative Actual)
			}
		}
						
    }
}
