/*
*********************************************************************************************************
*                                                ADT8949G1
*                                       The Motion Control PCI Card
*
*                                 (c) Copyright 2002-2014, ADTECH, Shenzhen, 
*                                           All Rights Reserved
*
*
* By      : ADTECH R&D 
* Remark  :
  1¡¢ADT8949 is a slow device for computers£¬Any query API can have some effect on the performance of motion computation£¬
     To reduce the number of interrupt control cards£¬Minimize query operation£¬For continuous query insert a Sleep (1)
	 statement for the two query intermediate recommendation.Also, for example, the drive state of the shaft is obtained, 
	 using get_status_all (... )For consolidationOperation, the status of all axes, then determine the status of the drive
	 shaft by bit values.
*********************************************************************************************************
*/

#ifndef	_ADT8949G1_H__
#define	_ADT8949G1_H__

typedef void (*FUNCTION)();

/*****************DLL error*****************/
#define ERR_FAIL				0xffffffff
#define ERR_SUCCESS				0x00000000
#define ERR_OVERTIME			0x00010000
#define ERR_CARDNOEXIST			0x00020000 
#define ERR_ARCMAP				0x00030000			//Arc axis selection error
#define ERR_FIFOFULL			0x00040000			//Buffer full error
#define ERR_ARCNOEXIST			0x00050000			//The arc is not there, the parameters of the arc can not reasonably also lead to the wrong number of the newspaper
#define ERR_DSP_CRC_FAIL		0x00060000			//DSP program verification
#define ERR_DSP_VERSION_FAIL	0x00070000			//Firmware version and DLL do not match, or firmware exception, can not identify, need to send the factory upgrade, or use the old version of DLL
#define ERR_DATALEN_DISACCORD	0x00080000			//The communication data length is not consistent, possibly PCI contact bad or the hardware abnormal
#define ERR_DATATIMEOUT			0x00090000			//Communication timeout, possibly PCI contact with bad or hardware exceptions
#define ERR_COLLECT_FAIL		0x000a0000			//The failure of the acquisition may be the last collection of tasks not yet completed¡£
#define ERR_NURBSMAP			0x000b0000			//NURBS axis selection error
#define ERR_NURBSNOEXIST		0x000c0000			//NURBS does not exist, the parameters of the NURBS will not reasonably lead to no errors of the newspaper.
#define ERR_NURBSNOSPACE		0x000d0000			//PC storage space is insufficient for NURBS interpolation
#define ERR_SERIES_FAIL			0x000f0000			//The card series error, call the function is the card belongs to the series does not contain the function

/*****************Termination error*****************/
#define	_ERR_NO_ERR				0x0000
#define _ERR_REDEF_AXIS			0x8001
#define _ERR_MOTION				0x8002
#define _ERR_MOTION2			0x8003
#define _ERR_PTPMOTION			0x8004
#define _ERR_INPMOTION			0x8005
#define _ERR_CALCUERR1			0x8006
#define _ERR_INPQAERR1			0x8007
#define _ERR_MQERR				0x8008
#define _ERR_TQ0ERR				0x8009
#define _ERR_TQ1ERR				0x800a
#define _ERR_TQ2ERR				0x800b
#define _ERR_TQ3ERR				0x800c
#define _ERR_EMGN				0x800d

/*****************Warning error*****************/
#define _ERR_PARAM				0x0001
#define	_ERR_AXISSTOP			0x0002
#define	_ERR_MOTIONCONFLICT		0x0003

#define SUCCESSFUL				ERR_SUCCESS
#define SUCCESS					ERR_SUCCESS
#define ERROR_FLAG				ERR_FAIL
#define FAIL					ERR_FAIL

#define INT8U	unsigned char
#define INT16U	unsigned short 
#define INT32U	unsigned int
#define INT8S	char
#define INT16S	short int
#define INT32S	int

#define MAXCARDNUMBER		10				//Maximum support 10 control cards
#define MAX_AXIS			4				//Define the number of axis
#define PAI                 3.1415927f		//The value of PI

#define	X_AXISREG			1				//Axis X
#define	Y_AXISREG			2				//Axis Y
#define	Z_AXISREG			3				//Axis Z
#define	A_AXISREG			4				//Axis A
#define INPA_AXISREG		0x3f			//The Interpolation axis number

/************************************************
Function£º     Initialize motion card
Returns£ºreturn>0£¬Return value is the quantity of adt-8949 cards in the system¡£
Value 3 indicate that three cards have been installed and available card number are 0¡¢ 1 and 2£¬
return=0£¬Value 0 indicates that no adt8949 card has been installed£»
return<0£¬value -1 indicates that the drivers of adt-8949 card haven't been installed
                -2 Indicates faulty PCI bridge
                -3 Indicates that DSP program download error
                -4 indicate hardware error or mismatched dll version
                -5 failed to create the mutex
                -6 open the mutex failed
                -7 other anomailes
************************************************/
int _stdcall adt8949_initial(void);

/************************************************
Function£ºrelease the sources of the motion card
Return£º0 success ,-1 failure
Remarks£ºwhen call the function£¬motion card will reset£¬clear all the motion command£¬and clear all the output£»
when program with VB6.0 , the execute program will exit abnormal without this API
************************************************/
int _stdcall adt8949_close_card(void);
 
/************************************************
Function£ºGet the version of library function
Return£ºthe version number of the library function
Remarks£º8949G1Drive library version number and firmware version number two version information, 
the same firmware version there may be a different driver library distribution, so once the problem back to pay 
attention to the two versions of the information.adt8949 has library version and firmware version, 
one firmware version may has many library version, so, please notice the two version
************************************************/
int _stdcall adt8949_get_lib_version(void);

/************************************************
Function£ºGet current firmware version
Para: cardno : Card number
Return£ºReturn value contains the information of firmware version and card ID.
The first five digits indicate card DIP ID.The last 27 digits indicate the firmware version
Remarks£º ADT-8949 has driver library version number and firmware version number. 
The same firmware version may have different driver library version, so pay attention to the information of both version numbers for problem tracing.
************************************************/
int _stdcall adt8949_get_firmware_ver(int cardno);

/************************************************
Function£º access to current available card number dial the code switch
Parameter£ºnum  available card number pointer index   number dial the code switch
Return   0£ºcorrect     non-zero: error
Remarks£º After the success of the initialization can call this function to get dial the code switch;
In accordance with the order of the close to the CPU, dial the code switch, arranged in order, 
such as the index [0] represent the most close to the CPU dial the code switch, index [1] second,...
************************************************/
int _stdcall adt8949_get_card_index(int *num,int index[10]);

/****************************************************
Function£ºGet the latest error number of the system
Parameter settings£º
       cardno      Card number
       ErrNum      Pointer of the system error number
Remark: Get system error number regularly, and view the running of the motion card
******************************************************/
int _stdcall adt8949_get_syserr(int cardno,int *ErrNum);

/********************************************************
Function£ºread the communication error
Parameter£º
        cardno     card number
        type       0: Control card terminal           1£º patch panel
ErrCount      Communication error number pointer
Return         0£ºcorrect                               non-zero: error
Remarks£º Control card with patch panel in the case of power cuts can make mistake number zero
Communication error number is not zero does not mean control card output error, check failures communication data automatically.
*********************************************************/
int _stdcall adt8949_get_communication_err(int cardno,int type,int *ErrCount);

