///////////////////////////////////////////////////////////////////////////
//
//  NAME
//    mcapi_dl.h - motion control API function prototypes & macros
//
//  DESCRIPTION
//    Include this header file in your source code to provide prototypes
//    for the motion control API functions when using dynamic linking to
//    load the MCAPI DLL.
//
//    #include "mcapi_dl.h"
//
//    To change your application from standard static linking (i.e. using
//    MCAPI32.LIB) to dynamic linking:
//
//      1. Include the file MCAPI_DL.CPP in your project
//      2. Remove any reference to MCAPI32.LIB from your project
//      3. Replace the standard MCAPI header file (MCAPI.H) with this 
//         header file
//      4. Add a call to MCLoadApi() prior to calling any API function
//         (function declared in MCAPI.CPP)
//      5. See the joystick demo supplied with the MCAPI for an example.
//
//  RELEASE HISTORY
//    Copyright (c) 2002-2014 by Precision Micro Control Corp. All rights
//    reserved.
//
//    $Id: mcapi_dl.h 796 2013-04-20 00:35:12Z brian $
//
//    Version 3.2.0      4-Jan-02       Programmer: Brian Gaynor
//      - First release
//
//    Version 3.2.1     26-Apr-02       Programmer: Brian Gaynor
//      - No changes to this module
//
//    Version 3.3.0		15-Jan-03		Programmer: Brian Gaynor
//      - Added missing MC_CAPTURE_ADVANCED state
//      - Wrapped constant _MCAPI_VER so it can be defined outside of
//        this header file
//      - Added constants for MFX-PCI1000 series controllers
//      - Added prototypes, structures, and constants for MCGetStatusEX(),
//        MCSTATUSEX, and MCDecodeStatusEx()
//      - Added status word lookup constants MC_STAT_PRI_ENC_FAULT, 
//        MC_STAT_AUX_ENC_FAULT, MC_STAT_LOOK_AUX_IDX, MC_STAT_AUX_IDX_FND
//      - Structure tags added to provide better support for source code
//        browsing tools
//      - Added prototype for MCEanableInterrupt()
//      - Added prototype for MCInterruptOnPosition()
//
//    Version 3.4.0		 2-Jun-03		Programmer: Brian Gaynor
//      - Added some conditional typedefs for basic Windows data types so
//        this header can also be used with products like LabWindows/CVI
//      - Added MCEnableEncoderFault() and constants MC_ENC_FAULT_PRI,
//        MC_ENC_FAULT_SEC for encoder fault detection feature of
//        Multiflex series of controllers
//      - Added MCGetAnalogEx/()MCSetAnalogEx() to make it easier for
//        Visual Basic users to handle 16-bit unsigned values
//      - Added pmcgetramex() and pmcputramex() to support larger memory
//        space of the PCI controllers (32-bit address offset and size)
//      - Added new fields to MCAXISCONFIG and MCPARAMEX structures
//
//    Version 3.4.1		31-Oct-03		Programmer: Brian Gaynor
//      - No changes to this module
//
//    Version 3.4.2		 5-Jul-04		Programmer: Brian Gaynor
//      - No changes to this module
//
//    Version 3.5.0		19-Nov-04		Programmer: Brian Gaynor
//      - Renamed to mcapi_dl.h so the dynamic linking code can more 
//        easily co-exist with the standard headers
//      - Added MCGetModuleOutputMode()
//      - Added MCGetVelocityOverride() / MCSetVelocityOverride()
//      - Extended MCFILTEREX structure with position deadband, delay at
//        target, output offset, and output deadband fields (MFX only)
//      - Extended MCPARAMEX with fields descroibing controllers support 
//        of the new functions added in this release
//
//    Version 3.5.1		 1-Feb-05		Programmer: Brian Gaynor
//      - No changes to this module
//
//    Version 3.5.2		24-Feb-05		Programmer: Brian Gaynor
//      - No changes to this module
//
//    Version 4.0.0		16-Jan-06		Programmer: Brian Gaynor
//      - Cleaned up function prototypes and header comments
//      - Converted long int types to int, doesn't effect 32-bit code,
//        sizeof(long int) == sizeof(int), but this will make sure that 
//        parameter sizes don't swell under 64-bit builds
//      - Added MCGetDigitalIOEx(), can return status of 32 digital I/O
//        channels in one call (BR #121).
//      - Added platform specific wrappers for dynamic linking on Windows
//        and Linux.
//
//    Version 4.0.1		27-Mar-06		Programmer: Brian Gaynor
//      - No changes to this module
//
//    Version 4.0.2		21-Apr-06		Programmer: Brian Gaynor
//      - No changes to this module
//
//    Version 4.0.3		17-Nov-06		Programmer: Brian Gaynor
//      - No changes to this module
//
//    Version 4.0.4		16-May-07		Programmer: Brian Gaynor
//      - No changes
//
//    Version 4.0.5		13-Jul-07		Programmer: Brian Gaynor
//      - No changes
//
//    Version 4.1.0		 1-Dec-08		Programmer: Brian Gaynor
//      - Added controller type for MultiFlex Ethernet.
//      - The MCAPI_LIB and MCDLG_LIB macros are now properly escaped for
//        use in UNICODE projects.
//      - Added constant MC_COMPARE_STROBE for new "strobe" output mode 
//        of compare function.
//      - Added new MCGetJogConfigEx() / MCSetJogConfig() prototypes and
//        MCJOGEX data structure declaration.
//      - Added new MCGetTrajectoryRate() / MCSetTrajectoryRate()
//        prototypes for checking/setting the trajectory rate on the 
//        MFX-ETH.
//
//    Version 4.1.1		14-Jul-09		Programmer: Brian Gaynor
//      - Added an error constant for TCP/IP socket errors.
//      - Added a more generic MCERR_OS_ERROR error constant as an alias
//        of MCERR_WINDOWSERROR.
//
//    Version 4.1.2		25-Sep-09		Programmer: Brian Gaynor
//      - No changes
//
//    Version 4.2.0		 1-Apr-10		Programmer: Brian Gaynor
//      - Added the LineModeAscii flag to the PARAMEX structture, allows
//        programs to optimize I/O with line oriented controllers such as
//        the Ethernet controller.
//      - Updates to the module output mode flags.
//
//    Version 4.3.0		19-Nov-12		Programmer: Brian Gaynor
//      - Added pmccmdrpyex(), pmclock(), pmcunlock(), pmclookupvar()
//
//    Version 4.3.1		XX-Apr-13		Programmer: Brian Gaynor
//      - DLL not found will now return MCERR_NOT_FOUND to differentiate
//        from missing functions which return MCERR_NOT_PRESENT. Missing
//        DLL usually means no API installed (application may want to run
//        in an offline mode), whereas missing functions usually mean the
//        version of the API installed is too old (bug #100201).
//
///////////////////////////////////////////////////////////////////////////

