#pragma once

#include "robbase.h"


#define RM_INVALID_ID   (-1)

//返回值
#define RM_OK            0
#define RM_FAILED        -1

#define RM_ERR_ILLEGAL_USE         (-94) 
#define RM_ERR_INVALID_AXIS        (-95)
#define RM_ERR_INVALID_OBJ         (-95)
#define RM_ERR_INVALID_HANDLE      RM_ERR_INVALID_OBJ
#define RM_ERR_UNSUPPORTED         (-96)
#define RM_ERR_OUT_OF_RANGE        (-97)
#define RM_ERR_NOT_READY           (-98)
#define RM_ERR_INPUT_TIME_OUT      (-99)
#define RM_ERR_USER_EX             (-100)


//#define RM_ERR_TORQUE_TEST_TIME_OUT    -132
//#define RM_ERR_DRIVE_TIME_OUT          -133
//#define RM_ERR_CANT_CONNECT_DRIVER     -136
//#define RM_ERR_PATTERN_MISSING         -137

#define RM_AXIS_1        1 //轴序号从1开始
#define RM_BIT_1         1 //位序列号从1开始
              

//vendor id
#define RM_UNKNOWN         (-1)
//#define RM_GOOGL           0
//#define RM_MOTIONTIME      1



#define RM_SUCCESS(code)  ((code) == RM_OK)

#define MAX_AXIS_COUNT     8

//轴号从1开始
#define RM_MIN_AXIS_NUM  1
#define RM_MAX_AXIS_NUM  MAX_AXIS_COUNT

//四、六轴常用轴名称
#define RM_AXIS_X       1
#define RM_AXIS_Y       2
#define RM_AXIS_Z       3
#define RM_AXIS_Y2      4  //第2个托盘轴
#define RM_AXIS_R       4  //z轴旋转
#define RM_AXIS_A1      5  //辅助轴1
#define RM_AXIS_A2      6  //辅助轴2
#define RM_AXIS_A3      7  //辅助轴2
#define RM_AXIS_A4      8  //辅助轴2

//独立第二组x,y,z坐标轴
#define RM_AXIS_X_2      4   
#define RM_AXIS_Y_2      5  
#define RM_AXIS_Z_2      6  


//AXIS FLAG
#define RM_AF_X         1
#define RM_AF_Y         (1<<1)
#define RM_AF_Z         (1<<2)
#define RM_AF_Y2        (1<<3)
#define RM_AF_A1        (1<<4)
#define RM_AF_A2        (1<<5)

#define RM_AF_X_2        (1<<3)
#define RM_AF_Y_2        (1<<4)
#define RM_AF_Z_2        (1<<5)




//普通轴名称
#define RM_AXIS_1      1
#define RM_AXIS_2      2
#define RM_AXIS_3      3
#define RM_AXIS_4      4   
#define RM_AXIS_5      5  
#define RM_AXIS_6      6  
#define RM_AXIS_7      7  
#define RM_AXIS_8      8   


#define RM_AF_1        (1)
#define RM_AF_2        (1<<1)
#define RM_AF_3        (1<<2)
#define RM_AF_4        (1<<3)
#define RM_AF_5        (1<<4)
#define RM_AF_6        (1<<5)
#define RM_AF_7        (1<<6)
#define RM_AF_8        (1<<7)


//8轴两坐标系轴名称
#define RM_AXIS_C1_X      1
#define RM_AXIS_C1_Y      2
#define RM_AXIS_C1_Z      3
#define RM_AXIS_C1_R      4   
#define RM_AXIS_C2_X      5   
#define RM_AXIS_C2_Y      6  
#define RM_AXIS_C2_Z      7  
#define RM_AXIS_C2_R      8   

#define RM_AF_C1_X        (1)
#define RM_AF_C1_Y        (1<<1)
#define RM_AF_C1_Z        (1<<2)
#define RM_AF_C1_R        (1<<3)
#define RM_AF_C2_X        (1<<4)
#define RM_AF_C2_Y        (1<<5)
#define RM_AF_C2_Z        (1<<6)
#define RM_AF_C2_R        (1<<7)



