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>Does this even exist?</summary>
        /// <param name="x">Absolute/relative (?) x co-ordinate in machine steps</param>
        /// <param name="y">Absolute/relative (?) y co-ordinate in machine steps</param>
        /// <param name="feedrate">Speed of actuation in machine steps per second</param>
        /// <returns>Error code from the AER internals, zero if no error</returns>
        [DllImport("MSL.dll", EntryPoint = "moveDistance")]
        public static extern int moveDistance(int x, int y, uint feedrate);
        
        /// <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 current positions and velocities of the axes</summary>
        /// <param name="xPos">Pointer to the x position</param>
        /// <param name="yPos">Pointer to the y position</param>
        /// <param name="zPos">Pointer to the z position</param>
        /// <param name="xVel">Pointer to the x velocity</param>
        /// <param name="yVel">Pointer to the y velocity</param>
        /// <param name="zVel">Pointer to the z velocity</param>
        /// <returns>Error code from AER internals, zero if no error</returns>
        [DllImport("MSL.dll", EntryPoint = "getMAxisPV")]
        public static extern uint getMAxisPV(double xPos, double yPos, 
            double zPos, double xVel, double yVel, double zVel);
        */

        [DllImport("MSL.dll", EntryPoint = "getMAxisPV")]
        public static extern uint getMAxisPV(ref double[] values);
    }
}