#ifndef MCAPI_DL_H
#define MCAPI_DL_H

#ifndef _MCAPI_VER
  #define _MCAPI_VER 430    	// change this value to limit function pointers
#endif                      	// to an earlier release of MCAPI. For instance,
                           		// if set to "210" only pointers for functions
								// present in MCAPI Ver 2.10 will be declared

//
//  Wrappers for platform specific dynamic linking 
//
#ifdef _WIN32
  #define wl_dynloadinit() 
  #define wl_dynloadopen(str) LoadLibrary(str) 
  #define wl_dynloadsym(lib, str) GetProcAddress(lib, str) 
  #define wl_dynloadclose(lib) FreeLibrary(lib) 
  #define wl_dynloadexit() 
#else
  #define wl_dynloadinit() lt_dlinit() 
  #define wl_dynloadopen(str) lt_dlopen(str) 
  #define wl_dynloadsym(lib, str) lt_dlsym(lib, str) 
  #define wl_dynloadclose(lib) lt_dlclose(lib) 
  #define wl_dynloadexit() lt_dlexit() 
#endif

//
//  Specify the proper libraries for the platform
//
#ifdef UNICODE
	#ifdef _WIN64
		#define MCAPI_LIB L"mcapi64.dll"
		#define MCDLG_LIB L"mcdlg64.dll"
	#else
		#define MCAPI_LIB L"mcapi32.dll"
		#define MCDLG_LIB L"mcdlg32.dll"
	#endif
#else
	#ifdef _WIN64
		#define MCAPI_LIB "mcapi64.dll"
		#define MCDLG_LIB "mcdlg64.dll"
	#else
		#define MCAPI_LIB "mcapi32.dll"
		#define MCDLG_LIB "mcdlg32.dll"
	#endif
#endif

//
//  Motion Control API manifest constants
//
#define MC_ALL_AXES             0

#define MC_ABSOLUTE             0
#define MC_RELATIVE             1

#define MC_BLOCK_COMPOUND       0
#define MC_BLOCK_TASK           1
#define MC_BLOCK_MACRO          2
#define MC_BLOCK_RESETM         3
#define MC_BLOCK_CANCEL         4
#define MC_BLOCK_CONTR_USER     5
#define MC_BLOCK_CONTR_LIN      6
#define MC_BLOCK_CONTR_CW       7
#define MC_BLOCK_CONTR_CCW      8

#define MC_CAPTURE_ACTUAL      16
#define MC_CAPTURE_ERROR       32
#define MC_CAPTURE_OPTIMAL     64
#define MC_CAPTURE_TORQUE     128
#define MC_CAPTURE_ADVANCED   256
#define MC_CAPTURE_AUXILIARY  512
#define MC_CAPTURE_STATUS    1024

#define MC_CENTER_ABS           MC_ABSOLUTE     // use MC_ABSOLUTE in new code
#define MC_CENTER_REL           MC_RELATIVE     // use MC_RELATIVE in new code

#define MC_COMPARE_DISABLE      0
#define MC_COMPARE_ENABLE       1
#define MC_COMPARE_STATIC       1
#define MC_COMPARE_TOGGLE       2
#define MC_COMPARE_ONESHOT      3
#define MC_COMPARE_STROBE       5
#define MC_COMPARE_INVERT  0x0080

#define MC_COUNT_CAPTURE        1
#define MC_COUNT_COMPARE        2
#define MC_COUNT_CONTOUR        4
#define MC_COUNT_FILTER         8
#define MC_COUNT_FILTERMAX     16

#define MC_CURRENT_FULL         1
#define MC_CURRENT_HALF         2

#define MC_DATA_ACTUAL          0               // use MC_CAPTURE_ACTUAL in new code
#define MC_DATA_OPTIMAL         1               // use MC_CAPTURE_OPTIMAL in new code
#define MC_DATA_ERROR           2               // use MC_CAPTURE_ERROR in new code
#define MC_DATA_TORQUE          3               // use MC_CAPTURE_TORQUE in new code

#define MC_DIO_FIXED          256
#define MC_DIO_INPUT            1
#define MC_DIO_OUTPUT           2
#define MC_DIO_HIGH             4
#define MC_DIO_LOW              8
#define MC_DIO_LATCH           16
#define MC_DIO_LATCHABLE      512
#define MC_DIO_STEPPER       1024

#define MC_DIR_POSITIVE         1
#define MC_DIR_NEGATIVE         2

#define MC_ENC_FAULT_PRI        1
#define MC_ENC_FAULT_AUX        2

#define MC_INT_NORMAL           0
#define MC_INT_FREEZE           1
#define MC_INT_ZERO             2

#define MC_IM_OPENLOOP          0
#define MC_IM_CLOSEDLOOP        1

#define MC_LIMIT_ABRUPT         4
#define MC_LIMIT_BOTH           3
#define MC_LIMIT_INVERT    0x0080
#define MC_LIMIT_MINUS          2
#define MC_LIMIT_OFF            0
#define MC_LIMIT_PLUS           1
#define MC_LIMIT_SMOOTH         8
#define MC_LIMIT_HIGH           MC_LIMIT_PLUS   // use MC_LIMIT_PLUS in new code
#define MC_LIMIT_LOW            MC_LIMIT_MINUS  // use MC_LIMIT_MINUS in new code

#define MC_LRN_POSITION         1
#define MC_LRN_TARGET           2

#define MC_MAX_ID              15