#define RM_AF_XY(af_x, af_y)             ((af_x) | ((af_y) << 8))
#define RM_AF_XYZ(af_x, af_y, af_z)      ((af_x) | ((af_y) << 8) | ((af_z) << 16)) 
#define RM_AF_XYZR(af_1, af_2, af_3, af_4)  ((af_1) | ((af_2) << 8) | ((af_3) << 16)  | ((af_4) << 24)) 

#define RM_AF_ANY2(af_1, af_2 )             ((af_1) | ((af_2) << 8) ) 
#define RM_AF_ANY3(af_1, af_2, af_3 )       ((af_1) | ((af_2) << 8) | ((af_3) << 16)) 
#define RM_AF_ANY4(af_1, af_2, af_3, af_4)  ((af_1) | ((af_2) << 8) | ((af_3) << 16)  | ((af_4) << 24)) 



#define RM_GET_AF(axis)   (1<<((axis)-1))

//
////输入，保留前4路
#define RM_DI_EMG           1  //急停
#define RM_DI_RESET         2  //复位
#define RM_DI_START         3  //开始
#define RM_DI_STOP          4  //停止

 
////输出，保留前三路
#define RM_DO_NORMAL       1  //绿灯
#define RM_DO_WARNING      2  //黄灯
#define RM_DO_ERROR        3  //红灯
 

//运动框架，注意下面的id，不能随意改变，新的id直接往后添加
#define  RM_FX          (-1) //  自定义 
#define  RM_F3            0 //  3轴
#define  RM_F3_2T         1 //  3轴，双工作位
#define  RM_F4_2T         2 //  4轴，双工作位
#define  RM_F4_1T_1R      3 //  4轴，单工作位，带旋转轴
#define  RM_F6_1T_1R_1A   4 //  6轴，单工作位，带旋转轴，辅助轴
#define  RM_F6_2T_L       5 //  6轴，双工作位，背靠背，联动
#define  RM_F6_2T_I       6 //  6轴，双工作位，背靠背，独立
#define  RM_F6_2T_1R_1A   7 //  6轴，双工作位，旋转，辅助轴
#define  RM_F2            8 //  2轴
#define  RM_F1            9 //  1轴
 





#define RM_VENDOR_TEXT_LEN     16



//实际值,每转行走距离,马达分辨率
//mr - motor resolution 马达细分，即每转需要多少脉冲
//dpr - dist per round 每转移动距离
#define RM_CALC_PULSE(n, dpr, mr)   (((n) / (dpr) * (mr)))  //公制mm转成脉冲
#define RM_CALC_METRIC(n, dpr, mr)  ((n)*1. /(mr) * (dpr) )       //脉冲转成公制mm
#define RM_PULSE_PER_MM(mr, dpr)  ((mr) /(dpr))   




//轴运动类型
#define RM_MT_UNLIMIT      0   //自由: 无原点限制或限位,
#define RM_MT_LINEAR       1   //直线运动： 默认
#define RM_MT_ROTATION     2   //旋转运动

//位置计数器
#define RM_PC_DEFAULT      0  // 规划位置
#define RM_PC_ENCODER      1  // 编码器
#define RM_PC_RASTER       2  // 光栅尺

//回零方式
#define RM_HT_DEFAULT      0 //默认回零方式

//轴辅助状态
#define		RM_AS_POS_LMT  1         //正限位
#define		RM_AS_NEG_LMT  (1<<1)   //负限位
#define	    RM_AS_DRV_ALM  (1<<2)   //驱动报警
#define		RM_AS_ENA_SRV  (1<<3)   //伺服使能
#define		RM_AS_EXC_TOL  (1<<4)   //随动误差超出限制
#define		RM_AS_EM_STP   (1<<5)     //急停
#define		RM_AS_SM_STP   (1<<6)     //缓停
#define		RM_AS_RUN_STA  (1<<7)    //运行状态

#define   RM_AS_SOFTLIMIT  ( RM_AS_POS_LMT | RM_AS_NEG_LMT)


