#pragma once

#include "bombax.h"



#include "..\pilelibs\includes\robbase\motion.h"
#include "..\pilelibs\includes\robbase\Axes.h"
#include "..\pilelibs\includes\robbase\Options.h"


 
 
////返回码
//#define RM_OK 0
//
////方向 
//#define RM_POSITIVE   1
//#define RM_NEGOTIVE   0
//
////运动轴专用IO
//#define RM_SIO_HOME       1  //原点 
//#define RM_SIO_POSLTD     2  //正限位
//#define RM_SIO_NEGLTD     3  //负限位
//#define RM_SIO_ALARM      4  //报警
//#define RM_SIO_SERVO      5  //伺服使能
//#define RM_SIO_EMERG      0  //急停
  
//单轴回零说明：
//ZAux_Direct_Single_Datum
//0 清除所有轴的错误状态。
//1 轴以CREEP速度正向运行直到Z信号出DPOS值重置为0同时纠正
//MPOS。
//2 轴以CREEP速度反向运行直到Z信号出现。DPOS值重置为0同时纠
//正MPOS。
//3 轴以SPEED速度正向运行，直到碰到原点开关。然后轴以CREEP速
//度反向运动直到离开原点开关。 DPOS值重置为0同时纠正MPOS 
//4 轴以SPEED速度反向运行，直到碰到原点开关。然后轴以CREEP速
//度正向运动直到离开原点开关。 DPOS值重置为0同时纠正MPOS。
//5 轴以SPEED速度正向运行，直到碰到原点开关。然后轴以CREEP
//速度反向运动直到离开原点开关，然后再继续以爬行速度反转直到
//碰到Z信号。DPOS值重置为0同时纠正MPOS
//6 轴以SPEED速度反向运行，直到碰到原点开关。然后轴以CREEP速
//度正向运动直到离开原点开关，然后再继续以爬行速度正转直到碰
//到Z信号。 DPOS值重置为0同时纠正MPOS。



class  BOMBAX_API  CZmotion  :	public CMotion
{
public:
	CZmotion(void);
	virtual ~CZmotion(void);
	//轴模式 
	enum AXIS_MODE{
	    AM_VIRTUAL  =0,
		AM_PULSE_DIR,
	}; 

	
	//运行轴状态
	enum{
		ZO_STOPPED=-1,
		ZO_RUN =0,
	};

	//extra1为连接延迟时间
	virtual BOOL  Init(int  axisCount, const char* strArgs, int extra1, int extra2,  int* pErrCode) ;
	virtual void  Release() ;
	virtual BOOL  IsDeviceReady() ;

	//分配专用io 
	//type: RM_SIO_HOME
	//virtual BOOL  ConfigSio(WORD axis, int id, int bit, BOOL bReverse, int* pErrCode);

	//virtual BOOL  SetSoftLimits(WORD axis, int item, double pos, int* pErrCode) ;
	//virtual BOOL  GetSoftLimits(WORD axis, int item, double* pp, int* pErrCode) ; 

	//virtual BOOL EnableSoftLimit(WORD axis,  int item, BOOL flag, int* pErrCode);
	//virtual BOOL IsSoftLimitEnabled(WORD axis,  int item, BOOL* flag, int* pErrCode);

	//virtual BOOL EnableHardLimit(WORD axis,  int item, BOOL flag, int* pErrCode);
	//virtual BOOL IsHardLimitEnabled(WORD axis,  int item,  BOOL* flag, int* pErrCode);
	 
	//获取正负限位电平
	//virtual BOOL GetHardLimitLevel(WORD axis,	 int item, int* level, int* pErrCode) ;
	//virtual BOOL GetNeglmtLevel(WORD axis,	 int item, int* level, int* pErrCode) ;

	//获取原点电平
	//virtual BOOL GetHomeLevel(WORD axis, int* level, int* pErrCode) ;
	//virtual BOOL SetHomeParams(WORD axis, RM_HOME_PARAMS* pHomeParams, int * pErrCode);

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