#define MC_MODE_CONTOUR         0
#define MC_MODE_GAIN            1
#define MC_MODE_POSITION        2
#define MC_MODE_TORQUE          3
#define MC_MODE_VELOCITY        4
#define MC_MODE_UNKNOWN         5

#define MC_MODULE_TYPE     0x000f
#define MC_MODULE_SUBTYPE  0x00f0

#define MC_OM_BIPOLAR           0
#define MC_OM_UNIPOLAR          1
#define MC_OM_PULSE_DIR         0
#define MC_OM_CW_CCW            1
#define MC_OM_BI_PWM            2
#define MC_OM_UNI_PWM           3
#define MC_OM_PIEZO             4
#define MC_OM_SINE_NOENC   0x8000
#define MC_OM_SINE_ENC	   0xC000

#define MC_OPEN_ASCII           1
#define MC_OPEN_BINARY          2
#define MC_OPEN_EXCLUSIVE  0x8000

#define MC_PHASE_STD            0
#define MC_PHASE_REV            1

#define MC_PROF_UNKNOWN         0
#define MC_PROF_TRAPEZOID       1
#define MC_PROF_SCURVE          2
#define MC_PROF_PARABOLIC       4

#define MC_RATE_UNKNOWN         0
#define MC_RATE_LOW             1
#define MC_RATE_MEDIUM          2
#define MC_RATE_HIGH            4

#define MC_STATUS_NOTIFY      "MCStatusNotify"  // message identifier
#define MC_STAT_BUSY            0
#define MC_STAT_MTR_ENABLE      1
#define MC_STAT_MODE_VEL        2
#define MC_STAT_TRAJ            3
#define MC_STAT_DIR             4
#define MC_STAT_JOG_ENAB        5
#define MC_STAT_HOMED           6
#define MC_STAT_ERROR           7
#define MC_STAT_LOOK_INDEX      8
#define MC_STAT_LOOK_EDGE       9
#define MC_STAT_BREAKPOINT     10
#define MC_STAT_FOLLOWING      11
#define MC_STAT_AMP_ENABLE     12
#define MC_STAT_AMP_FAULT      13
#define MC_STAT_PLIM_ENAB      14
#define MC_STAT_PLIM_TRIP      15
#define MC_STAT_MLIM_ENAB      16
#define MC_STAT_MLIM_TRIP      17
#define MC_STAT_PSOFT_ENAB     18
#define MC_STAT_PSOFT_TRIP     19
#define MC_STAT_MSOFT_ENAB     20
#define MC_STAT_MSOFT_TRIP     21
#define MC_STAT_INP_INDEX      22
#define MC_STAT_INP_HOME       23
#define MC_STAT_INP_AMP        24
#define MC_STAT_INP_AUX        25
#define MC_STAT_INP_PLIM       26
#define MC_STAT_INP_MLIM       27
#define MC_STAT_INP_USER1      28
#define MC_STAT_INP_USER2      29
#define MC_STAT_PHASE          30
#define MC_STAT_FULL_STEP      31
#define MC_STAT_HALF_STEP      32
#define MC_STAT_JOGGING        33
#define MC_STAT_PJOG_ENAB      34
#define MC_STAT_PJOG_ON        35
#define MC_STAT_MJOG_ENAB      36
#define MC_STAT_MJOG_ON        37
#define MC_STAT_INP_PJOG       38
#define MC_STAT_INP_MJOG       39
#define MC_STAT_STOPPING       40
#define MC_STAT_PROG_DIR       41
#define MC_STAT_AT_TARGET      42       // changed in v2.0d from MC_STAT_PWM_ENAB
#define MC_STAT_ACCEL          43  
#define MC_STAT_MODE_POS       44
#define MC_STAT_MODE_TRQE      45
#define MC_STAT_MODE_ARC       46
#define MC_STAT_MODE_CNTR      47
#define MC_STAT_MODE_SLAVE     48
#define MC_STAT_LMT_ABORT      49
#define MC_STAT_LMT_STOP       50
#define MC_STAT_CAPTURE        51
#define MC_STAT_RECORD         52
#define MC_STAT_SYNC           53
#define MC_STAT_MODE_LIN       54
#define MC_STAT_INDEX_FOUND    55
#define MC_STAT_POS_CAPT       56
#define MC_STAT_NULL           57
#define MC_STAT_EDGE_FOUND     58
#define MC_STAT_PRI_ENC_FAULT  59
#define MC_STAT_AUX_ENC_FAULT  60
#define MC_STAT_LOOK_AUX_IDX   61
#define MC_STAT_AUX_IDX_FND    62

#define MC_STEP_FULL            1
#define MC_STEP_HALF            2

#define MC_THREAD           0x100

#define MC_TYPE_NONE            0
#define MC_TYPE_REG             1
#define MC_TYPE_LONG            2
#define MC_TYPE_FLOAT           3
#define MC_TYPE_DOUBLE          4
#define MC_TYPE_STRING          5

#define MC_TYPE_SERVO           1
#define MC_TYPE_STEPPER         2

#define MC_LINEAR               1
#define MC_CIRC_CW              2
#define MC_CIRC_CCW             3

//
//  Controller specific manifest constants
//                     
#define NO_CONTROLLER           0
#define NONE                    NO_CONTROLLER    // old constant, use NO_CONTROLLER instead
#define DCXPC100                1
#define DCXAT100                2
#define DCXAT200                3
#define DC2PC100                4
#define DC2STN                  5
#define DCXAT300                6
#define DCXPCI300               7
#define DCXPCI100               8
#define MFXPCI1000              9
#define MFXETH1000             10

#define MC100                   5
#define MC110                   4
#define MC150                   6
#define MC160                   7
#define MC200                   0
#define MC210                  16
#define MC260                   1
#define MC300                   2
#define MC302                  22
#define MC320                 162
#define MC360                   3
#define MC362                  23
#define MC400                   8
#define MC500                  12
#define MF300                  10
#define MF310                   9
#define NO_MODULE              15
#define MFXSERVO              252
#define MFXSTEPPER            253
#define DC2SERVO              254
#define DC2STEPPER            255