//轴运行状态
#define	RM_RS_NORMAL    0
#define	RM_RS_HOMEOK    0
#define	RM_RS_BUSYHOME  1
#define	RM_RS_MOVING    1
#define	RM_RS_STOPPED   2  //缓冲区可能有这种状态，轴停止，但没有错误发生
#define	RM_RS_ERROR     3

//轴停止方式
#define RM_SM_IMD     0  //立即停止
#define RM_SM_SMOOTH  1  //平滑停止


//输入信号触发模式：限位，急停，通用信号
#define  RM_TM_DISABLE  0  //不使用紧急停止功能
#define  RM_TM_IMD_LOW  1  //低电平触发紧急停止 
#define  RM_TM_DEC_LOW  2  //低电平触发减速停止
#define  RM_TM_IMD_HI   3  //高电平触发紧急停止
#define  RM_TM_DEC_HI   4  //高电平触发减速停止

typedef struct __rm_axis_info_
{
	int  type;  //运动类型， 直线，旋转，
	BOOL bReady;
	BOOL bEnableServo;  
	int  posCounter; // 位置计数器: 规划位置，编码器 ,光栅尺

	//编码器相关
	int    initEncoderLogic;  //编码器初始电平，控制编码器计数正方方向。	 
	union{
	    float  fScalar;   //编码器当量变换值
		int    iScalar;   //编码器当量变换值，固高,((alpha <<16) | beta)
	};

	//马达相关
	double distPerRound; //unit: mm
	int    motorReso;   // 3200

	double rasterGap;   //光栅尺精度
	
	//int    encoderReso;  //编码器分辨率
}RM_AXIS_INFO;


typedef struct __rm_home_params_
{
	int  homeType;    //回零方式，不同供应商回零类型不一样，值也会不一样
	int  evenTime;    //停止时间,ms
	double homeOffset; //回零时移位距离

	int limitLogic;
	int homeLogic;
	int indexLogic;
}RM_HOME_PARAMS;
 
 
typedef struct __rm_trigger_params_{
	//int  pulseMode;                 //脉冲模式
	int  homeTriggerMode;           //原点信号触发模式
	int  negativeLimitTriggerMode;  //负限位信号触发模式
	int  positivelimitTriggerMode;  //正限位信号触发模式
	int  indexTriggerMode;          //索引电平信号触发模式
	int  alarmTriggerMode;          //伺服报警信号触发模式	
}RM_TRIGGER_PARAMS;

class ROBBASE_API CRobMot
{
public:
	CRobMot(void);
	virtual ~CRobMot(void);
	 
	enum  
	{
	    RM_DISABLE =0,
		RM_ENABLE  =1,
		RM_LOW =0,
		RM_HI  =1,
		RM_OFF  =0,
		RM_ON   =1,
		RM_CLOSE=0,
		RM_OPEN=1,
		RM_CW=0,          //move direction: 顺时针
		RM_CCW=1,        //move direction: 逆时针 
	};
	   
	//初始化与释放
	virtual BOOL  Init(const char* pStrFile, int frameWork, int ctrlMode,  int* pErrCode){return FALSE; };

	//单模块初始化
	virtual BOOL  Init(int id, int model, int frameWork,  int* pErrCode){ return FALSE; };

	virtual void Release();
	//Init成功后，应该设置m_bInit=TRUE
	BOOL    IsModuleReady(){ return m_bInit; };

	//virtual void Refresh(){};

	virtual const char* GetVersion() =0;
	virtual const char* GetVendorDesc() =0;
	virtual const char* GetErrorDesc(int errCode)=0;
    virtual const char* GetSerialNum() =0;

	//设置软限位
	virtual BOOL  SetSoftLimits(int axis, double neg, double pos, int* pErrCode)=0;
	virtual BOOL  GetSoftLimit(int axis, double* np, double* pp, int* pErrCode)=0; 
	//获取正负限位电平
	virtual BOOL GetPositiveLimitBit(int axis,	int* level, int* pErrCode)=0;
	virtual BOOL GetNegativeLimitbit(int axis,	int* level, int* pErrCode)=0;