/****************************************************
Function£ºReset motion card
Parameter£º
cardno      card number
Return             0£ºcorrect           -1£ºwrong
After calling this function, the control will clear all cache events and motion instruction data; 
if synchronized axis has been set, the synchronization relationship of axes will also be cleared, 
but limit, acceleration, gear ratio and other motion parameters that have been set won't be cleared, and do not need to re-set;
When the machine has external emergency stop, positive/negative limit or abnormal stop, or before cache interpolation of large 
amount of data, it is recommended to call the function to reset the control card.	   
******************************************************/
int _stdcall adt8949_reset_card(int cardno);

/************************************************
Function: Set total speed rate
Parameter:
      cardno       Card number
      rate         Rate (0~2.0)
Return: 0 correct,-1 wrong
Remarks: Refresh immediately; if the rate of change is too large, it will cause speed step;
the ideal method is to set timing gradually to produce a deceleration effect; when the rate is set to 0, the effect is equivalent to suspend.
***********************************************/
int _stdcall adt8949_set_rate1(int cardno,float rate);

/***************************************************************
Function:  Set speed rate of each axis
Parameter:
       cardno      Card number
       axis        Axis number :Ax,Ay,Az,Aa,INPA_AXISREG, INPB_AXISREG
       rate        Rate (0~2.0)
Return: 0 correct , -1 wrong
Remarks£ºRemark: After calling this function, the speed rate of the axis will refresh immediately, so if the rate of change is too large,
it will cause speed step; the ideal method is to set timing gradually to produce a deceleration effect.
****************************************************************/
int _stdcall adt8949_set_rate2(int cardno,int axis,float rate);

/*****************************************************************
Function:  Set the electronic gear ratio of each axis,
Parameter:
       cardno      Card number
       axis        Axis number (1-4)
       gear        Gear ratio(1-10000)£¬the pulses corresponding to 1mm Default: 1000, i.e. 1000 pulses moves 1mm
Return: 0 correct, -1 wrong
Remarks£ºGear ratio value for floating point number
******************************************************************/
int _stdcall adt8949_set_gear(int cardno, int axis,float gear);

/**********************************************************
Function:  Axis cache position and logic position synchronization
Parameter:
       cardno      Card number
       axismap     Axis mapping bit£¬bit0 indicate axis 1£¬bit1 indicate axis 2£¬bit2 indicate axis 3£¬bit3 indicate axis 4
Return: 0 correct,-1 wrong
Remarks£ºSet after zeroing and tool setting and before one group of interpolation motion to improve accuracy. Do not set when the machine is in motion.
**********************************************************/
int _stdcall adt8949_set_syncpos(int cardno, int axismap);


/*************************************************
Function£ºSet the work mode of output pulse
Parameter£º
       cardno      Card number
       axis        Axis number (1-4)
       value       0£ºpulse + pulse   1£ºpulse + direction  2£º90¡ãPhase difference 2 phase pulse encoder (simulation) A + B phase
        logic       0£º positive logic pulse             1£ºnegative logic pulse
       dir_logic   0£ºpositive logic direction signal   1£ºnegative logic direction signal
Return             0£ºcorrect                              -1£ºwrong
Default modes£ºpulse + direction£¬positive logic pulse£¬positive logic direction signal
**************************************************/
int _stdcall adt8949_set_pulse_mode(int cardno,int axis,int value,int logic,int dir_logic);


/*************************************************
Function£ºSet the working mode of actual position counter (encoder input)
Parameter£º
       cardno      Card number
       axis        Axis number (1-4),
       value       0£ºA/B pulse input      1£ºup/down (PPIN/PMIN) pulse input
       dir_logic   count direction£¬0: input signal direction positive logic,   1: input signal direction negative logic
Return             0£ºcorrect              -1£ºwrong
Default modes£ºA/B pulse input £¬input signal direction positive logic
Remarks£ºWhen it is set to A/B phase pulse input, the pulse count is the data by 4 times frequency multiplication
**************************************************/
int _stdcall adt8949_set_actual_count_mode(int cardno, int axis, int value,int dir_logic);


/****************************************************
Function£ºSet the mode of positive/negative limit input signal nLMT
Para£º
cardno     card number
axis           axis number(1-4)
v1          0£ºpositive limit valid                      1£ºpositive limit invalid
v2          0£ºnegative limit valid                      1£ºnegative limit invalid
logic       0£ºlow level valid                      1£ºhigh level valid
Return                 0£ºsuccess                                 1£ºfailure
default modes£ºpositive limit valid £¬negative limit valid £¬low level valid
*****************************************************/
int _stdcall adt8949_set_limit_mode(int cardno,int axis,int v1,int v2,int logic);

/****************************************************
Function£ºSet positive/negative limit mode
Parameter£º
       cardno      Card number
       axis        Axis number (1-4)
       v           0£ºInactive                 1£ºActive
       logic       0£ºLow level active         1£ºHigh level active
       admode      0£ºDeceleration stop        1£ºImmediate stop
Return             0£ºcorrect                  -1£ºwrong
Default modes£º stop0 inactive
Remarks£ºstop0 signal is mechanical origin , XHM/IN12, YHM/IN13, ZHM/IN14, AHM/IN15
*****************************************************/
int _stdcall adt8949_set_stop0_mode(int cardno,int axis,int v,int logic,int admode);

/****************************************************
Function£ºSet positive/negative limit mode
Parameter£º
       cardno      Card number
       axis        Axis number (1-4)
       v           0£º Inactive                        1£ºActive
       logic       0£ºLow level active                 1£ºHigh level active
       admode          0£ºDeceleration stop            1£ºImmediate stop
Return                 0£ºcorrect                      -1£ºwrong
Default modes£º Inactive
Remarks£ºstop1 is servo origin or Z-phase signal, IN44, IN45, IN46, IN47
******************************************************/
int _stdcall adt8949_set_stop1_mode(int cardno,int axis,int v,int logic,int admode);


/****************************************************
Function£ºset soft limit mode
Parameter£º
       cardno                  card number
       axis                    axis(1-4)
       EnableFlag      0£ºinvalid                 1£ºvalid
       Ppos                   Positive direction trigger position, the unit is mm

       Npos                    Negative direction trigger position, the unit is mm

       admode                  0£º deceleration stop          1£ºimmediate stop
Return                         0£ºcorret                 -1£ºwrong
Default modes£ºsoft limit invalid
*****************************************************/
int _stdcall adt8949_set_softlimit_mode(int cardno,int axis,int EnableFlag,float Ppos,float Npos,int admode);

