// First_demoDlg.cpp : implementation file
//

#include "stdafx.h"
#include "First_demo.h"
#include "First_demoDlg.h"
#include "WinConSDK.h"
#include "I8092.h"

bool Driver_Open;
BYTE cardNo=0;
CI8092MF I8092MF;

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CFirst_demoDlg dialog

CFirst_demoDlg::CFirst_demoDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CFirst_demoDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CFirst_demoDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CFirst_demoDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CFirst_demoDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CFirst_demoDlg, CDialog)
	//{{AFX_MSG_MAP(CFirst_demoDlg)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFirst_demoDlg message handlers

BOOL CFirst_demoDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	CenterWindow(GetDesktopWindow());	// center to the hpc screen

	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CFirst_demoDlg::OnButton1() 
{
	I8092MF.
}















void CFirst_demoDlg::OnButton1() 
{
	// TODO: Add your control notification handler code here
	//====='Step 1 Driver init
	if  (!Driver_Open)
	{
		I8092MF.REGISTRATION(cardNo,1);
		Driver_Open = true;
    }
	//====='Step 2 CONFIG IO
	I8092MF.RESET_CARD (cardNo);
    I8092MF.SET_PULSE_MODE (cardNo, AXIS_XY, 2);	//set the pulse output mode
    I8092MF.SET_ALARM (cardNo, AXIS_XY, 0, 0);	//disable the SERVO ALARM Input
    I8092MF.SET_ENCODER (cardNo, AXIS_XY, 0, 0, 0);//set the encoder input type
    I8092MF.SET_MAX_V (cardNo, AXIS_XY, 16000);	//set the max speed for XY
    I8092MF.EXD_DISABLE (cardNo, AXIS_XY);		//set the external input Off
    I8092MF.SET_LP (cardNo, AXIS_XY, 0);			//set the Logic position =0
    I8092MF.SET_EP (cardNo, AXIS_XY, 0);			//set the Encoger position =0
    I8092MF.SET_A (cardNo, AXIS_XY, 1000);		//set the Acc =1000
    I8092MF.SERVO_ON (cardNo, AXIS_XY);			//set the Servo_ON to servo motors
	//======'Step 3 Check ERROR
	WORD KK=0;
	KK=I8092MF.GET_ERROR(cardNo);
	CString MSGG;
	if (KK != YES)
	{
		//No ERROR: Step 4 Move X axis
		BYTE axis=AXIS_X;  //for AXIS_X it can be to AXIS_XY
		I8092MF.SET_MAX_V(cardNo, axis, 20000); 
		I8092MF.NORMAL_SPEED(cardNo, axis, 0);		//set axis as Symmetrical T curve mode
		I8092MF.SET_V(cardNo, axis, 20000);			//set v=10000 PPS
		I8092MF.SET_A(cardNo, axis, 100000);		//set acc=100000 PPS/S
		I8092MF.SET_SV(cardNo, axis, 10);			//set start speed=1000 PPS
		I8092MF.SET_AO(cardNo, axis, 0);			//set offset pulse (at SV speed)= 0 PS
		I8092MF.FIXED_MOVE(cardNo, axis, 10000);	//run the fixed 10000 Pulse move.
		while (I8092MF.STOP_WAIT(cardNo, axis) == NO)
		{
			DoEvents();
			Sleep(1);
			//wait for axis to stop
		}
		long AA=I8092MF.GET_LP(cardNo,axis);    //Get X Now position
	}
	else
	{
		//Please check the ERROR CODE
        //Get X ERROR CODE
		KK=I8092MF.GET_ERROR_CODE(cardNo, AXIS_X);
		//Get Y ERROR CODE
		KK=I8092MF.GET_ERROR_CODE(cardNo, AXIS_Y);
		/*/
		//Get Z ERROR CODE
		KK=I8092MF.GET_ERROR_CODE(cardNo, AXIS_Z);
		//Get U ERROR CODE
		KK=I8092MF.GET_ERROR_CODE(cardNo, AXIS_U);
		//====================================
		/*/
	}
}