	//获取原点电平
	virtual BOOL GetHomeBit(int axis, int* level, int* pErrCode)=0;

	//获取急停位电平,紧急停止电平
	virtual BOOL GetEmergBit(int* level, int* pErrCode)=0;

	//设置紧急停止位,不会进行立即停止，如果需要立即停止，请调用EntrEmerg函数
	virtual BOOL SetEmergBit(int bit, int type, int* pErrCode){ return RM_FAILED ;}; 
	 

	int  GetVendorId(){ return m_nVendorId; };
	int  GetLastError();

	BOOL IsMultiCard(){return (m_nCardCount >1); };
	int  GetCurCard(){ return m_nCurCard; }
	int  SetCurCard(int index );
	int  GetCardCount();

	//BOOL IsEncoderLogicReversed(int axis);
	//virtual BOOL InvertEncoder(int axis, int* pErrCode);
	//编码器电平，控制计数方向
	//RM_LOW 或 RM_HI
	virtual BOOL SetEncoderLogic(int axis, int level,  int* pErrCode);
	int     GetEncoderLogic(int axis);


	void   GetEncoderScalar(int axis, int* pScalar);
	void   GetEncoderScalar(int axis, float* pScalar);
	virtual BOOL SetEncoderScalar(int axis, int scalar, int* pErrCode);
	virtual BOOL SetEncoderScalar(int axis, float scalar, int* pErrCode);


	virtual BOOL   IsAxisReady(int axis);
	virtual BOOL   IsMultiAxisReady(int axes);

	
	//将当前轴坐标位置清零
 	virtual BOOL   ClearAxisPos(int axis, int posType, int* pErrCode){ return FALSE;};

	//将清除轴错误状态，同时将ready标志为false
 	virtual BOOL   ResetAxisState(int axis,  int* pErrCode) ;



	//当前位置，单位:mm
	virtual BOOL   GetAxisCurPos(int axis, double *curpos, int * pErrCode=NULL){ return FALSE;};
	
	//posType: profile, encoder
	virtual BOOL   GetAxisRawPos(int axis, int posType, long *curpos, int * pErrCode=NULL){ return FALSE;};
	
	//获取光栅尺位置，单位:mm（有些卡伺服与光栅尺接口复用，需要单独使用接口）
	virtual BOOL   GetAxisRasterPos(int axis, double *curpos, int * pErrCode=NULL){ return FALSE;};


	//
	virtual BOOL   GetAxisState(int axis, int* state, int* pErrCode){ return FALSE;};
	
	virtual BOOL   EnableAxisServo(int axis, BOOL flag = TRUE, int* pErrCode =NULL);
	BOOL           IsAxisServoEnabled(int axis);




	virtual BOOL   ClearAxisServoAlarm(int axis,int* pErrCode){return FALSE;};
	virtual BOOL   GetAxisServoAlarm(int axis,int* state, int* pErrCode){ return FALSE; };

    //自定义框架才可以设置轴数 
	BOOL SetAxisCount(int count, int* pErrCode);

	//设置轴类型,自由，直线, 旋转
	int GetAxisMachType(int axis );
	virtual BOOL SetAxisMachType(int axis, int type, int * pErrCode);

	//位置计数器
    int  GetPosCounterType(int axis);
    virtual BOOL SetPosCounterType(int axis, int type, int * pErrCode);

	BOOL     GetHomeParams(int axis, RM_HOME_PARAMS* pHomeParams, int * pErrCode);
	virtual BOOL SetHomeParams(int axis, RM_HOME_PARAMS* pHomeParams, int * pErrCode);

	//输入信号触发轴停止模式
	virtual BOOL GetTriggerMode(int axis, RM_TRIGGER_PARAMS* pTrigerParams, int paramSize, int * pErrCode){ return FALSE; };
    virtual BOOL SetTriggerMode(int axis, RM_TRIGGER_PARAMS* pTrigerParams, int paramSize, int * pErrCode){ return FALSE; };
 

	void SetDPR(int axis, double val);
	void SetMotorReso(int axis, int val);
	double GetDPR(int axis);
	int    GetMotorResolution(int axis);