/****************************************************
Function£ºSet input signal mode (including positive/negative limit, home)
Parameter£º
       cardno      Card number
       axis        Axis number (1-4)
       mode        0: Positive limit, 1: Negative limit      2£ºHome (or encoder Z phase signal)
       port        Input port number quickly (0-18, 36-47), 255or -1:
                   Set corresponding mode to inactive; in addition,
                   the corresponding ports of encoder signals (phase A, B & Z) of the four driving axes:
                   IN36¡«IN39:     A1...A4
                   IN40¡«IN43:     B1...B4
                   IN44¡«IN47:     Z1...Z4
       logic       Active voltage level: 0: Low level active,  1: High level active
       admode      Whether use deceleration when limit is active, 0: deceleration stop; 1: immediate stop
Return                 0£ºcorrect                                -1£ºwrong
Remarks£ºTo facilitate the setting of machine limit, home, and servo phase-Z signal, the following functions have been packaged: adt8949_set_limit_mode(¡­), adt8949_set_stop0_mode(¡­), adt8949_set_stop1_mode(¡­)
         The default mode is: Positive limit low level active, negative limit low level active, home signal (or encoder Z-phase signal) inactive;
         Positive and negative limit temporarily support the immediate stop mode only;
         The home or encoder Z-phase signal mode used for homing can't be enabled at the same time. You can set homing first and then reset encoder Z-phase.
*****************************************************/
int _stdcall adt8949_set_input_mode(int cardno,int axis,int mode,int port,int logic,int admode);

/****************************************************
Function£ºset the mode of hardstop signal
Parameter£º
       cardno      Card number
       port        input port number quickly (0-18, 36-47), 255 or -1: set corresponding mode to inactive
       logic       active voltage level   0: Low level active, 1: High level active
Return             0£ºcorrect                                -1£ºwrong
Remarks£ºRemark: Emergency stop is inactive by default. Once external emergency stop is active, you need to call adt8949_reset_card(¡­) to reset the motion card,
or else the calling of any motion instruction will be inactive even if the emergency stop active level has been canceled.
*****************************************************/
int _stdcall adt8949_set_emergency_stop_mode(int cardno,int port,int logic);


/*************************************************
Function£ºSet the position latch function
Parameter£º
       cardno      card number
       axis           Shaft number (1-4), of which the corresponding shaft specified port is:
                                       1axis:IN12
                                       2axis:IN13
                                       3 axis: IN14
                                       4 axis: IN15
       logic          Effective level, single along when change: 0 means from high to low, 1 from low to high
                     Double along the vt: 0 indicates the change from high to low for the first time, second time along the change from low to high; 1 for the first time along the change from low to high, the second time along the change from high to low
       type            1Single along the latches change, 2 pairs along the latches
Return                 0£ºcorrect -1£ºerror
Default modes£ºLatch function is invalid
Remarks£ºPosition latch function when triggered, will at the same time record down the variation signal at the time of the logic and the actual location.
         The function is enabled, the limit of time, if the location of the need to capture the change occurs again, need to ensure that cleared the last time the latch state, and enable the position latch function again.
*****************************************************/
int _stdcall adt8949_set_lock_position(int cardno,int axis,int logic,int type);


/*************************************************
Function£ºGet the driving status of each axis
Parameter£º
       cardno      Card number
       axis        Axis number (1-4)
       v           Pointer of driving status
                   0£º Driving ends                             1£ºDriving
Return             0£ºcorrect                               -1£ºwrong
Remarks£ºThis function is used to query API. For consecutive query, insert a Sleep(1) sentence between two queries
*****************************************************/
int _stdcall adt8949_get_lock_status(int cardno,int axis,int type,int *v);

/*************************************************
Function£ºTo obtain position latched position
Parameter£º
       cardno     card number
       axis            axis number (1-4), of which the corresponding shaft specified port is:
                                       1 axis:IN12
                                       2axis:IN13
                                       3axis:IN14
                                       4axis:IN15
       type            0x10£ºSaid to get logical location for the first time along the change occurs
                               0x11£ºshow get the actual position for the first time along the change occurs
                               0x20£ºshow obtain second time along the change occurs in the logic of the position (for double edge position latch)
                               0x21£ºshow  get second time along the change occurs when the actual location of the (for double along the position latch)
       pos                     To obtain a pointer to the position
Return                 0£ºcorrect     -1£ºerror
*****************************************************/
int _stdcall adt8949_get_lock_position(int cardno,int axis,int type,long *pos);


/*************************************************
Function£ºRemove lock state
Parameter£º
       cardno      card number
       axis          axis  number (1-4), of which the corresponding shaft specified port is:
                                       1 axis:IN12
                                       2 axis:IN13
                                       3 axis:IN14
                                       4 axis:IN15
Return                 0£ºcorrect                                -1£ºerror
*****************************************************/
int _stdcall adt8949_clr_lock_status(int cardno,int axis);


/*************************************************
Function£ºSet extension position latch function
Parameter£º
       cardno     card number
       axis            The axis number(1-4)
       port            Port(17-18)
       logic           Effective level, single along when change: 0 means from high to low, 1 from low to high
                                                Double along the vt: 0 indicates the change from high to low for the first time, second time along the change from low to high; 1 for the first time along the change from low to high, the second time along the change from high to low
       type           1 single along the latches, 2 said double along the latches
Return                 0£ºcorrect                                -1£ºerror
Default modes£ºLatch function is invalid
Remarks£ºPosition latch function when triggered, will at the same time record down the variation signal at the time of the logic and the actual location.
         The function is enabled, the limit of time, if the location of the need to capture the change occurs again, need to ensure that cleared the last time the latch state, and enable the position latch function again.
*****************************************************/
int _stdcall adt8949_set_EXlock_position(int cardno,int axis,int port,int logic,int type);


/*************************************************
Function£ºFor extended position latched condition
Parameter£º
       cardno      card number
       port           port(17-18)
       type            1 said to get first along the position latch state change, 2 said along the change will require a second position when the latch state (for double edge position latch)
       v                       0: latches action did not happen, 1: latch action has occurred
Return                 0£ºcorrect                               -1£ºerror
*****************************************************/
int _stdcall adt8949_get_EXlock_status(int cardno,int port,int type,int *v);


/*************************************************
Function£ºAccess to extension position latched position
Parameter£º
       cardno     card number
       port            port(17-18)
       type            0x10£ºshow  get logical location for the first time along the change occurs
                               0x11£ºshow get the actual position for the first time along the change occurs
                               0x20£ºshow get second position along the logic of change occurs along the change (for double position latches)
                               0x21£ºshow get second time along the change occurs when the actual location of the (for double along the position latch)
       pos                    To obtain a pointer to the position
Return                 0£ºcorrect                              -1£ºerror
*****************************************************/
int _stdcall adt8949_get_EXlock_position(int cardno,int port,int type,long *pos);


/*************************************************
Function£ºClear extension latch state
Parameter£º
       cardno      card number
       port            port(17-18)
Return                 0£ºcorrect                                -1£ºerror
*****************************************************/
int _stdcall adt8949_clr_EXlock_status(int cardno,int port);


/****************************************************
Function: Set the filter level of input signal, The default mode is no filter for all input signals.
Parameter£º
       cardno      Card number
       gp           Input signal types
                    0: limit, home, common IO
                    1: encoder signal(A, B, Z)
       grade        Range: 0-15. 0 indicates no filter; if it is set to n, the filter time is 2 (n-1) us
Return                 0£ºcorrect                                -1£ºwrong
Remarks£ºThe default mode for all input signal filtering. This function is effective to check the firmware version.
*****************************************************/
int _stdcall adt8949_set_input_filter(int cardno,int gp,int grade);



//----------------------------------------------------//
//            Drive the state examination function   //
//----------------------------------------------------//