//
//  Error code group masks
//
#define MCERRMASK_UNSUPPORTED 0x00000001L   // function not supported
#define MCERRMASK_HANDLE      0x00000002L   // bad handle
#define MCERRMASK_AXIS        0x00000004L   // bad axis number
#define MCERRMASK_PARAMETER   0x00000008L   // bad parameter
#define MCERRMASK_IO          0x00000010L   // I/O problem
#define MCERRMASK_SYSTEM      0x00000020L   // system level errors

#define MCERRMASK_STANDARD    0xFFFFFFFEL   // most common MCErrorNotify settings
                                            // includes all errors except UNSUPPORTED

#define MC_ERROR_NOTIFY       "MCErrorNotify"   // message identifier

//
//  Individual error codes
//

#define MCERR_NOERROR           0    // no error

//
//  MCERRMASK_SYSTEM group errors
//
#define MCERR_NO_CONTROLLER     1   // no controller assigned for this ID
#define MCERR_OUT_OF_HANDLES    2   // driver out of handles
#define MCERR_OPEN_EXCLUSIVE    3   // cannot open - exclusive
#define MCERR_MODE_UNAVAIL      4   // controller already open in different mode
#define MCERR_UNSUPPORTED_MODE  5   // controller doesn't support this mode
#define MCERR_INIT_DRIVER       6   // couldn't initialize the device driver
#define MCERR_NOT_PRESENT       7   // controller hardware not present;
#define MCERR_ALLOC_MEM         8   // memory allocation error
#define MCERR_WINDOWSERROR      9   // Windows function reported an error
#define MCERR_OS_ERROR          9   // OS function reported an error

//
//  MCERRMASK_UNSUPPORTED group errors
//
#define MCERR_NOTSUPPORTED     11   // controller doesn't support this feature
#define MCERR_OBSOLETE         12   // function is obsolete

//
//  MCERRMASK_HANDLE group errors
//
#define MCERR_CONTROLLER       13   // invalid controller handle 
#define MCERR_WINDOW           14   // invalid window handle

//
//  MCERRMASK_AXIS group errors
//
#define MCERR_AXIS_NUMBER      15   // axis number out of range
#define MCERR_AXIS_TYPE        16	// axis type doesn't support this feature
#define MCERR_ALL_AXES         17   // cannot select "ALL AXES" for function
#define MCERR_AXIS_ACTIVE      31	// axis was enabled or moving

//
//  MCERRMASK_PARAMETER group errors
//
#define MCERR_RANGE            18   // parameter was out of range
#define MCERR_CONSTANT         19   // constant value inappropriate
#define MCERR_NOT_INITIALIZED  30   // feature not initialized

//
//  MCERRMASK_IO group errors
//                                
#define MCERR_UNKNOWN_REPLY    20   // unexpected or unknown reply 
#define MCERR_NO_REPLY         21   // controller failed to reply 
#define MCERR_REPLY_SIZE       22   // reply size incorrect
#define MCERR_REPLY_AXIS       23   // wrong axis for reply 
#define MCERR_REPLY_COMMAND    24   // reply is for different command
#define MCERR_TIMEOUT          25   // controller failed to respond
#define MCERR_BLOCK_MODE       26   // block mode error
#define MCERR_COMM_PORT        27   // communications port (RS232) error
#define MCERR_CANCEL           28   // operation was canceled
#define MCERR_NOT_FOUND        29   // restore operation could not find data
#define MCERR_SOCKET           32	// tcp/ip socket error

//
//  Types. We define some windows types if they aren't already defined so that
//  this header file may be used with environments like LabWindows/CVI or under unix-like
//  (i.e. linux) operating systems
//
typedef short int HCTRLR;

#ifndef _WINDEF_
  typedef long LONG;
  typedef unsigned short WORD;
  typedef unsigned long DWORD;
  typedef unsigned int UINT;
  typedef void* HANDLE;
  typedef HANDLE HINSTANCE;
  typedef unsigned long HWND;
  typedef void* LPVOID;
  typedef char CHAR;
  typedef CHAR *LPSTR;
  typedef const CHAR *LPCSTR;
#endif

#ifndef APIENTRY
  #ifdef _WIN32
  	#define APIENTRY __stdcall
  	#define PASCAL __stdcall
	#define CALLBACK __stdcall
  #else							// non-windows os
  	#define APIENTRY
  	#define PASCAL
	#define CALLBACK
  #endif
#endif


//
//  Data structures (set packing to 4-byte). Note that the MSDN documentation for this 
//  pragma is not correct (but our usage here is correct)!
//
#pragma pack(push,4)

//
//  Axis configuration structure
//
typedef struct _MCAXISCONFIG {
	int			cbSize;
	int			ModuleType;
	int			ModuleLocation;
	int			MotorType;
	int			CaptureModes;
	int			CapturePoints;
	int			CaptureAndCompare;
	double		HighRate;
	double		MediumRate;
	double		LowRate;
	double		HighStepMin;
	double		HighStepMax;
	double		MediumStepMin;
	double		MediumStepMax;
	double		LowStepMin;
	double		LowStepMax;
	int			AuxEncoder;				// added v3.4.0, axis has auxiliary encoder input
} MCAXISCONFIG;

//
//  Commutation parameters structure
//
typedef struct _MCCOMMUTATION {
	int			cbSize;
	double		PhaseA;
	double		PhaseB;
	int			Divisor;
	int			PreScale;
	int			Repeat;
} MCCOMMUTATION;

//
//  Contouring parameters structure
//
typedef struct _MCCONTOUR {
	double		VectorAccel;
	double		VectorDecel;
	double		VectorVelocity;
	double		VelocityOverride;
} MCCONTOUR;

//
//  PID Filter parameters structure (extended)
//
typedef struct _MCFILTEREX {
	int			cbSize;
	double		Gain;
	double		IntegralGain;
	double		IntegrationLimit;
	int			IntegralOption;
	double		DerivativeGain;
	double		DerSamplePeriod;
	double		FollowingError;
	double		VelocityGain;
	double		AccelGain;
	double		DecelGain;
	double		EncoderScaling;
	int			UpdateRate;
	double		PositionDeadband;		// added v3.5.0
	double		DelayAtTarget;			// added v3.5.0
	double		OutputOffset;			// added v3.5.0
	double		OutputDeadband;			// added v3.5.0
} MCFILTEREX;