	double GetRasterGap(int axis);
	void   SetRasterGap(int axis, double gap);


	//从轴标记中提取相应的轴号。ie: axes = RM_AF_X | RM_AF_Y
	BOOL   GetAxisNumsFromFlags(int axes, int* pAxis1, int* pAxis2 = NULL, int* pAxis3 = NULL, int* pAxis4 = NULL);
	BOOL   GetAxisNumsFromFlags(int axes, int* pAxisArr, int count);
	
	//获取x,y 轴
	BOOL   GetAxisNumsFromFlagsXY(int axes, int* pAxisX, int* pAxisY );

	//获取x, y, z轴
	BOOL   GetAxisNumsFromFlagsXYZ(int axes, int* pAxisX, int* pAxisY,  int* pAxisZ);

	//按循序排列的轴号,用于任意移动函数
	BOOL   GetAxisNumsFromFlagsAny2(int axes, int* pAxis1, int* pAxis2 );
	BOOL   GetAxisNumsFromFlagsAny3(int axes, int* pAxis1, int* pAxis2,  int* pAxis3);
	BOOL   GetAxisNumsFromFlagsAny4(int axes, int* pAxis1, int* pAxis2,  int* pAxis3, int* pAxis4);

	BOOL   IsAxisInFlags(int flags, int axis);

	//毫米转成脉冲,输入有序的轴标志
	double GetMaxSpeedInPulsesAny2(int axes, double metric);
	double GetMaxSpeedInPulsesAny3(int axes, double metric);
	double GetMaxSpeedInPulsesAny4(int axes, double metric);
	  
	//组成轴号,homeany
	int    GetAxisFlagsFromNums(int axis1, int axis2);
	int    GetAxisFlagsFromNums(int axis1, int axis2, int axis3);
	int    GetAxisFlagsFromNumsE1(int firstAxis, int count);

	//组成轴号: move any
	int    GetAxisFlagsFromXY(int axisX, int axisY);
	int    GetAxisFlagsFromXYZ(int axisX, int axisY, int axisZ);
	 
	//virtual BOOL  Reset(int *pErrCode);
	virtual BOOL  EnterEmerg(int *pErrCode);//{ return FALSE; };

	//virtual BOOL ChangeTool(double posx, double posy, int* pErrCode){return FALSE;};
    
	virtual BOOL Delay(int duration, int* pErrCode){ return FALSE;};

	virtual BOOL MoveRaw(int axis, int step, int* pErrCode){ return FALSE;};
	virtual BOOL HomeRaw(int axis,  int* pErrCode){ return FALSE;};

	int  GetFrameWork(){ return m_nFramework; };
	int  GetAxisCount(){ return m_nAxisCount; };
	BOOL SetFrameWork(int frameWork, int* pErrCode);

//运动相关
public:
	//回零
	//acc may be maximum speed
	//speed may be minimum speed
	virtual BOOL  GoHome(int axis, double speed, double maxSpeed, double acc, int* pErrCode){ return FALSE; };
    virtual BOOL  GoHomeXY(double speed, double maxSpeed,double acc, int* pErrCode){ return FALSE; };
    virtual BOOL  GoHomeXY2(double speed, double maxSpeed,double acc, int* pErrCode){ return FALSE; };
	virtual BOOL  GoHomeX2Y2(double speed, double maxSpeed,double acc, int* pErrCode){ return FALSE; };

    virtual BOOL  GoHomeXYY2(double speed, double maxSpeed,double acc, int* pErrCode){ return FALSE; };
    
   

	//x,两个y轴
	//virtual BOOL  GoHomeX2Y(double speed, double maxSpeed,double acc, int* pErrCode){ return FALSE; };
	virtual BOOL  GoHomeXYZ(double speed, double maxSpeed,double acc, int* pErrCode){ return FALSE; };
	virtual BOOL  GoHomeX2Y2Z2(double speed, double maxSpeed,double acc, int* pErrCode){ return FALSE; };
    virtual BOOL  GoHome4A(double speed, double maxSpeed,double acc, int* pErrCode){ return FALSE; };