/*****************************************************
Function£ºGet the driving status of each axis
Parameter£º
       cardno      Card number
       axis        Axis number (1-4)
       v           Pointer of driving status
                   0£º Driving ends                             1£ºDriving
Return             0£ºcorrect                               -1£ºwrong
Remarks£ºThis function is used to query API. For consecutive query, insert a Sleep(1) sentence between two queries
******************************************************/
int _stdcall adt8949_get_status(int cardno,int axis,int *v);

/*****************************************************
Function£ºGet driving status of all axes
Parameter£º
       cardno      Card number
       v           Pointer of driving status£¬bit0¡«bit3 axis1¡«axis4£¬bit15 indicate INPA_AXISREG
                   0£ºDriving ends                             1£ºDriving
Return             0£ºcorrect                                  -1£ºwrong
Remarks£ºThis function is used to query API. For consecutive query, insert a Sleep(1) sentence between two queries
******************************************************/
int _stdcall adt8949_get_status_all(int cardno,int *v);

/*****************************************************
Function£ºGet driving status of interpolation
Parameter£º
       cardno      Card number
       v           Pointer of driving status
                   0£ºriving ends                            1£ºDriving
Return             0£ºcorrect                               -1£ºwrong
Remarks£ºThis function is used to query API. For consecutive query, insert a Sleep(1) sentence between two queries
*****************************************************/
int _stdcall adt8949_get_inp_status(int cardno,int *v);

/*****************************************************
Function£ºFunction: Get stop data of each axis
Parameter£º
       cardno      Card number
       axis        Axis number (1-4)
       value       Pointer of stop data (0: no error stop; non-0: has limit, home or encoder Z phase signal triggers stop):
                   bit0==1: positive limit triggers stop
                   bit1==1: negative limit triggers stop
                   bit2==1: home signal triggers stop
                   it3==1: encoder Z phase signal triggers stop
                   bit4==1: external emergency stop signal triggers stop
Return                 0£ºcorrect                                -1£ºwrong
Remarks£º    Remark: Stop data may appear in combination, e.g. if both bit0 and bit1 are 1, positive limit and negative limit are triggered, resulting in axis stop
'             For consecutive query, insert a Sleep(1) sentence between two queries, or else it will affect the efficiency of the control card.
*****************************************************/
int _stdcall adt8949_get_stopdata(int cardno,int axis,int *value);

//----------------------------------------------------//
//         Motion parameters setting function        //
//----------------------------------------------------//
/****************************************************
Function£ºSet S-shaped jerk; default: 0£¬Set axis acceleration £¬Set axis deceleration
Parameter£º
       cardno      Card number
       axis        Axis number (1-4, number of interpolation axis: INPA_AXISREG)
       jcc         Jerk: 0~10
       add         Acceleration/deceleration value (1-100000),mm/sec^2

Return                 0£ºcorrect                                 -1£ºwrong
Remarks£º    ADT-8949 supports asymmetric acceleration/deceleration; when setting acceleration, deceleration will be equal to the acceleration by default;
             therefore, to set the deceleration, place set_dec after set_acc, or else the deceleration value will be overwritten by acceleration.
*****************************************************/
int _stdcall adt8949_set_jcc(int cardno, int axis,unsigned short jcc);
int _stdcall adt8949_set_acc(int cardno, int axis,float add);
int _stdcall adt8949_set_dec(int cardno, int axis,float add);

/****************************************************
Function£ºSet axis start speed, end speed in sequence
Parameter£º
       cardno      Card number
       axis        1~4 single axis  INPA_AXISREG interpolation axis
       speed       Speed, unit: mm/sec,0.001~100000
Return                 0£ºcorrect                                 -1£ºwrong
Remarks£º     If endv is set before startv, default endv= startv
******************************************************/
int _stdcall adt8949_set_startv(int cardno, int axis,float speed);
int _stdcall adt8949_set_endv(int cardno, int axis,float speed);


/****************************************************
Function£ºSet axis acceleration/deceleration mode
Parameter£º
       cardno      Card number
       axis        Axis number (1-4, number of interpolation axis: INPA_AXISREG )
       mode        Range (0-3)
                               0 S-shaped acceleration/deceleration mode
                               1 trapezoidal acceleration/deceleration mode
                               2 exponential acceleration/deceleration mode
                               3 trigonometric acceleration/deceleration mode
Return                 0£ºcorrect                                -1£ºwrong
Remarks£ºRemark: The default option is trapezoidal acceleration/ deceleration modePoint motion and single linear interpolation can use any mode,
Single arc interpolation uses mode 1 and 3.Spline interpolation uses mode 1.
To use non-trapezoidal acceleration/deceleration mode in interpolation, ensure that the segment of pretreatment cache is zero.
******************************************************/
int _stdcall adt8949_set_admode(int cardno, int axis,unsigned short mode);

/****************************************************
Function£ºSet axis running speed
Parameter£º
       cardno      Card number
       axis        1~4 single axis INPA_AXISREG interpolation axis
       speed       Speed, unit: mm/sec,0.001~100000
Return                 0£ºcorrect                                 -1£ºwrong
******************************************************/
int _stdcall adt8949_set_speed(int cardno, int axis,float speed);


/****************************************************
Function£ºSet acceleration constraint at motion path connection
Parameter£º
       cardno      Card number
       axis        Axis number (1-4)
       add         Range (100-100000), default: 500mm/sec^2
Return                 0£ºcorrect                                -1£ºwrong
Remarks£º    In cache interpolation, it is used to set the acceleration constraint of axis; it is active in pretreatment,
               and limits the maximum speed change of each axis at the connection of line segments
             In the debugging process, constraint value can be gradually increased as long as the interpolation accuracy won't be affected,
             which will reduce machine shake in interpolation.
******************************************************/
int _stdcall adt8949_set_acc_constraint(int cardno, int axis,float add);

/****************************************************
Function£ºSet speed constraint at motion path connection
Parameter£º
cardno     Card number
axis       1~4 single axis  INPA_AXISREG interpolation axis
speed      Speed, unit: mm/sec,0.001~100000
Return                 0£ºcorrect                                -1£ºwrong
Remarks£º    This function doesn't need to be called generally.
    In special process, it is used to set the maximum axis speed at the connection of two line segments in cache interpolation; it is active in pretreatment,
    and limits the maximum speed of each axis at the connection of line segments.
******************************************************/
int _stdcall adt8949_set_speed_constraint(int cardno, int axis,float speed);


/****************************************************
Function£ºWhen using cache interpolation, set axis acceleration constraint active in pretreatment,
           and limit the maximum speed changes of each axis at the connection of line segments
Parameter£º
       cardno      Card number
       radius      Radius coefficient
       speed       Speed coefficient, range (0.01-100000 mm/sec)
Default value      Radius coefficient = 10mm, speed coefficient = 100mm/sec
Return                 0£ºcorrect                                 -1£ºwrong
Remarks            The function will be active in flat arc or spatial arc interpolation;
                   if the function is called and the actual radius is smaller than the radius coefficient, the arc speed is less limited;
                   If the actual radius is larger than the radius coefficient, the arc speed limit is greater.
                   If the actual radius is equal to the radius coefficient, the maximum speed of arc is equal to the speed coefficient.
******************************************************/
int _stdcall adt8949_set_arc_speed_clamp(int cardno, float radius,float speed);

