www.pudn.com > pci7222vc.rar > Dio.cpp


// dio.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "pci7222.h" 
#include "dio.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
mPCH365_IO_REG mBaseAddr; 
///////////////////////////////////////////////////////////////////////////// 
// dio dialog 
 
 
dio::dio(CWnd* pParent /*=NULL*/) 
	: CDialog(dio::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(dio) 
	m_iIO = -1; 
	m_strDo1 = _T(""); 
	m_strDo2 = _T(""); 
	m_strIn1 = _T(""); 
	m_strIn2 = _T(""); 
	//}}AFX_DATA_INIT 
} 
 
 
void dio::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(dio) 
	DDX_Radio(pDX, IDC_DI_RADIO, m_iIO); 
	DDX_Text(pDX, IDC_EDIT1, m_strDo1); 
	DDX_Text(pDX, IDC_EDIT2, m_strDo2); 
	DDX_Text(pDX, IDC_INPUT1, m_strIn1); 
	DDX_Text(pDX, IDC_INPUT2, m_strIn2); 
	//}}AFX_DATA_MAP 
} 
 
 
BEGIN_MESSAGE_MAP(dio, CDialog) 
	//{{AFX_MSG_MAP(dio) 
	ON_BN_CLICKED(IDC_DIO_EXIT, OnDioExit) 
	ON_WM_TIMER() 
	ON_BN_CLICKED(IDC_DI_RADIO, OnDiRadio) 
	ON_BN_CLICKED(IDC_DO_RADIO, OnDoRadio) 
	ON_BN_CLICKED(IDC_ALL_PUT, OnAllPut) 
	ON_BN_CLICKED(IDC_HELP_BUTTON, OnHelpButton) 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// dio message handlers 
 
BOOL dio::OnInitDialog()  
{ 
	CDialog::OnInitDialog(); 
	 
	// TODO: Add extra initialization here 
	  
    m_iIO=0; 
    m_strIn1=_T("1--8路开关量输入显示(16进制):"); 
	m_strIn2=_T("9--16路开关量输入显示(16进制):"); 
	UpdateData(false); 
	GetDlgItem(IDC_EDIT1)->EnableWindow(false); 
	GetDlgItem(IDC_EDIT2)->EnableWindow(false); 
	SetTimer(1,100,NULL); 
	return TRUE;  // return TRUE unless you set the focus to a control 
	              // EXCEPTION: OCX Property Pages should return FALSE 
} 
 
void dio::OnDioExit()  
{ 
	// TODO: Add your control notification handler code here 
	 
	OnOK(); 
} 
 
void dio::OnTimer(UINT nIDEvent)  
{ 
	// TODO: Add your message handler code here and/or call default 
	UCHAR cByte1,cByte2; 
    if(m_iIO==0) 
	{ 
		 
	    GetDlgItem(IDC_EDIT1)->EnableWindow(false); 
	    GetDlgItem(IDC_EDIT2)->EnableWindow(false); 
		m_strIn1=_T("1--8路开关量输入显示(16进制):"); 
	    m_strIn2=_T("9--16路开关量输入显示(16进制):"); 
		CH365mReadIoByte( 0, &mBaseAddr->mCh365IoPort[4], &cByte1 ); 
        CH365mReadIoByte( 0, &mBaseAddr->mCh365IoPort[5], &cByte2 ); 
		//读开关量 
		m_strDo1.Format("%x",cByte1); 
		m_strDo2.Format("%x",cByte2); 
        UpdateData(false); 
	} 
	CDialog::OnTimer(nIDEvent); 
} 
 
void dio::OnDiRadio()  
{ 
	// TODO: Add your control notification handler code here 
	m_iIO=0; 
	m_strDo1 = _T(""); 
	m_strDo2 = _T(""); 
	m_strIn1=_T("1--8路开关量输入显示(16进制):"); 
	m_strIn2=_T("9--16路开关量输入显示(16进制):"); 
	UpdateData(false); 
	GetDlgItem(IDC_EDIT1)->EnableWindow(false); 
	GetDlgItem(IDC_EDIT2)->EnableWindow(false); 
	SetTimer(1,100,NULL); 
} 
 
void dio::OnDoRadio()  
{ 
	// TODO: Add your control notification handler code here 
	KillTimer(1); 
	UpdateData(true); 
	int ir; 
    ir=MessageBox( 
		"你确定设置为输出方式吗?", 
		"CH365开关量测试界面", 
		MB_YESNO + MB_ICONQUESTION); 
	if (ir==IDNO) 
	{ 
		int i=SetTimer(1,100,NULL); 
        m_iIO=0; 
		m_strIn1=_T("1--8路开关量输入显示(16进制):"); 
	    m_strIn2=_T("9--16路开关量输入显示(16进制):"); 
		if(i==0) 
		AfxMessageBox("cannot install timer!"); 
		UpdateData(FALSE); 
		GetDlgItem(IDC_EDIT1)->EnableWindow(false); 
	    GetDlgItem(IDC_EDIT2)->EnableWindow(false); 
	} 
	else 
	{ 
		GetDlgItem(IDC_EDIT1)->EnableWindow(true); 
	    GetDlgItem(IDC_EDIT2)->EnableWindow(true); 
		m_iIO=1; 
		m_strIn1=_T("1--8路开关量(16进制)输出:"); 
	    m_strIn2=_T("9--16路开关量(16进制)输出:"); 
		UpdateData(false); 
	} 
} 
 
void dio::OnAllPut()  
{ 
	// TODO: Add your control notification handler code here 
	UCHAR cByte1,cByte2; 
    if(m_iIO==1) 
	{ 
 
		 UpdateData(true); 
		 sscanf(m_strDo1,"%x",&cByte1); 
		 sscanf(m_strDo2,"%x",&cByte2); 
         CH365mWriteIoByte(0,&mBaseAddr->mCh365IoPort[6],cByte1); 
		 CH365mWriteIoByte(0,&mBaseAddr->mCh365IoPort[7],cByte2); 
		 //写开关量 
	} 
} 
 
void dio::OnHelpButton()  
{ 
	// TODO: Add your control notification handler code here 
	m_help.DoModal(); 
}