	//任意2轴回零,使用轴标识
	//如RM_AF_X | RM_AF_Y
	virtual BOOL  GoHomeAny2(int axes, double speed, double maxSpeed, double acc, int* pErrCode){ return FALSE; };
	virtual BOOL  GoHomeAny3(int axes, double speed, double maxSpeed, double acc, int* pErrCode){ return FALSE; };

	virtual BOOL  GoHomeAny4(int axes, double speed, double maxSpeed, double acc, int* pErrCode){ return FALSE; };

	
	//mode : 立即停止，平滑停止
	virtual BOOL  StopHome(int axis, int mode, double dec, double dec2,int* pErrCode){ return FALSE; };
	virtual BOOL  StopHomeXY(int mode,double dec,double dec2, int* pErrCode){ return FALSE; };
	virtual BOOL  StopHomeXYY2(int mode,double dec,  double dec2,int* pErrCode){ return FALSE; };
	virtual BOOL  StopHomeXYZ(int mode,double dec, double dec2, int* pErrCode){ return FALSE; };

	virtual BOOL  StopHomeX2Y2Z2(int mode,double dec, double dec2, int* pErrCode){ return FALSE; };

	//停止任意2轴回零。
	//如RM_AF_X | RM_AF_Y
	virtual BOOL  StopHomeAny2(int axes, int mode, double dec, double dec2, int* pErrCode){ return FALSE; };
	virtual BOOL  StopHomeAny3(int axes, int mode, double dec, double dec2, int* pErrCode){ return FALSE; };
	virtual BOOL  StopHomeAny4(int axes, int mode, double dec, double dec2, int* pErrCode){ return FALSE; };


	virtual BOOL  GetHomeState(int axis, int* state, int* pErrCode){ return FALSE; };

	//点动
	//移动到相对位置,dist为负的话，反方向移动
	virtual BOOL Move(int axis, double dist, double speed, double acc, double acc2, int* pErrCode){ return FALSE; };

	//移动到具体位置
	virtual BOOL MoveTo(int axis, double targetPos, double speed, double acc, double acc2, int* pErrCode){ return FALSE; };

	//停止单轴
	virtual BOOL StopAxis(int axis, int mode, double dec, double dec2, int* pErrCode){ return FALSE; };

	//连续运动
	virtual BOOL Jog(int axis,  double speed, double acc, double acc2, int* pErrCode){ return FALSE; };

	//连续运动停止
	virtual BOOL StopJog(int axis,  int mode, double dec, double dec2,  int* pErrCode){ return FALSE; };
	
	//插补
	//相对运动
	virtual BOOL MoveXY(double dx, double dy, double speed, double acc, double acc2, int* pErrCode){return FALSE; };
	virtual BOOL MoveXYZ(double dx, double dy, double dz, double speed, double acc, double acc2, int* pErrCode){return FALSE; };
	
	//绝对位置
	virtual BOOL MoveToXY(double x, double y, double speed, double acc, double acc2, int* pErrCode){return FALSE; };
	virtual BOOL MoveToXY2(double x, double y2, double speed, double acc, double acc2, int* pErrCode){return FALSE; };

	 

	virtual BOOL MoveToXYZ(double x, double y, double z, double speed, double acc, double acc2, int* pErrCode){return FALSE; };
	virtual BOOL MoveToXY2Z(double x, double y, double z, double speed, double acc, double acc2, int* pErrCode){return FALSE; };

	
	virtual BOOL MoveArcXYZ(double  ex, double  ey, double z, double radius, BOOL bBigArc, int direct, double speed, double acc, double acc2, int* pErrCode){return FALSE; };
	virtual BOOL MoveCircleXYZ(double cx, double cy, double z,  double sx, double sy, int direct, double speed, double acc, double acc2, int* pErrCode){return FALSE; };

	virtual BOOL MoveArcXY2Z(double  ex, double  ey, double z, double radius, BOOL bBigArc, int direct, double speed, double acc, double acc2, int* pErrCode){return FALSE; };
	virtual BOOL MoveCircleXY2Z(double cx, double cy, double z,  double sx, double sy, int direct, double speed, double acc, double acc2, int* pErrCode){return FALSE; };