/****************************************************
Function£ºSet logic position of axis pulse
Parameter£º
       cardno      Card number
       axis        1~4 single axis
       pos         Logic position  Set range (-2147483648~+2147483647)
Return             0£ºcorrect                                -1£ºwrong
*****************************************************/
int _stdcall adt8949_set_command_pos(int cardno, int axis,long pos);

/****************************************************
Function£ºSet actual position
Parameter£º
       cardno      Card number
       axis        Axis number(1-4)
       pos         Range (-2147483648~+2147483647)
Return             0£ºcorrect                                -1£ºwrong
******************************************************/
int _stdcall adt8949_set_actual_pos(int cardno, int axis,long pos);

//----------------------------------------------------//
//           Check function motion parameters         //
//----------------------------------------------------//

/*****************************************************
Function£ºGet the pulse count value sent by the card
Parameter£º
       cardno      Card number
       axis        1~4 single axis
       pos         Pulse count
Return                 0£ºcorrect                                 -1£ºwrong
*******************************************************/
int _stdcall adt8949_get_command_pos(int cardno,int axis,long *pos);

/*****************************************************
Function£ºGet the actual position of each axis
Parameter£º
       cardno      Card number
       axis        axis(1-4)
       pos         Pointer of actual position
Return                 0£ºcorrect                                -1£ºwrong
*****************************************************/
int _stdcall adt8949_get_actual_pos(int cardno,int axis,long *pos);

/*****************************************************
Function£ºGet current running speed of the axis (instantaneous speed)
Parameter£º
       cardno      Card number
       axis        1~4 single axis£¬INPA_AXISREG interpolation axis
       speed       Instantaneous speed, unit: mm/sec
Return                 0£ºcorrect                                 -1£ºwrong
*****************************************************/
int _stdcall adt8949_get_speed(int cardno,int axis,float *speed);

/*****************************************************
Function£ºGets the current interpolation motion index information

Parameter£º
       cardno     card number
       index       The pointer to the index information (0-65535)
Return                 0£ºcorrect                              -1£ºerror
Remarks£ºThis function is used for processing synchronous display use G code, cannot be used for precise localization of trajectory
*****************************************************/
int _stdcall adt8949_get_inp_index(int cardno,unsigned short *index);

//----------------------------------------------------//
//               Drive function                       //
//----------------------------------------------------//

/****************************************************
Function£ºSingle axis quantitative relative motion (PTP)
Parameter£º
       cardno      Card number
       axis        Axis number (1~4)
       pos      >0: positive motion, <0: negative motion, Range (+/- 9999999.999mm)
Return                 0£ºcorrect                                -1£ºwrong
*****************************************************/
int _stdcall adt8949_pmove(int cardno,int axis,float pos);

/****************************************************
Function£ºAbsolute coordinates quantitative driving, unit: mm
Parameter£º
       cardno      Card number
       axis        Axis number (1-4)
       pos         Unit: mm, (+/- 9999999.999) >0: positive driving, <0: negative driving
Return                 0£ºcorrect                                -1£ºwrong
*****************************************************/
int _stdcall adt8949_abs_pmove(int cardno,int axis,float pos);

/********************************************************************
Function£ºSingle axis continuous driving
Parameter£º
       cardno                          Card number
       axis                            Axis number (1-4)
       dir                             >0: positive driving, <0: negative driving
Return£º   0£ºcorrect                             -1£ºwrong
Note: Before writing drive command, be sure to set the speed parameters properly
********************************************************************/
int _stdcall adt8949_continue_move(int cardno,int axis,int dir);

/*****************************************************
Function£º stop in deceleration
Parameter£º
       cardno      Card number
       axis        Axis number (1~4)
Return                 0£ºcorrect                                 -1£ºwrong
Remarks£º    If the set axis participates in the interpolation, other corresponding axes in the interpolation will be decelerated to stop.
*******************************************************/
int _stdcall adt8949_dec_stop(int cardno,int axis);

/*******************************************************
Function£ºstop in sudden
Parameter£º
       cardno      Card number
       axis        Axis number (1~4)
Return                 0£ºcorrect                                 -1£ºwrong
Remarks£º    If the set axis participates in the interpolation, other corresponding axes in the interpolation will be decelerated to stop.
*********************************************************/
int _stdcall adt8949_sudden_stop(int cardno,int axis);

/*******************************************************
Function£ºSet cache segments of interpolation; default: 0
Parameter£º cardno          Card number
               prec         Preview segments(0-50)The default value is 0, the closing speed foresight;
Remarks: Buffer segment number does not represent the capacity of the cache, for small line segments, suggest set up more than 30 pieces, be helpful for the continuity of interpolation;
            Start after the pretreatment, calling function adt8949_set_acc_constraint (...). Adjust the axial acceleration constraint value, to improve processing efficiency and stability of machine tools;
              Setup is effective at a time, without having to repeat Settings.
*********************************************************/
int _stdcall adt8949_set_precount(int cardno,unsigned short prec);		


/*****************************************************
Function£ºSet follow axis
Parameter£º
       cardno      Card number
       slaveaxis   Slave axis (following master axis), Axis number (1-4)
       masteraxis  Master axis (followed by slave axis), Axis number (0-4), 0: cancel follow
Return                 0£ºcorrect                                -1£ºwrong
*******************************************************/
int _stdcall adt8949_set_follow_axis(int cardno,int slaveaxis,int masteraxis);

/*********************************************************
Function£ºQuery margin in interpolation cache zone
Parameter£º
       cardno      Card number
       len         Cache length variable to be gotten
Return                 0£ºcorrect                                NO 0£ºwrong
Remarks£ºThe interpolation cache zone has 10000 segments in total. Interpolation data and cache events are stored in different regions of the control card.
         An arc occupies four segments of cache space, and a full circle occupies eight segments of cache space. It is recommended to issue motion data when the cache margin is greater than 8 segments.
          This function is used to query API. For consecutive query, insert a Sleep(1) sentence between two queries.
*********************************************************/
int _stdcall adt8949_get_fifo_len(int cardno,int *len);

/*********************************************************
Function£ºSet four-axis interpolation instruction (relative position)
Parameter£º
       cardno      Card number
       index       index info£¬used to indicate this driving infomation£¬usually set to 0
       pos1,pos2,pos3,pos4 indicate the distance of XYZA axis  unit : mm
Return                 0£ºcorrect                                -1£ºwrong
Remarks£ºif the follow axis has setted£¬the pos of the follow axis should be set to 0£¬otherwise return failure¡£
*********************************************************/
int _stdcall adt8949_inp_move4(int cardno,unsigned short index,float pos1,float pos2,float pos3,float pos4);

/*********************************************************
Function£ºSet four-axis interpolation instruction (absolute position)
Parameter£º
       cardno      Card number
       index       index info£¬used to indicate this driving infomation£¬usually set to 0
       axismap     Axis mapping bit, bit0 indicates 1# axis, bit1 indicates 2# axis
       pos1,pos2 pos3,pos4  Absolute position of the motor

Return                 0£ºcorrect                                -1£ºwrong
note:if the follow axis has setted £¬the pos of the follow axis should be set to 0
*********************************************************/
int _stdcall adt8949_inp_abs_move4(int cardno,unsigned short index,unsigned char axismap,float pos1,float pos2,float pos3,float pos4);

