// DialogIOTestDlg.cpp : implementation file
//

#include "stdafx.h"
#include "8949G1VC.h"
#include "DialogIOTestDlg.h"
#include "CtrlCardSingletion.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDialogIOTestDlg dialog


CDialogIOTestDlg::CDialogIOTestDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CDialogIOTestDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDialogIOTestDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


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


BEGIN_MESSAGE_MAP(CDialogIOTestDlg, CDialog)
	//{{AFX_MSG_MAP(CDialogIOTestDlg)
	ON_BN_CLICKED(IDC_OUT_ALLOPEN, OnOutAllopen)
	ON_WM_TIMER()
	ON_BN_CLICKED(IDC_OUT_ALLCLOSE, OnOutAllclose)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDialogIOTestDlg message handlers

BOOL CDialogIOTestDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	SetTimer(IOTESTTIMER, 100, NULL);
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CDialogIOTestDlg::OnOutAllopen() 
{
	// TODO: Add your control notification handler code here
	int nID[]={IDC_OUT0, IDC_OUT1, IDC_OUT2, IDC_OUT3, IDC_OUT4, IDC_OUT5, IDC_OUT6, IDC_OUT7,
		IDC_OUT8, IDC_OUT9, IDC_OUT10, IDC_OUT11, IDC_OUT12, IDC_OUT13, IDC_OUT14, IDC_OUT15, 
		IDC_OUT16,IDC_OUT17, IDC_OUT18, IDC_OUT19, IDC_OUT20, IDC_OUT21, IDC_OUT22, IDC_OUT23, IDC_OUT24, 
		IDC_OUT25, IDC_OUT26, IDC_OUT27, IDC_OUT28, IDC_OUT29, IDC_OUT30, IDC_OUT31};
	CButton *pBtn = NULL;
	
	for (int i=0; i<32; i++)
	{
		pBtn = (CButton*)GetDlgItem(nID[i]);
		pBtn->SetCheck(1);
		CCtrlCardSingletion::Instance()->WriteOutput(i, 1);
	}
}

void CDialogIOTestDlg::OnTimer(UINT_PTR nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	int nID[] = {IDC_IN0, IDC_IN1, IDC_IN2, IDC_IN3, IDC_IN4, IDC_IN5, IDC_IN6, IDC_IN7,
		IDC_IN8, IDC_IN9, IDC_IN10, IDC_IN11, IDC_IN12, IDC_IN13, IDC_IN14, IDC_IN15,
		IDC_IN16, IDC_IN17, IDC_IN18, IDC_IN19, IDC_IN20, IDC_IN21, IDC_IN22, IDC_IN23,
		IDC_IN24, IDC_IN25, IDC_IN26, IDC_IN27, IDC_IN28, IDC_IN29, IDC_IN30, IDC_IN31,
		IDC_IN32, IDC_IN33, IDC_IN34, IDC_IN35};
	
	CButton *pBtn = NULL;
	int nValue = -1;
// 	number      输入点(0-47)，其中0-18、36-47为快速输入点，19-35为慢速输入点
// 		其中，四个驱动轴的编码器信号(A相、B相、Z相)对应的端口为：
// 		IN36～IN39:	A1...A4	
// 		IN40～IN43:	B1...B4
// 		IN44～IN47:	Z1...Z4	
	for (int i=0; i<36; i++)
	{
		nValue = CCtrlCardSingletion::Instance()->ReadInput(i);
		pBtn = (CButton*)GetDlgItem(nID[i]);
		pBtn->SetCheck(nValue == 0 ? 1 : 0);
	}

	int nID1[]={IDC_OUT0, IDC_OUT1, IDC_OUT2, IDC_OUT3, IDC_OUT4, IDC_OUT5, IDC_OUT6, IDC_OUT7,
		IDC_OUT8, IDC_OUT9, IDC_OUT10, IDC_OUT11, IDC_OUT12, IDC_OUT13, IDC_OUT14, IDC_OUT15, 
		IDC_OUT16,IDC_OUT17, IDC_OUT18, IDC_OUT19, IDC_OUT20, IDC_OUT21, IDC_OUT22, IDC_OUT23, IDC_OUT24, 
		IDC_OUT25, IDC_OUT26, IDC_OUT27, IDC_OUT28, IDC_OUT29, IDC_OUT30, IDC_OUT31};
	CButton *pBtn1 = NULL;
	
	for (int i1=0; i1<32; i1++)
	{
		pBtn1 = (CButton*)GetDlgItem(nID1[i1]);
		CCtrlCardSingletion::Instance()->WriteOutput(i1, pBtn1->GetCheck());
	}
	CDialog::OnTimer(nIDEvent);
}

void CDialogIOTestDlg::OnOutAllclose() 
{
	// TODO: Add your control notification handler code here
	int nID[]={IDC_OUT0, IDC_OUT1, IDC_OUT2, IDC_OUT3, IDC_OUT4, IDC_OUT5, IDC_OUT6, IDC_OUT7,
		IDC_OUT8, IDC_OUT9, IDC_OUT10, IDC_OUT11, IDC_OUT12, IDC_OUT13, IDC_OUT14, IDC_OUT15, 
		IDC_OUT16,IDC_OUT17, IDC_OUT18, IDC_OUT19, IDC_OUT20, IDC_OUT21, IDC_OUT22, IDC_OUT23, IDC_OUT24, 
		IDC_OUT25, IDC_OUT26, IDC_OUT27, IDC_OUT28, IDC_OUT29, IDC_OUT30, IDC_OUT31};
	CButton *pBtn = NULL;
	
	for (int i=0; i<32; i++)
	{
		pBtn = (CButton*)GetDlgItem(nID[i]);
		pBtn->SetCheck(0);
		CCtrlCardSingletion::Instance()->WriteOutput(i, 0);
	}
}