	virtual BOOL MoveArc(double  ex, double  ey, double radius, BOOL bBigArc, int direct, double speed, double acc, double acc2, int* pErrCode){return FALSE; };
	virtual BOOL MoveCircle(double cx, double cy, double sx, double sy, int direct, double speed, double acc, double acc2, int* pErrCode){return FALSE; };

	virtual BOOL MoveArcXY2(double  ex, double  ey, double radius, BOOL bBigArc, int direct, double speed, double acc, double acc2, int* pErrCode){return FALSE; };
	virtual BOOL MoveCircleXY2(double cx, double cy, double sx, double sy, int direct, double speed, double acc, double acc2, int* pErrCode){return FALSE; };
	
	virtual BOOL MoveArcAny2(int axes, double  ex, double  ey, double radius, BOOL bBigArc, int direct, double speed, double acc, double acc2, int* pErrCode){return FALSE; };
	virtual BOOL MoveCircleAny2(int axes, double cx, double cy, double sx, double sy, int direct, double speed, double acc, double acc2, int* pErrCode){return FALSE; };


	//任意2轴移动,使用轴标识
	//如RM_AF_X | RM_AF_Y
	virtual BOOL  MoveAny2(int axes,  double dx, double dy, double speed, double acc, double acc2, BOOL bAbsolute, int* pErrCode){ return FALSE; };
	virtual BOOL  MoveAny3(int axes,  double dx, double dy, double dz, double speed, double acc, double acc2, BOOL bAbsolute, int* pErrCode){ return FALSE; };
	virtual BOOL  MoveAny4(int axes,  double dx, double dy, double dz, double speed, double acc, double acc2, BOOL bAbsolute, int* pErrCode){ return FALSE; };

	
	//停止插补运动
	//
	virtual BOOL StopAxisXY(  int mode, double dec, double dec2, int* pErrCode){return FALSE; } ;

	//停止任意2轴移动(差补)。
	//如RM_AF_X | RM_AF_Y
	virtual BOOL StopAxisAny2(int axes,  int mode, double dec, double dec2, int* pErrCode){return FALSE; } ;
	virtual BOOL StopAxisAny3(int axes,  int mode, double dec, double dec2, int* pErrCode){return FALSE; } ;
	virtual BOOL StopAxisAny4(int axes,  int mode, double dec, double dec2, int* pErrCode){return FALSE; } ;
	 
	virtual BOOL StopAxisXYZ(  int mode, double dec, double dec2, int* pErrCode){return FALSE; };
	virtual BOOL StopAxisXY2(  int mode, double dec, double dec2, int* pErrCode){return FALSE; };

	virtual BOOL StopAxisX2Y2(  int mode, double dec, double dec2, int* pErrCode){return FALSE; };
	virtual BOOL StopAxisX2Y2Z2(  int mode, double dec, double dec2, int* pErrCode){return FALSE; };
	//停止插补运动
	virtual BOOL StopMultiAxes(int coord,  int mode, double dec, double dec2, int* pErrCode){return FALSE; };

	

	//MCF_Buffer_Arc_Radius_Net

	//缓冲区运动
	virtual BOOL OpenBank(int id, void* pParams, int paramSize,  int* pErrCode){return FALSE;};
	virtual BOOL SubmitBank(int id,  int* linecount,int* pErrCode){return FALSE;};
	virtual BOOL ExecuteBank(int id,   int* pErrCode ){ return FALSE;};
	virtual BOOL GetBankState(int id, int* state, int* linenum, int* pErrCode) { return FALSE;};
	
	//旧接口
	//virtual BOOL StopBank(int id, int* pErrCode){ return FALSE;};

	virtual BOOL StopBank(int id, int mode,   double dec, double dec2,  int* pErrCode){ return FALSE;};
	
	//旧接口
	//virtual BOOL PlanBank(int id,   int* pErrCode){ return FALSE;};

	virtual BOOL PlanBank(int id,   double speed, double acc, double acc2 , int* pErrCode){ return FALSE;};

