using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace MoveTest
{
    /// <summary>
    /// This class provides static member functions to interface with MSL.dll
    /// </summary>
    public class MoveClass
    {
        /// <summary>Initialises the controller</summary>
        /// <returns>The error code from the AER internals</returns>
        [DllImport("MSL.dll", EntryPoint = "initialise")]
        public static extern uint initialise();
              
        /// <summary>Disables the axes and releases them</summary>
        /// <returns>Error code from AER internals, zero if no error</returns>
        [DllImport("MSL.dll", EntryPoint = "disableAxes")]
        public static extern uint disableAxes();

        /// <summary>Enables the axes and locks them</summary>
        /// <returns>Error code from AER internals, zero if no error</returns>
        [DllImport("MSL.dll", EntryPoint = "enableAxes")]
        public static extern uint enableAxes();

        /// <summary>Moves the stage from its current location in the x axis</summary>
        /// <param name="distance">Distance and direction to move in machine counts</param>
        /// <param name="feedrate">Speed of actuation in machine steps per second</param>
        /// <returns>Error code from AER internals, returns zero if no error</returns>
        [DllImport("MSL.dll", EntryPoint = "incX")]
        public static extern uint incX(int distance, uint feedrate);

        /// <summary>Moves the stage from its current location in the y axis</summary>
        /// <param name="distance">Distance and direction to move in machine counts</param>
        /// <param name="feedrate">Speed of actuation in machine steps per second</param>
        /// <returns>Error code from AER internals, returns zero if no error</returns>
        [DllImport("MSL.dll", EntryPoint = "incY")]
        public static extern uint incY(int distance, uint feedrate);

        /// <summary>Moves the stage from its current location in the z axis</summary>
        /// <param name="distance">Distance and direction to move in machine counts</param>
        /// <param name="feedrate">Speed of actuation in machine steps per second</param>
        /// <returns>Error code from AER internals, returns zero if no error</returns>
        [DllImport("MSL.dll", EntryPoint = "incZ")]
        public static extern uint incZ(int distance, uint feedrate);

        /// <summary>Moves stage to absolute position</summary>
        /// <param name="distanceArray">Array of int distances in x, y, z</param>
        /// <param name="speedArray">Array of uint speeds</param>
        /// <returns>Error code from AER internals, returns zero if no error</returns>
        [DllImport("MSL.dll", EntryPoint = "moveMAbs")]
        public static extern uint moveAbsolute(ref int[] distanceArray, 
            ref uint[] speedArray);

        /// <summary>Shuts down the communications to the controller</summary>
        /// <returns>Zero?</returns>
        [DllImport("MSL.dll", EntryPoint = "closeComms")]
        public static extern uint shutdown();

        /// <summary>Gets the position of a given axis</summary>
        /// <param name="axisMask">Integer describing axis; 0 for x, 1 for y, 2 for z</param>
        /// <returns>Position in machine steps</returns>
        [DllImport("MSL.dll", EntryPoint = "_getPosition@4")]
        public static extern double getPosition(uint axisMask);

        /// <summary>Gets the velocity of a given axis</summary>
        /// <param name="axisMask">Integer describing axis; 0 for x, 1 for y, 2 for z</param>
        /// <returns>Velocity in machine steps per second</returns>
        [DllImport("MSL.dll", EntryPoint = "_getVelocity@4")]
        public static extern double getVelocity(uint axisMask);

    }
}
