// IOTest.cpp: implementation file 
// 

# include "stdafx.h" 
# include "DEMO.h" 
# include "IOTest.h" 
# include "CtrlCard.h" 

extern CCtrlCard g_CtrlCard; 

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

# define TESTTIMER 2001 // IO detection timer 
///////////////////////////////////////////////////////////////////////////// 
// CIOTest dialog 


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


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


BEGIN_MESSAGE_MAP (CIOTest, CDialog) 
// ((AFX_MSG_MAP (CIOTest) 
ON_WM_TIMER () 
ON_BN_CLICKED (IDC_OUT_ALLOPEN, OnOutAllopen) 
ON_BN_CLICKED (IDC_OUT_ALLCLOSE, OnOutAllclose) 
ON_WM_DESTROY () 
ON_BN_CLICKED (IDC_BUTTON_OUTALL, OnButtonOutall) 
ON_BN_CLICKED (IDC_BUTTON_INALL, OnButtonInall) 
//)) AFX_MSG_MAP 
END_MESSAGE_MAP () 

///////////////////////////////////////////////////////////////////////////// 
// CIOTest message handlers 

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

SetTimer (TESTTIMER, 100, NULL); // Start Timer IO test 

return TRUE; // return TRUE unless you set the focus to a control 
// EXCEPTION: OCX Property Pages should return FALSE 
} 
//*************** Signal input **********************// 
void CIOTest:: CheckInput () 
{ 
	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, IDC_IN36, IDC_IN37, IDC_IN38, IDC_IN39, 
IDC_IN40, IDC_IN41, IDC_IN42, IDC_IN43, IDC_IO0, IDC_IO1, IDC_IO2, IDC_IO3, IDC_IO4, 
IDC_IO5, IDC_IO6, IDC_IO7, IDC_IO8, IDC_IO9, IDC_IO10, IDC_IO11, IDC_IO12, IDC_IO13, 
IDC_IO14, IDC_IO15}; 
CButton * btn; 

int value; 

for (int i = 0; i <60; i ++) 
{ 
value = g_CtrlCard.Read_Input (i); 

btn = (CButton *) GetDlgItem (nID [i]); 

btn-> SetCheck (value == 0? 1:0); 
} 


} 
//****************** Signal output ***********************// 
void CIOTest:: CheckOutput () 
{ 
	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}; 

CButton * btn; 

for (int i = 0; i <16; i ++) 
{ 

btn = (CButton *) GetDlgItem (nID [i]); 

g_CtrlCard.Write_Output (i, btn-> GetCheck ()); 

} 

} 
//************** Timer ****************// 
void CIOTest:: OnTimer (UINT nIDEvent) 
{ 
CheckInput (); // input signal detection 

CheckOutput (); // test output signal 


CDialog:: OnTimer (nIDEvent); 
} 

//*************** Output full *******************// 
void CIOTest:: OnOutAllopen () 
{ 
	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}; 

CButton * btn; 

for (int i = 0; i <16; i ++) 
{ 

btn = (CButton *) GetDlgItem (nID [i]); 

btn-> SetCheck (1); 

g_CtrlCard.Write_Output (i, 1); 

} 

} 
//**************** Output fully closed ***************// 
void CIOTest:: OnOutAllclose () 
{ 
	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}; 

CButton * btn; 

for (int i = 0; i <16; i ++) 
{ 

btn = (CButton *) GetDlgItem (nID [i]); 

btn-> SetCheck (0); 

g_CtrlCard.Write_Output (i, 0); 

} 

} 

//********** Exit IO detection ***************// 
void CIOTest:: OnDestroy () 
{ 
CDialog:: OnDestroy (); 

OnOutAllclose (); // output all off 

KillTimer (TESTTIMER); // close the IO detection timer 

} 

// General output 
void CIOTest:: OnButtonOutall () 
{ 
	int nID [] = {IDC_IO0, IDC_IO1, IDC_IO2, IDC_IO3, IDC_IO4, 
IDC_IO5, IDC_IO6, IDC_IO7, IDC_IO8, IDC_IO9, 
IDC_IO10, IDC_IO11, IDC_IO12, IDC_IO13, 
IDC_IO14, IDC_IO15}; 

g_CtrlCard.Set_IoMode (0,0); 

} 

// General purpose input 
void CIOTest:: OnButtonInall () 
{ 
	int nID [] = {IDC_IO0, IDC_IO1, IDC_IO2, IDC_IO3, IDC_IO4, 
IDC_IO5, IDC_IO6, IDC_IO7, IDC_IO8, IDC_IO9, 
IDC_IO10, IDC_IO11, IDC_IO12, IDC_IO13, 
IDC_IO14, IDC_IO15}; 

g_CtrlCard.Set_IoMode (1,1); 

} 