//
//  PID Filter parameters structure (new programs should use MCFILTEREX)
//
typedef struct _MCFILTER {
	double		DerivativeGain;
	double		DerSamplePeriod;
	double		IntegralGain;
	double		IntegrationLimit;
	double		VelocityGain;
	double		AccelGain;
	double		DecelGain;
	double		FollowingError;
} MCFILTER;

//
//  Jog control parameters structure (added in version 4.1.0)
//
typedef struct _MCJOGEX {
	int			cbSize;
	double		Acceleration;
	double		MinVelocity;
	double		Deadband;
	double		Gain;
	double		Offset;
	int			Channel;
} MCJOGEX;

//
//  Jog control parameters structure (new programs should use MCJOGEX)
//
typedef struct _MCJOG {
	double		Acceleration;
	double		MinVelocity;
	double		Deadband;
	double		Gain;
	double		Offset;
} MCJOG;

//
//  Motion parameters structure (extended)
//
typedef struct _MCMOTIONEX {
	int			cbSize;
	double		Acceleration;
	double		Deceleration;
	double		Velocity;
	double		MinVelocity;
	int			Direction;
	double		Torque;
	double		Deadband;
	double		DeadbandDelay;
	int			StepSize;
	int			Current;
	int			HardLimitMode;
	int			SoftLimitMode;
	double		SoftLimitLow;
	double		SoftLimitHigh;
	int			EnableAmpFault;
} MCMOTIONEX;

//
//  Motion parameters structure (new programs should use MCMOTIONEX)
//
typedef struct _MCMOTION {
	double		Acceleration;
	double		Deceleration;
	double		Velocity;
	double		MinVelocity;
	short int	Direction;
	double		Gain;
	double		Torque;
	double		Deadband;
	double		DeadbandDelay;
	short int	StepSize;
	short int	Current;
	short int	HardLimitMode;
	short int	SoftLimitMode;
	double		SoftLimitLow;
	double		SoftLimitHigh;
	short int	EnableAmpFault;
	short int	Rate;
} MCMOTION;

//
//  Controller configuration structure (extended)
//
typedef struct _MCPARAMEX {
	int			cbSize;
	int			ID;
	int			ControllerType;
	int			NumberAxes;
	int			MaximumAxes;
	int			MaximumModules;
	int			Precision;
	int			DigitalIO;
	int			AnalogInput;
	int			AnalogOutput;
	int			PointStorage;
	int			CanDoScaling;
	int			CanDoContouring;
	int			CanChangeProfile;
	int			CanChangeRates;
	int			SoftLimits;
	int			MultiTasking;
	int			AmpFault;
	double		AnalogInpMin;			// added v3.4.0, motherboard analog inp min voltage	
	double		AnalogInpMax;			// added v3.4.0, motherboard analog inp max voltage	
	int			AnalogInpRes;			// added v3.4.0, motherboard analog inp resolution (bits)
	double		AnalogOutMin;			// added v3.4.0, motherboard analog out min voltage	
	double		AnalogOutMax;			// added v3.4.0, motherboard analog out max voltage	
	int			AnalogOutRes;			// added v3.4.0, motherboard analog out resolution (bits)
	int			OutputMode;				// added v3.5.0, supports MCGetModuleOutputMode()
	int			AtTarget;				// added v3.5.0, supports position deadband and delay at target
	int			OutputControl;			// added v3.5.0, supports output offset and output deadband
	int			LineModeAscii;			// added v4.1.3, can accept line oriented ASCII (e.g. TCP/IP controllers) 
} MCPARAMEX;

//
//  Controller configuration structure (new programs should use MCPARAMEX)
//
typedef struct _MCPARAM {
    short int	ID;
    short int	ControllerType;
    short int	NumberAxes;
    short int	DigitalIO;
    short int	AnalogInput;
    short int	AnalogOutput;
    short int	AxisType[8];
    short int	PointStorage;
    short int	CanDoScaling;
    short int	CanDoContouring;
    short int	CanChangeProfile;
    short int	CanChangeRates;
    short int	SoftLimits;
    short int	MultiTasking;
    short int	AmpFault;
} MCPARAM;

//
//  Scaling factors data structure
//
typedef struct _MCSCALE {
    double		Constant;
    double		Offset;
    double		Rate;
    double		Scale;
    double		Zero;
    double		Time;
} MCSCALE;

//
//  Status word data structure
//
typedef struct _MCSTATUSEX {
	int			cbSize;
	DWORD		Status;
	DWORD		AuxStatus;
	DWORD		ProfileStatus;
	DWORD		ModeStatus;
} MCSTATUSEX;

//
//  Restore default packing
//
#pragma pack(pop)