	//设置脉冲模式: 
	//如： mode = 256*100 + 0 表示100微妙的保护时间，模式为0
	//返回0, 表示成功 
	virtual BOOL  SetPulseMode(WORD axis, int mode,  int* pErrCode) ;
	virtual BOOL  GetPulseMode(WORD axis, int* mode,  int* pErrCode) ;

	//设置轴类型:0. 虚拟; 1. 脉冲+方向;
	//该类型为厂家自己定义的类型，应用在不同场所 
	//返回0, 表示成功 
	virtual BOOL  SetAxisVendorType(WORD axis, int type,  int* pErrCode) ;
	virtual BOOL  GetAxisVendorType(WORD axis, int* type,  int* pErrCode) ;

	//脉冲当量: 每毫米多少脉冲 
	virtual BOOL  SetAxisUnits(WORD axis, float units, int* pErrCode);
	virtual BOOL  GetAxisUnits(WORD axis, float* units,  int* pErrCode);
	  
	virtual BOOL   EnterEmergState(COptions* options,int *pErrCode);
	virtual BOOL   ClearEmergState(int *pErrCode) ;
 
	//virtual BOOL   PauseMove(WORD axis,  int mode,  int* pErrCode) ;
	//virtual BOOL   ResumeMove(WORD axis,  int* pErrCode)  ;

	virtual BOOL   StopAll(COptions* options,int* pErrCode);

	virtual BOOL  GetCurSpeed(WORD axis, double* speed, int* pErrCode) ;

	
	//virtual BOOL  Reset(int *pErrCode);
	virtual BOOL   ClearAxisState(WORD axis,  int* pErrCode) ;
	

	//功能项
	virtual BOOL GetAuxState(WORD axis, /*int item,*/ int* state, int* pErrCode){return FALSE; } ;
	//virtual BOOL SetAuxState(WORD axis,int items, int state, int* pErrCode) {return FALSE; } ;

	virtual COptions* CreateOptions(double speed, double acc, double dec ) ;
	virtual void DestroyOptions(COptions* pOptions) ;
	 
//公用接口
public:
	virtual BOOL   ClearAxisPos(WORD axis,  int posType, int* pErrCode);

	//当前位置 ,编码器位置, 光栅尺位置 
	virtual BOOL   GetAxisEncoderPos(WORD axis,  double *curpos, int * pErrCode);
    virtual BOOL   GetAxisRasterPos(WORD axis, double *curpos, int * pErrCode);
	virtual BOOL   GetAxisCurPos(WORD axis,  int posType, double *curpos,int * pErrCode  ) ;

	//state: 0-运动中; -1-停止
	virtual BOOL   GetMoveState(WORD axis, int* state, int* pErrCode);
	virtual BOOL   GetHomeState(WORD axis, int* state, int* pErrCode) ;

	//virtual BOOL   EnableAxisServo(WORD axis,   BOOL flag, int* pErrCode);
	//virtual BOOL   IsAxisServoEnabled(WORD axis, BOOL* flag, int* pErrCode) ;

	//
	//virtual BOOL   ClearAxisServoAlarm(WORD axis, int duration, int* pErrCode) ;
//	virtual BOOL   IsAxisServoAlarmOn(WORD axis, int* flag, int* pErrCode) ;


	virtual BOOL   Delay(int duration, int* pErrCode);
	 
	//@512  回零位 
	virtual BOOL  Home(WORD axis, COptions* options, int* pErrCode) ;
	 
	//任意2轴回零,使用轴标识
	//如RM_AF_X | RM_AF_Y
	//virtual BOOL  HomeAny2(CAxes& axes, COptions* options, int* pErrCode) ;
	//virtual BOOL  HomeAny4(CAxes& axes, COptions* options, int* pErrCode) ;
	//virtual BOOL  HomeAny3(CAxes& axes, COptions* options, int* pErrCode) ;
	//virtual BOOL  HomeAny(CAxes& axes, COptions* options, int* pErrCode) ;
	 
	virtual BOOL  StopHome(WORD axis, COptions* options, int* pErrCode) ;
	 