/*********************************************************
Function£ºSet four-axis interpolation instruction £¨specifying motion time£©
Parameter£º
   cardno      Card number
   index       Data index, used to identify the data of the motion, generally set to 0 to
   pulse1,pulse2,pulse3,pulse4 indicate the relative distance of axis XYZW
   time        Time required by motion of the straight line, unit: ms
Return                     0£ºcorrect                                -1£ºwrong
Note: The straight line moves at constant speed within the specified time. Before calling this function, ensure that the number of preprocessing segments is zero,
       or else the call will fail;If synchronized axis is set, pos parameter of slave axis should be set to 0, or else the call will fail.
*********************************************************/
int _stdcall adt8949_time_move4(int cardno,unsigned short index,float pos1,float pos2,float pos3,float pos4,float time);

/*********************************************************
Function£ºFour-axis absolute coordinates linear interpolation (specifying motion time)
Parameter£º
       cardno      Card number
       index       Data index, used to identify the data of the motion, generally set to 0 to
       axismap      Axis mapping bit, bit0 indicates 1# axis, bit1 indicates 2# axis; if the axis is not marked, the target position will not take effect.¡£
       pulse1,pulse2,pulse3,pulse4 indicate the coordinates that axis XYZW move to
       time         Time required by motion of the straight line (non-cumulative time), unit: ms
Return                 0£ºcorrect                                -1£ºwrong
Note: The straight line moves at constant speed within the specified time. Before calling this function, ensure that the number of preprocessing segments is zero, or else the call will fail.
       If synchronized axis is set, pos parameter of slave axis should be set to 0, and axismap value doesn't need to consider the slave axis position.
*********************************************************/
int _stdcall adt8949_time_abs_move4(int cardno,unsigned short index,unsigned char axismap,float pos1,float pos2,float pos3,float pos4,float time);

/*********************************************************
Function£ºTwo-axis arc interpolation, unit: mm
Parameter£º
       cardno      Card number
       index       Data index, used to identify the data of the motion, generally set to 0 to
       axismap     Axis selection mapping flag, mark any two axes in the space for plane arc interpolation
       pos         Target point coordinates of the arc (relative to the current point)
       Center      Center coordinates of the arc (relative to the current point)
       dir         Arc direction (1: clockwise; 0: counterclockwise)
Return                 0£ºcorrect                                 Non-0£ºwrong
Remarks£ºAxismap: axis mapping. AZYX correspond to binary. 0011 indicates that X,
   Y axis participate in two-axis arc interpolation, 0110 indicates that Y, Z axis participate in two-axis arc interpolation
*********************************************************/
int _stdcall adt8949_inp_arc2(int cardno,unsigned short index,unsigned char arcmap,float pos[4],float Center[4],int dir);

/*********************************************************
Function£ºTwo shaft absolute coordinates of arc interpolation
Parameter£º
       cardno      card number
       index          Index information, used to identify the motion information, generally can be set to 0
       axismap        Shaft choose map symbol, shaft bit0 said 1, 2 axis, bit1 said... , two axes do planes can sign space circular arc interpolation
       pos                    Arc absolute coordinates of target, the unit is mm
       Center        Absolute coordinates the center of the arc, the unit is mm
       dir                     Arc direction (1 to 0 clockwise counterclockwise)
Return                 0£ºcorrect                           Non-zero: error
Remarks£ºA circular arc takes 4 period of cache space, a full circle takes 8 period of cache space
         If you call this function to draw a complete the plane of the circle, the pretreatment of the need to set a certain buffer period of number, otherwise go semicircle deceleration process occurs
*********************************************************/
int _stdcall adt8949_inp_abs_arc2(int cardno,unsigned short index,unsigned char arcmap,float pos[4],float Center[4],int dir);

/*********************************************************
Function£ºRelative coordinate interpolation based on plane circular arc
parameter£º
cardno	    card number
index	Index information, used to identify the motion information, generally can be set to 0
AxisList	Axis number (1-4)£¬The first two axes for involvement in the planar circle interpolation of axis, and after two axis for servo axis and axis list two for 0 only in the planar circle interpolation
pos			pos[0]¡¢pos[1] is the target point coordinate of circular arc£¬pos[2]¡¢pos[3]Is the target point coordinates of the moving axis,the unit is mm
center		Center point coordinate of circular arc(relative to the current point),the unit is mm
dir			Circular direction£¨1 for the clockwise 0 counterclockwise£©
Return			0£ºcorrect					Non-zero£ºerror
Remarks£ºA circular arc takes 4 period of cache space, a full circle takes 8 period of cache space
         If you call this function to draw a complete the plane of the circle, the pretreatment of the need to set a certain buffer period of number, otherwise go semicircle deceleration process occurs
*********************************************************/
int _stdcall adt8949_inp_helix2(int cardno,unsigned short index,int AxisList[4],float pos[4],float center[2],int dir);

/*********************************************************
Function£ºAbsolute coordinate interpolation based on plane circular arc
paramer£º
cardno	    card number
index		Index information, used to identify the motion information, generally can be set to 0
AxisList	Axis number (1-4)£¬The first two axes for involvement in the planar circle interpolation of axis, and after two axis for servo axis and axis list two for 0 only in the planar circle interpolation
pos			pos[0]¡¢pos[1] is the target point coordinate of circular arc£¬pos[2]¡¢pos[3]Is the target point coordinates of the moving axis,the unit is mm
center	    Center point coordinate of circular arc(relative to the current point),the unit is mm
dir			Circular direction£¨1 for the clockwise 0 counterclockwise£©
Return			0£ºcorrect					Non-zero£ºerror
Remarks£ºA circular arc takes 4 period of cache space, a full circle takes 8 period of cache space
         If you call this function to draw a complete the plane of the circle, the pretreatment of the need to set a certain buffer period of number, otherwise go semicircle deceleration process occurs.
*********************************************************/
int _stdcall adt8949_inp_abs_helix2(int cardno,unsigned short index,int AxisList[4],float pos[4],float center[2],int dir);

/*********************************************************
Function£ºThree-axis arc interpolation instruction
Parameter£º
       cardno      Card number
       index       ata index, used to identify the data of the motion, generally set to 0
       arcmap          Arc participating in axes mapping mark
       pos2            Coordinates of second point (relative to current point)
       pos3            Coordinates of third point (relative to current point)
       arc_flag        0:  arc                                1£ºcircle
Return                 0£ºcorrect                                 Non-0£ºwrong
Remarks: one segment of arc contains four segment caches
*********************************************************/
int _stdcall adt8949_inp_arc3(int cardno,unsigned short index,unsigned char arcmap,float pos2[4],float pos3[4],int arc_flag);

/*********************************************************
Function£ºThree-axis arc interpolation instruction
Parameter£º
       cardno      Card number
       index       Data index, used to identify the data of the motion, generally set to 0
       arcmap      Axis selection mapping flag, mark any two axes in the space for plane arc interpolation
       pos2        Coordinates of second point (absolute to current point)
       pos3        Coordinates of third point (absolute to current point)
       arc_flag        0: arc                                 1£ºcircle
Return                 0£ºcorrect                                 Non-0£ºwrong
Remarks£ºone segment of arc contains four segment caches
*********************************************************/
int _stdcall adt8949_inp_abs_arc3(int cardno,unsigned short index,unsigned char arcmap,float pos2[4],float pos3[4],int arc_flag);

