AxisSwitchID.cs

Get an Axis object from an expected switch id (instead of topology)

/*  
 Copyright(c) 1998-2009 by Robotic Systems Integration, Inc. All rights reserved.
 This software contains proprietary and confidential information of Robotic 
 Systems Integration, Inc. (RSI) and its suppliers. Except as may be set forth 
 in the license agreement under which this software is supplied, disclosure, 
 reproduction, or use with controls other than those provided by RSI or suppliers
 for RSI is strictly prohibited without the prior express written consent of 
 Robotic Systems Integration.

 Warning!  This is a sample program to assist in the integration of your motion 
 controller with your application.  It may not contain all of the logic and safety
 features that your application requires.

 For any questions regarding this sample code please visit www.roboticsys.com.
 ==================================================================================
*/

using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using RSI.RapidCode.SynqNet.dotNET;
using RSI.RapidCode.SynqNet.dotNET.Enums;

namespace SampleApplications
{
    [TestFixture]
    public class AxisSwitchID
    {
        // desired and/or expected switch id values
        const int LINEAR_AXIS_SWITCH_ID = 0xCC;
        const int ROTARY_AXIS_SWITCH_ID = 0x44;

        // RapidCode objects
        MotionController controller;
        Axis linear;
        Axis rotary;

        // A list of Axis objects
        List<Axis> axes;


        public Axis AxisGetFromSwitchID(int switchID)
        {
            Axis axisMatch = null;

            foreach (Axis axis in axes)
            {
                if (axis.SqNode.Exists())
                {
                    if (axis.SqNode.SwitchIDGet() == switchID)
                    {
                        axisMatch = axis;
                    }
                }
            }
            return axisMatch;
        }


        [Test]
        public void Main()
        {

            try
            {
                controller = MotionController.Create();

                axes = new List<Axis>();

                for(int i = 0; i < controller.AxisCountGet(); i++)
                {
                    axes.Add(controller.AxisGet(i));
                }

                linear = AxisGetFromSwitchID(LINEAR_AXIS_SWITCH_ID);
                rotary = AxisGetFromSwitchID(ROTARY_AXIS_SWITCH_ID);

                
                Assert.IsNotNull(linear, "Oops, there is no drive with the expected Switch ID!");
                Assert.IsNotNull(rotary, "Oops, there is no drive with the expected Switch ID!");
            }
            catch(RsiError e)
            {
                Console.WriteLine(e.Message);
            }
        }
    }
}