#ifdef __cplusplus
  extern "C" {
#endif 

//
//  Interrupt callback function typedef
//
typedef void (CALLBACK* MCINTERRUPTPROC)(HWND, HCTRLR, WORD, DWORD);

//
//  API Function Prototypes
//
extern void (APIENTRY*		MCAbort)(HCTRLR hCtlr, WORD axis);
extern int (APIENTRY*		MCArcCenter)(HCTRLR hCtlr, WORD axis, short int type, double position);
extern int (APIENTRY*		MCBlockBegin)(HCTRLR hCtlr, int mode, int num);
extern int (APIENTRY*		MCBlockEnd)(HCTRLR hCtlr, int* taskID);
extern int (APIENTRY*		MCCancelTask)(HCTRLR hCtlr, int taskID);
extern int (APIENTRY*		MCCaptureData)(HCTRLR hCtlr, WORD axis, int points, double period, double delay);
extern short int (APIENTRY*	MCClose)(HCTRLR hCtlr);
extern short int (APIENTRY*	MCConfigureDigitalIO)(HCTRLR hCtlr, WORD channel, WORD mode);
extern int (APIENTRY*		MCContourDistance)(HCTRLR hCtlr, WORD axis, double distance);
extern int (APIENTRY*		MCContourPath)(HCTRLR hCtlr, WORD axis, WORD mode, char* buffer);
extern int (APIENTRY*		MCDecodeStatus)(HCTRLR hCtlr, DWORD status, int bit);
extern void (APIENTRY*		MCDirection)(HCTRLR hCtlr, WORD axis, WORD dir);
extern void (APIENTRY*		MCEnableAxis)(HCTRLR hCtlr, WORD axis, short int state);
extern int (APIENTRY*		MCEnableBacklash)(HCTRLR hCtlr, WORD axis, double backlash, short int state);
extern void (APIENTRY*		MCEnableDigitalIO)(HCTRLR hCtlr, WORD channel, short int state);
extern void (APIENTRY*		MCEnableGearing)(HCTRLR hCtlr, WORD axis, WORD master, double ratio, short int state);
extern void (APIENTRY*		MCEnableJog)(HCTRLR hCtlr, WORD axis, short int state);
extern void (APIENTRY*		MCEnableSync)(HCTRLR hCtlr, WORD axis, short int state);
extern void (APIENTRY*		MCErrorNotify)(HWND hWnd, HCTRLR hCtlr, DWORD errormask);
extern int (APIENTRY*		MCFindEdge)(HCTRLR hCtlr, WORD axis, double position);
extern int (APIENTRY*		MCFindIndex)(HCTRLR hCtlr, WORD axis, double position);
extern int (APIENTRY*		MCGetAccelerationEx)(HCTRLR hCtlr, WORD axis, double* acceleration);
extern WORD (APIENTRY*		MCGetAnalog)(HCTRLR hCtlr, WORD channel);
extern int (APIENTRY*		MCGetAuxEncIdxEx)(HCTRLR hCtlr, WORD axis, double* index);
extern int (APIENTRY*		MCGetAuxEncPosEx)(HCTRLR hCtlr, WORD axis, double* position);
extern int (APIENTRY*		MCGetBreakpointEx)(HCTRLR hCtlr, WORD axis, double* breakpoint);
extern int (APIENTRY*		MCGetCaptureData)(HCTRLR hCtlr, WORD axis, int type, int start,
											  int points, double* data);
extern void (APIENTRY*		MCGetConfiguration)(HCTRLR hCtlr, MCPARAM* param);
extern short int (APIENTRY*	MCGetContourConfig)(HCTRLR hCtlr, WORD axis, MCCONTOUR* contour);
extern int (APIENTRY*		MCGetContouringCount)(HCTRLR hCtlr, WORD axis);
extern int (APIENTRY*		MCGetDecelerationEx)(HCTRLR hCtlr, WORD axis, double* deceleration);
extern short int (APIENTRY*	MCGetError)(HCTRLR hCtlr);
extern short int (APIENTRY*	MCGetDigitalIO)(HCTRLR hCtlr, WORD channel);
extern short int (APIENTRY*	MCGetFilterConfig)(HCTRLR hCtlr, WORD axis, MCFILTER* filter);
extern int (APIENTRY*		MCGetFollowingError)(HCTRLR hCtlr, WORD axis, double* error);
extern int (APIENTRY*		MCGetGain)(HCTRLR hCtlr, WORD axis, double* gain);
extern int (APIENTRY*		MCGetIndexEx)(HCTRLR hCtlr, WORD axis, double* index);
extern short int (APIENTRY*	MCGetJogConfig)(HCTRLR hCtlr, WORD axis, MCJOG* jog);
extern int (APIENTRY*		MCGetLimits)(HCTRLR hCtlr, WORD axis, short int* hardlimitmode, short int* softlimitmode,
										 double* softlimitminus, double* softlimitplus);
extern short int (APIENTRY*	MCGetMotionConfig)(HCTRLR hCtlr, WORD axis, MCMOTION* motion);
extern int (APIENTRY*		MCGetOptimalEx)(HCTRLR hCtlr, WORD axis, double* optimal);
extern int (APIENTRY*		MCGetPositionEx)(HCTRLR hCtlr, WORD axis, double* position);
extern int (APIENTRY*		MCGetProfile)(HCTRLR hCtlr, WORD axis, WORD* profile);
extern int (APIENTRY*		MCGetRegister)(HCTRLR hCtlr, int reg, void* value, int type);
extern short int (APIENTRY*	MCGetScale)(HCTRLR hCtlr, WORD axis, MCSCALE* scale);
extern int (APIENTRY*		MCGetServoOutputPhase)(HCTRLR hCtlr, WORD axis, WORD* phase);
extern DWORD (APIENTRY*		MCGetStatus)(HCTRLR hCtlr, WORD axis);
extern int (APIENTRY*		MCGetTargetEx)(HCTRLR hCtlr, WORD axis, double* target);
extern int (APIENTRY*		MCGetTorque)(HCTRLR hCtlr, WORD axis, double* torque);
extern int (APIENTRY*		MCGetTrajectoryRate)(HCTRLR, int*);
extern int (APIENTRY*		MCGetVectorVelocity)(HCTRLR hCtlr, WORD axis, double* velocity);
extern int (APIENTRY*		MCGetVelocityEx)(HCTRLR hCtlr, WORD axis, double* velocity);
extern DWORD (APIENTRY*		MCGetVersion)(HCTRLR hCtlr);
extern void (APIENTRY*		MCGo)(HCTRLR hCtlr, WORD axis);
extern void (APIENTRY*		MCGoHome)(HCTRLR hCtlr, WORD axis);
extern int (APIENTRY*		MCIndexArm)(HCTRLR hCtlr, WORD axis, double position);
extern int (APIENTRY*		MCLearnPoint)(HCTRLR hCtlr, WORD axis, int lIndex, WORD mode);
extern void (APIENTRY*		MCMacroCall)(HCTRLR hCtlr, WORD macro);
extern void (APIENTRY*		MCMoveAbsolute)(HCTRLR hCtlr, WORD axis, double position);
extern void (APIENTRY*		MCMoveRelative)(HCTRLR hCtlr, WORD axis, double distance);
extern int (APIENTRY*		MCMoveToPoint)(HCTRLR hCtlr, WORD axis, int index);
extern HCTRLR (APIENTRY*	MCOpen)(short int nID, WORD mode, LPCSTR name);
extern int (APIENTRY*		MCReopen)(HCTRLR hCtlr, WORD newmode);
extern int (APIENTRY*		MCRepeat)(HCTRLR hCtlr, int count);
extern void (APIENTRY*		MCReset)(HCTRLR hCtlr, WORD axis);
extern void (APIENTRY*		MCSetAcceleration)(HCTRLR hCtlr, WORD axis, double rate);
extern void (APIENTRY*		MCSetAnalog)(HCTRLR hCtlr, WORD channel, WORD value);
extern void (APIENTRY*		MCSetAuxEncPos)(HCTRLR hCtlr, WORD axis, double position);
extern short int (APIENTRY*	MCSetContourConfig)(HCTRLR hCtlr, WORD axis, MCCONTOUR* contour);
extern void (APIENTRY*		MCSetDeceleration)(HCTRLR hCtlr, WORD axis, double rate);
extern short int (APIENTRY*	MCSetFilterConfig)(HCTRLR hCtlr, WORD axis, MCFILTER* filter);
extern int (APIENTRY*		MCSetGain)(HCTRLR hCtlr, WORD axis, double gain);
extern short int (APIENTRY*	MCSetJogConfig)(HCTRLR hCtlr, WORD axis, MCJOG* jog);
extern int (APIENTRY*		MCSetLimits)(HCTRLR hCtlr, WORD axis, short int hardlimitmode, short int softlimitmode,
										 double softlimitminus, double softlimitplus);
extern void (APIENTRY*		MCSetModuleOutputMode)(HCTRLR hCtlr, WORD axis, WORD mode);
extern short int (APIENTRY*	MCSetMotionConfig)(HCTRLR hCtlr, WORD axis, MCMOTION* motion);
extern void (APIENTRY*		MCSetOperatingMode)(HCTRLR hCtlr, WORD axis, WORD caxis, WORD mode);
extern void (APIENTRY*		MCSetPosition)(HCTRLR hCtlr, WORD axis, double position);
extern void (APIENTRY*		MCSetProfile)(HCTRLR hCtlr, WORD axis, WORD mode);
extern int (APIENTRY*		MCSetRegister)(HCTRLR hCtlr, int reg, void* value, int type);
extern short int (APIENTRY*	MCSetScale)(HCTRLR hCtlr, WORD axis, MCSCALE* scale);
extern void (APIENTRY*		MCSetServoOutputPhase)(HCTRLR hCtlr, WORD axis, WORD phase);
extern int (APIENTRY*		MCSetTimeoutEx)(HCTRLR hCtlr, double timeout, double* oldtimeout);
extern int (APIENTRY*		MCSetTorque)(HCTRLR hCtlr, WORD axis, double torque);
extern int (APIENTRY*		MCSetTrajectoryRate)(HCTRLR, int);
extern int (APIENTRY*		MCSetVectorVelocity)(HCTRLR hCtlr, WORD axis, double velocity);
extern void (APIENTRY*		MCSetVelocity)(HCTRLR hCtlr, WORD axis, double rate);
extern void (APIENTRY*		MCStop)(HCTRLR hCtlr, WORD axis);
extern void (APIENTRY*		MCWait)(HCTRLR hCtlr, double period);
extern void (APIENTRY*		MCWaitForDigitalIO)(HCTRLR hCtlr, WORD channel, short int state);
extern int (APIENTRY*		MCWaitForEdge)(HCTRLR hCtlr, WORD axis, short int state);
extern void (APIENTRY*		MCWaitForPosition)(HCTRLR hCtlr, WORD axis, double position);
extern void (APIENTRY*		MCWaitForRelative)(HCTRLR hCtlr, WORD axis, double distance);
extern void (APIENTRY*		MCWaitForStop)(HCTRLR hCtlr, WORD axis, double period);
extern void (APIENTRY*		MCWaitForTarget)(HCTRLR hCtlr, WORD axis, double period);

//
//  Low level controller access commands
//
extern short int (APIENTRY*	pmccmd)(HCTRLR hCtlr, short int size, void* buffer);
extern short int (APIENTRY*	pmcgetc)(HCTRLR hCtlr);
extern void (APIENTRY*		pmcgetram)(HCTRLR hCtlr, WORD wOffset, void* buffer, short int size);
extern short int (APIENTRY*	pmcgets)(HCTRLR hCtlr, char* buffer, short int size);
extern short int (APIENTRY*	pmcputc)(HCTRLR hCtlr, short int character);
extern void (APIENTRY*		pmcputram)(HCTRLR hCtlr, WORD offset, void* buffer, short int size);
extern short int (APIENTRY*	pmcputs)(HCTRLR hCtlr, const char* buffer);
extern short int (APIENTRY*	pmcrdy)(HCTRLR hCtlr);
extern short int (APIENTRY*	pmcrpy)(HCTRLR hCtlr, short int size, char* buffer);

#if (_MCAPI_VER >= 210)

extern int (APIENTRY*		MCGetDigitalIOConfig)(HCTRLR hCtlr, WORD channel, WORD* mode);
extern int (APIENTRY*		MCGoEx)(HCTRLR hCtlr, WORD axis, double param);
extern int (APIENTRY*		MCTranslateErrorEx)(short int nError, LPSTR buffer, int size);

#endif

#if (_MCAPI_VER >= 220)

extern int (APIENTRY*		MCArcEndAngle)(HCTRLR hCtlr, WORD axis, short int nType, double angle);
extern int (APIENTRY*		MCArcRadius)(HCTRLR hCtlr, WORD axis, double radius);
extern int (APIENTRY*		MCFindAuxEncIdx)(HCTRLR hCtlr, WORD axis, double position);
extern int (APIENTRY*		MCIsAtTarget)(HCTRLR hCtlr, WORD axis, double timeout);
extern int (APIENTRY*		MCIsStopped)(HCTRLR hCtlr, WORD axis, double timeout);
extern int (APIENTRY*		pmccmdex)(HCTRLR hCtlr, WORD axis, WORD command, void* argument, int type);
extern int (APIENTRY*		pmcrpyex)(HCTRLR hCtlr, void* reply, int type);

#endif

#if (_MCAPI_VER >= 300)

extern int (APIENTRY*		MCGetAxisConfiguration)(HCTRLR hCtlr, WORD axis, MCAXISCONFIG* axiscfg);
extern int (APIENTRY*		MCGetConfigurationEx)(HCTRLR hCtlr, MCPARAMEX* param);
extern int (APIENTRY*		MCGetInstalledModules)(HCTRLR hCtlr, int modules[], int size);

#endif

#if (_MCAPI_VER >= 310)

extern int (APIENTRY*		MCConfigureCompare)(HCTRLR hCtlr, WORD axis, double* values, int num, double inc, int mode, double period);
extern int (APIENTRY*		MCEnableCapture)(HCTRLR hCtlr, WORD axis, int count);
extern int (APIENTRY*		MCEnableCompare)(HCTRLR hCtlr, WORD axis, int count);
extern int (APIENTRY*		MCEnableDigitalFilter)(HCTRLR hCtlr, WORD axis, int state);
extern int (APIENTRY*		MCGetCount)(HCTRLR hCtlr, WORD axis, int type, int* count);
extern int (APIENTRY*		MCGetDigitalFilter)(HCTRLR hCtlr, WORD axis, double* coeff, int num, int* actual);
extern int (APIENTRY*		MCIsDigitalFilter)(HCTRLR hCtlr, WORD axis);
extern int (APIENTRY*		MCSetDigitalFilter)(HCTRLR hCtlr, WORD axis, double* coeff, int num);

#endif

#if (_MCAPI_VER >= 320)

extern int (APIENTRY*		MCEdgeArm)(HCTRLR hCtlr, WORD axis, double position);
extern int (APIENTRY*		MCGetFilterConfigEx)(HCTRLR hCtlr, WORD axis, MCFILTEREX* filter);
extern int (APIENTRY*		MCGetModuleInputMode)(HCTRLR hCtlr, WORD axis, int* mode);
extern int (APIENTRY*		MCGetMotionConfigEx)(HCTRLR hCtlr, WORD axis, MCMOTIONEX* motion);
extern int (APIENTRY*		MCGetOperatingMode)(HCTRLR hCtlr, WORD axis, int* mode);
extern int (APIENTRY*		MCIsEdgeFound)(HCTRLR hCtlr, WORD axis, double timeout);
extern int (APIENTRY*		MCIsIndexFound)(HCTRLR hCtlr, WORD axis, double timeout);
extern int (APIENTRY*		MCSetCommutation)(HCTRLR hCtlr, WORD axis, MCCOMMUTATION* commutation);
extern int (APIENTRY*		MCSetFilterConfigEx)(HCTRLR hCtlr, WORD axis, MCFILTEREX* filter);
extern int (APIENTRY*		MCSetModuleInputMode)(HCTRLR hCtlr, WORD axis, int mode);
extern int (APIENTRY*		MCSetMotionConfigEx)(HCTRLR hCtlr, WORD axis, MCMOTIONEX* motion);
extern int (APIENTRY*		MCWaitForIndex)(HCTRLR hCtlr, WORD axis);

#endif

#if (_MCAPI_VER >= 330)

extern int (APIENTRY*		MCDecodeStatusEx)(HCTRLR hCtlr, MCSTATUSEX* status, int bit);
extern int (APIENTRY*		MCEnableInterrupt)(HWND hWnd, HCTRLR hCtlr, WORD axis, DWORD mask, MCINTERRUPTPROC lpIntFunc);
extern int (APIENTRY*		MCGetStatusEx)(HCTRLR hCtlr, WORD axis, MCSTATUSEX* status);
extern int (APIENTRY*		MCInterruptOnPosition)(HCTRLR hCtlr, WORD axis, int mode, double position);

#endif

#if (_MCAPI_VER >= 340)

extern int (APIENTRY*		MCEnableEncoderFault)(HCTRLR hCtlr, WORD axis, int state);
extern int (APIENTRY*		MCGetAnalogEx)(HCTRLR hCtlr, int channel, DWORD* value);
extern int (APIENTRY*		MCGetVelocityActual)(HCTRLR hCtlr, WORD axis, double* velocity);
extern int (APIENTRY*		MCSetAnalogEx)(HCTRLR hCtlr, int channel, DWORD value);
extern int (APIENTRY*		pmcgetramex)(HCTRLR hCtlr, DWORD offset, void* buffer, DWORD size);
extern int (APIENTRY*		pmcputramex)(HCTRLR hCtlr, DWORD offset, void* buffer, DWORD size);

#endif

#if (_MCAPI_VER >= 350)

extern int (APIENTRY*		MCGetModuleOutputMode)(HCTRLR hCtlr, WORD axis, WORD* mode);
extern int (APIENTRY*		MCGetVelocityOverride)(HCTRLR hCtlr, WORD axis, double* override);
extern int (APIENTRY*		MCSetVelocityOverride)(HCTRLR hCtlr, WORD axis, double override);

#endif

#if (_MCAPI_VER >= 400)

extern int (APIENTRY*		MCGetDigitalIOEx)(HCTRLR hCtlr, WORD channel, unsigned int* state);

#endif

#if (_MCAPI_VER >= 410)

extern int (APIENTRY*		MCGetJogConfigEx)(HCTRLR hCtlr, WORD axis, MCJOGEX* jog);
extern int (APIENTRY*		MCSetJogConfigEx)(HCTRLR hCtlr, WORD axis, MCJOGEX* jog);
extern int (APIENTRY*		MCGetTrajectoryRate)(HCTRLR, int*);
extern int (APIENTRY*		MCSetTrajectoryRate)(HCTRLR, int);

#endif

#if (_MCAPI_VER >= 430)

extern int (APIENTRY*		pmccmdrpyex)(HCTRLR hCtlr, WORD axis, WORD cmd, void* arg, int arg_type, void* rpy, int rpy_type);
extern DWORD (APIENTRY*		pmclock)(HCTRLR hCtlr, DWORD wait_msec);
extern int (APIENTRY*		pmclookupvar)(HCTRLR hCtlr, const char* varname, DWORD* address);
extern void (APIENTRY*		pmcunlock)(HCTRLR hCtlr);

#endif

//
//  declared in mcapi_dl.cpp
//
extern int					MCLoadApi(void);

#ifdef __cplusplus
  }
#endif 

#endif			// MCAPI_DL_H