	//停止任意2轴回零。
	//如RM_AF_X | RM_AF_Y
	//virtual BOOL  StopHomeAny2(CAxes& axes, COptions* options, int* pErrCode);
	//virtual BOOL  StopHomeAny3(CAxes& axes, COptions* options, int* pErrCode);
	//virtual BOOL  StopHomeAny4(CAxes& axes, COptions* options, int* pErrCode);
	  
	//@528 连续运动 
	virtual BOOL Jog(WORD axis,  COptions* opts,  int dir, int* pErrCode) ;

	//连续运动停止
	virtual BOOL StopJog(WORD axis,  COptions* opts,  int* pErrCode) ;
	//end of @528

	//@527 点动
	virtual BOOL  Move(WORD axis, double step, COptions* options, BOOL bAbsolute, int* pErrCode) ;  	
	virtual BOOL  StopAxis(WORD axis, COptions* options,  int* pErrCode);
	   
	//@529 插补运动 	 
	//virtual BOOL MoveArcAny2(CAxes& axes, double  ex, double  ey, double radius, BOOL bBigArc, int direct, double speed, double acc, double acc2, int* pErrCode) ;
	//virtual BOOL MoveCircleAny2(CAxes& axes, double cx, double cy, double sx, double sy, int direct, double speed, double acc, double acc2, int* pErrCode) ;
	  
	//任意2轴移动,使用轴标识
	//如RM_AF_X | RM_AF_Y

	//virtual BOOL  MoveAny2(CAxes& axes, double x, double y,  COptions* options, BOOL bAbsolute,  int* pErrCode );
	//virtual BOOL  MoveAny3(CAxes& axes, double x, double y, double z, COptions* options, BOOL bAbsolute, int* pErrCode);
	//virtual BOOL  MoveAny4(CAxes& axes, double x, double y, double z, double r, COptions* options, BOOL bAbsolute, int* pErrCode);
	 virtual BOOL  MoveAny ( DWORD csid, CAxes& axes, double* posArray, int count, COptions* options, BOOL bAbsolute, int* pErrCode) ;

	virtual BOOL MoveArcTo( DWORD csid,  WORD axisX, WORD axisY, double cx, double cy, double ex, double ey, int direct, COptions* options, int* pErrCode) ;

	   
	//virtual BOOL StopAxisAny2(CAxes& axes,  COptions* options, int* pErrCode);
	//virtual BOOL StopAxisAny3(CAxes& axes,  COptions* options, int* pErrCode);
	//virtual BOOL StopAxisAny4(CAxes& axes,  COptions* options, int* pErrCode);
	virtual BOOL StopAny( DWORD csid, CAxes&  axes, COptions* options,  int* pErrCode) ;


	//缓冲区运动
	virtual BOOL ExecuteQueue(  CQueue* pQueue, int startIndex, int count, COptions* options,   int* pErrCode )   ;
	virtual BOOL GetQueueState(CQueue* pQueue, int* state, int* linenum, int* pErrCode)  ;
	virtual BOOL StopQueue(CQueue* pQueue, COptions* options,   int* pErrCode)    ; 
	virtual BOOL WaitQueue(CQueue* pQueue, int timeout, int* pErrCode) ;
	  
public:
	virtual BOOL SetOutputLevel(int bit, int level, int* pErrCode) ;
    virtual BOOL GetOutputLevel(int bit, int* level, int* pErrCode) ;
    virtual BOOL GetInputLevel(int bit, int* level, int* pErrCode) ; 
	 
	//virtual BOOL SetBatchOutBits(int levels,   int* pErrCode)  {return FALSE;} ;
   // virtual BOOL GetBatchOutBits(int* pLevels, int* pErrCode)  {return FALSE;} ;
	//virtual BOOL GetBatchInBits(int* pLevels,   int* pErrCode) {return FALSE;};

	

public:
	
	 
	
	virtual const char* GetVersion()  ;
	virtual const char* GetVendorDesc() ;
    virtual const char* GetErrorDesc(int errCode);
	virtual const char* GetSerialNum() ;

 private:
	 HANDLE  m_hZmc;
	   
	  
};