	virtual void CloseBank(int id);

	BOOL IsBankOpened(){ return m_bOpenBank; };

	//等待输入
	virtual BOOL WaitInput(int bit, int timeout, BOOL& bCanceled, int* pErrCode) ;
	virtual BOOL WaitAxis(int axis, BOOL& bCanceled, int* pErrCode) ;
	virtual BOOL WaitHome(int axis, BOOL& bCanceled, int* pErrCode) ;
	virtual BOOL WaitBank(int bankId, BOOL& bCanceled, int* pErrCode) ;

	//
	virtual BOOL SetAxisReady(int axis, BOOL flag, int* pErrCode);
	//virtual BOOL SetMultiAxisReady(int axes, BOOL flag, int* pErrCode);

//通用和专用IO
public:

	

	virtual BOOL GetAuxState(int axis, int items, int* state, int* pErrCode) {return FALSE; };
	virtual BOOL SetAuxState(int axis,int itemss, int state, int* pErrCode){ return FALSE ;};


	//单点设置
    virtual BOOL SetOutputBit(int bit, int level, int* pErrCode){return RM_FAILED; };
    virtual BOOL GetOutputBit(int bit, int* level, int* pErrCode){return RM_FAILED; };
    virtual BOOL GetInputBit(int bit, int* level, int* pErrCode){return RM_FAILED; };

	//批量设置
	//原来版本
	//virtual BOOL SetOutputBits(int lowLevels, int hiLevels, int* pErrCode){ return RM_FAILED ;};
    //virtual BOOL GetOutputBits(int* lowLevels, int* hiLevels, int* pErrCode){ return RM_FAILED ;};
	//virtual BOOL GetInputBits(int* lowLevels, int* hiLevels, int* pErrCode){ return RM_FAILED ;};

	virtual BOOL SetBatchOutBits(int levels, int* pErrCode){ return RM_FAILED ;};
    virtual BOOL GetBatchOutBits(int* pLevels, int* pErrCode){ return RM_FAILED ;};
	virtual BOOL GetBatchInBits(int* pLevels, int* pErrCode){ return RM_FAILED ;};

	
	//限位
	//np - 负方向位置， 
	//pp - 正方向位置
	//virtual int SetSoftLimit(int axis, long np, long pp)=0; 
	//virtual int GetSoftLimit(int axis, long* np, long* pp)=0; 
	  
//运动控制
public:
	//CMotOpts* SelectOptions(CMotOpts* pMovOpts);
	//CMotOpts* ResetOptions();

	//CMotOpts* GetCurOpts();

	
	//int       m_nBankMode;   //缓冲区运动模式 

protected:
   

	int   m_nCmdCounter; //缓冲区指令计数
	void* m_pBankParams; //仅引用外部的参数,继承类解释内容
    

public:
	//
	int   m_nInputCount;  //输入信号数量
	int   m_nOutputCount; //输出信号数量
	
	int   m_nDeviceId;    //模块编号，从0开始
	int   m_nDeviceType;  //设备类型,数字输入输出模块，运动模块， 
	
	char  m_strVendor[RM_VENDOR_TEXT_LEN + 1];
	int   m_nVendorId;  //大于等于0
   
	BOOL m_bRevertInputLevel;   //输入电平电平反转
	BOOL m_bRevertOutputLevel;  //输出电平反转

 
	  
protected:
	//CMotOpts* m_pMovOpts;
	BOOL      m_bOpenBank;
	int       m_nCurBank;

	int   m_nAxisCount;   //轴数
	int   m_nFramework;   //运动框架

protected:

	int m_nLastError; //0表示无错误.可选。

	int m_nCardCount;
	int m_nCurCard;

	RM_AXIS_INFO    m_arrAxisInfo[MAX_AXIS_COUNT];
	RM_HOME_PARAMS  m_arrHomeParams[MAX_AXIS_COUNT];

	//BOOL m_bReadyX, m_bReadyY, m_bReadyY2, m_bReadyZ;
	//double m_nCurX, m_nCurY, m_nCurY2, m_nCurZ;

	BOOL m_bInit;

};