/*********************************************************
Function£ºGet arc length of two axes
Parameter£º
       axismap        Axis selection mapping flag, mark any two axes in the space for plane arc interpolation
       pos            Target point coordinates of the arc (relative to the current point)
       Center         Center coordinates of the arc (relative to the current point)
       dir            Arc direction (1: clockwise; 0: counterclockwise)
       length         Arc length of two axes
Return                 0£ºcorrect                                Non-0£ºwrong
*********************************************************/
int _stdcall adt8949_get_arc2_length(unsigned char arcmap,float pos[4],float Center[4],int dir,float *length);


/*********************************************************
Function£ºGet arc length of three axes
Parameter£º
       arcmap          Axis selection mapping flag; up to three positions can be marked as 1, that is, support arc interpolation of up to three axes
       pos2            Second point coordinates of the arc (relative to the current point)
       pos3            Third point coordinates of the arc (relative to the current point)
       length          Arc length of three axes
       arc_flag        0: arc                               1£ºcircle
Return                 0£ºcorrect                                Non-0£ºwrong
*********************************************************/
int _stdcall adt8949_get_arc3_length(unsigned char arcmap,float pos2[4],float pos3[4],float *length,int arc_flag);


/*********************************************************
Function£ºNURBS interpolation
Parameter£º
       cardno      Card number
       index       Data index, used to identify the data of the motion, generally set to 0
       axismap     Axis selection mapping flag, only three positions can be marked to 1, that is, support NURBS interpolation up to three axes
       conp        Spline control point (relative to the current point, the coordinates of first control point should be 0, or else it will return error)
       weight      Weight corresponding to control point of spline. The weight of each control point of AutoCAD is -1 by default
       node        Node value of spline
       nodenum     Number of spline nodes
Return                 0£ºcorrect                                 Non-0£ºwrong
Remarks£ºFor NURBS interpolation, it is recommended to set a bigger number of pre-processing cache segments and use trapezoidal acceleration/deceleration mode;
         calling the function to set arc speed clamp will affect planning of spline interpolation speed;
         Using spline interpolation will occupy a larger number of cache segments of control card.
        To continue to call interpolation instruction, check the remaining cache capacity in advance.
*********************************************************/
int _stdcall adt8949_inp_NURBS(int cardno,unsigned short index,unsigned char axismap,float conp[][4],float weight[],float node[],int nodenum);


//-------------------------------------------------//
//               Switch output class               //
//-------------------------------------------------//

/*********************************************************
Function£ºGet input IO status (adt8949_read_bit)
Parameter£º
       cardno      Card number
       number      Input point (0-47), including 0 to 18, 36-47 for quick input points, 19-35 input point for the bus
                              Among them, four drive shaft encoder signal phase (A, B, Z) corresponding to the port as follows:
                                       IN36¡«IN39:     A1...A4
                                       IN40¡«IN43:     B1...B4
                                       IN44¡«IN47:     Z1...Z4
Return                 0£ºlow voltage level                1£ºhigh voltage level
*********************************************************/
int _stdcall adt8949_read_bit(int cardno,int number);

/*****************************************************
Function£ºGet output IO status (adt8949_et_out)
Parameter£º
       cardno      Card number
       number        Output point (0-31), which is suitable for rapid output points, 0 to 14 15 to 31 points for bus output
Return                Return value: the current state of the specified port, 1 said parameter error
Remarks£º
*****************************************************/
int _stdcall adt8949_get_out(int cardno, int number);

/********************************************************
Function£ºRead IO status by groups
Parameter£º
       cardno      Card number
       gp          Group number (the number of OUT0~OUT15 is 0, the number of IN0~IN15 is 0x20, the number of IN16~IN31 is 0x21)
       levelmap    Status of this group of IO (determine the status of certain IO through bit value, e.g. OUT0 corresponds to bit0, OUT15 corresponds to bit15)
Return                 0£ºcorrect                        -1£ºwrong
Remarks£ºlevelmapFor 16-bit signed short plastic data, to Mosaic the 32-bit data and on the low 16 bits, required for operation: levelmap & 0 XFFFF, lest affect high 16 bit data
*********************************************************/
int _stdcall adt8949_get_gpio(int cardno,int gp,short int *levelmap);

/********************************************************
Function£ºSet output IO status (adt8949_write_bit)
Parameter£º
       cardno      Card number
       number      Output point (0-31), which is suitable for rapid output points, 0 to 14 15 to 31 points for bus output
       value       0: close                             1: open
Return                 0£ºcorrect                         -1£ºwrong
*********************************************************/
int _stdcall adt8949_write_bit(int cardno,int number,int value);

/********************************************************
Function£ºOperate output by group
Parameter£º
       cardno      Card number
       gp          Group number
                   OUT0¡«OUT15£¬group id is 0
                   OUT16¡«OUT31£¬group id is 1
       levelmap         Voltage level setting of this group of IO (determine the status of certain output point through bit value, e.g. OUT0 corresponds to bit0, OUT15 corresponds to bit15); only the output points with iomap bit value 1 are affected
Return                 0£ºcorrect                         -1£ºwrong
*********************************************************/
int _stdcall adt8949_set_gpio(int cardno,int gp,short int levelmap);

/********************************************************
Function£ºSet voltage level for multiple output points at the same time
Parameter£º
       cardno      Card number
       gp          group number
                   OUT0¡«OUT15£¬group number is 0
                   OUT16¡«OUT31£¬group number is 1
       iomap       Specify the output point to be operated by bit (bit0~bit15); if the bit value is 1, operate corresponding output point; if the bit value is 0, output point isn't affected
       levelmap    Voltage level setting of this group of IO (determine the status of certain output point through bit value,
                   e.g. OUT0 corresponds to bit0, OUT15 corresponds to bit15); only the output points with iomap bit value 1 are affected
Return                 0£ºcorrect                         -1£ºwrong
*********************************************************/
int _stdcall adt8949_set_multi_io(int cardno,int gp,short int iomap,short int levelmap);

//-------------------------------------------------//
//            Set the cache event                  //
//-------------------------------------------------//

/*********************************************************
Function£ºQuery cache event area remaining paragraphs 1000 number
Parameter£º
       cardno     card number
       len                    A pointer to the cache event length variable to get
Return                 0£ºcorrect                                Non-zero: error
Remarks£ºInterpolation data and cache events in different areas of the control card;
        Set the cache event functions are:
                       adt8949_set_fifo_io(¡­)£¬
                       adt8949_set_fifo_multi_io(¡­)£¬
                       adt8949_set_fifo_delay(¡­)£¬
                       adt8949_set_fifo_pulser(¡­)£¬
         The function as part of the inquiry API, for continuous sci-tech novelty search, query twice middle suggest inserting a Sleep (1) statements.
*********************************************************/
int _stdcall adt8949_get_fifo_event_len(int cardno,int *len);


/********************************************************
Function£ºSingle point IO output in interpolation
Parameter£º
       cardno      Card number
       number      Output point (0-14)
       value       0: close           1: open
       speed       -1: no speed constraint before motion by default, other: range (0.0-100000.0 mm/sec)
Return                 0£ºcorrect                         -1£ºwrong
Remarks£ºSpeed setting is same as the motion track speed, and motion track won't decelerate. If the speed setting is smaller,
       the motion track will decelerate to the set speed in advance before corresponding IO operation, and then accelerate to motion track speed, and form V-shaped process.
*********************************************************/
int _stdcall adt8949_set_fifo_io(int cardno,int number,int value,float speed);

/********************************************************
Function£ºSingle point IO output in interpolation
Parameter£º
       cardno      Card number
       gp          Group number (the number of OUT0~OUT14 is 0; only output point settings of group are available)
       iomap       Specify the output point to be operated by bit (bit0~bit15); if the bit value is 1,
                   perate corresponding output point; if the bit value is 0, output point isn't affected
       levelmap    Voltage level setting of this group of IO (determine the status of certain output point through bit value,
                   e.g. OUT0 corresponds to bit0, OUT15 corresponds to bit15); only the output points with iomap bit value 1 are affected
       speed       -1: no speed constraint before motion by default, other: range (0.0-100000.0 mm/sec)
Return                 0£ºcorrect                        -1£ºwrong
Remarks£ºSpeed setting is same as the motion track speed, and motion track won't decelerate. If the speed setting is smaller,
           the motion track will decelerate to the set speed in advance before corresponding IO operation,
           and then accelerate to motion track speed, and form V-shaped process.
*********************************************************/
int _stdcall adt8949_set_fifo_multi_io(int cardno,int gp,short int iomap,short int levelmap,float speed);

/********************************************************
Function£ºSpecific position delay motion in interpolation
Parameter£º
       cardno           Card number
       millisecond      delay time, unit: ms
Return                 0£ºcorrect                         -1£ºwrong
Remarks£ºSingle control card FIFO capacity of a total of 1000 events, if the function return value is non-zero, represents the event buffer is full, need to cache events have allowance.

        The query cache event area remaining number can call a function adt8949_get_fifo_event_len(¡­)¡£
*********************************************************/
int _stdcall adt8949_set_fifo_delay(int cardno,int millisecond);

/********************************************************
Function£ºInsert pulse generator in interpolation
Parameter£º
       cardno                  Card number
       port                    Output point port of pulse generator (0-14)
       NormalLevel             Normal state voltage level   0: Low, 1: High
       NormalTime              Holding time of normal level, unit: ms
       UnNormalTime            Holding time of non-normal level, unit: ms
       ReverseNum              Reverse times of output level
       speed                   -1: no speed constraint before motion by default, other: range (0.0-100000.0 mm/sec)
Return£º0£ºcorrect               -1£ºwrong
Remarks£ºSpeed setting is same as the motion track speed, and motion track won't decelerate.
           If the speed setting is smaller, the motion track will decelerate to the set speed in advance before corresponding IO operation,
           and then accelerate to motion track speed, and form V-shaped process.
*********************************************************/
int _stdcall adt8949_set_fifo_pulser(int cardno,int port,int NormalLevel,int NormalTime,int UnNormalTime,int ReverseNum,float speed);


/********************************************************
Function£ºSet DA output voltage
Parameter£º
       cardno          Card number
       port            Set DA output port (1-2)
       value           Set DA output size (0-10), unit: V
Return                 0£ºcorrect                                 Non-0£ºwrong
Remarks£º DA output voltage is accurate to two decimal places
*********************************************************/
int _stdcall adt8949_set_daout(int cardno,int port,float value);


//-------------------------------------------------//
//            Back to the origin function          //
//-------------------------------------------------//

/********************************************************
Function£ºSet home signal, step parameter
Parameter£º
       m_nCardNum                      Card number
       m_nAxisNum                      Axis number
       m_nHomeDir                      Home direction, 0: negative direction, 1: positive direction
       m_nStop0Active          stop0 active level setting; 0: Low level stop; 1: High level stop
       m_nLimitActive          limit signal active level setting; 0: Low level stop; 1: High level stop
       m_nStop1Active          stop1 active level setting; 0: Low level stop; 1: High level stop
       m_fBackRange            Reverse distance >1, shouldn't exceed the distance between positive limit and stop0
       m_fEncoderZRange        Encoder Z phase range >1
       m_fOffset               Home offset; ==0: No, >0: positive direction, <0: negative direction
Return         0£ºcorrect        -1 ~ -8£ºerror type£¬-x £º x parameter error
*********************************************************/
int _stdcall adt8949_SetHomeMode_Ex(int m_nCardNum,int m_nAxisNum,int m_nHomeDir, int m_nStop0Active,int m_nLimitActive,int m_nStop1Active,
									float m_fBackRange,float m_fEncoderZRange,float m_fOffset);


/********************************************************
Function£ºSet speed parameters in home
Parameter£º
       m_nCardNum                              Card number
       m_nAxisNum                              Axis number
       m_fStartSpeed                           Home (STOP0) search start speed
       m_fSearchSpeed                          Home search speed
       m_fHomeSpeed                            Slow homing speed
       m_fAcc                                  Acceleration in homing process
       m_fZPhaseSpeed                          Encoder Z phase (STOP1) search speed
Return         0£ºcorrect                         -1~-7£º£¬-x £º x parameter error

*********************************************************/
int _stdcall adt8949_SetHomeSpeed_Ex(int m_nCardNum,int m_nAxisNum,float m_fStartSpeed,float m_fSearchSpeed,float m_fHomeSpeed,float m_fAcc,float m_fZPhaseSpeed);

/********************************************************
Function£ºstart home process
Parameter£º
       m_nCardNum                             Card number
       m_nAxisNum                             Axis number
       m_fGear                                Electronic gear ratio:(1-10000)
Return  0: Correct      -1~-3: Parameter error-x: x parameter error

Remarks£ºCall this function when start back to zero, start after need regular call adt8949_GetHomeStatus_Ex(¡­)£¬Until back to zero
*********************************************************/
int _stdcall adt8949_HomeProcess_Ex(int m_nCardNum,int m_nAxisNum,float m_fGear);

/********************************************************
Function£ºGet the status of home
Parameter£º
       m_nCardNum                              Card number
       m_nAxisNum                              Axis number
Return         0:Home successfully£»-1: Parameter 1 error£»Parameter 2 error£»Homing isn't started;
                       (1-10) steps:
                       1: Approach home fast and search STOP0
                       2: Check if STOP0 is found
                       3: Exit home reversely
                       4: Check if reverse exit is complete
                       5: Approach home slowly and search STOP0
                       6: Check if STOP0 searching completes
                       7: Approach Z phase slowly, and search STOP1. If STOP1 is set to -1, skip step 7 & 8.
                       8: Check if STOP1 searching completes
                       9: Home offset
                       10: Check home offset
                  -100x: The x homing step is abnormal, e.g.: -1001: the first homing step is abnormal
                  -1020: Homing is terminated
Remarks£ºNeed to call regularly, in the process of back to zero until back to zero
*********************************************************/
int _stdcall adt8949_GetHomeStatus_Ex(int m_nCardNum,int m_nAxisNum);


#endif
