disettingdlg.cpp

来自「16 relay output channels and 16 isolated」· C++ 代码 · 共 155 行

CPP
155
字号
// DISettingDlg.cpp : implementation file
//

#include "stdafx.h"
#include "1758di_int.h"
#include "DISettingDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CDISettingDlg dialog


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


void CDISettingDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDISettingDlg)
	DDX_Control(pDX, IDC_PortList, m_PortList);
	DDX_Control(pDX, IDC_ChanList, m_ChanList);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDISettingDlg, CDialog)
	//{{AFX_MSG_MAP(CDISettingDlg)
	ON_LBN_SELCHANGE(IDC_PortList, OnSelchangePortList)
	ON_CLBN_CHKCHANGE(IDC_PortList, OnChekchangePortList)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDISettingDlg message handlers

BOOL CDISettingDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	CString str;
	USHORT DICCheck = 0;
	DIPortNum = DIChanNum / 8;
	m_ChanList.SetColumnWidth(80);
	

	for(int i=0; i< DIChanNum; i++)
	{
		str.Format(" P%X_IDI%d", i / 8, i % 8);
		m_ChanList.AddString(str);
	}
	for( i=0; i< DIChanNum; i++)
	{			
		DICCheck = DISetting[i / 8 ] & ( 1 << (i % 8) );	
		if( DICCheck >0 )
			m_ChanList.SetCheck( i, 1 );
		else
			m_ChanList.SetCheck( i, 0 );
		
	}
	for( i=0; i< DIPortNum ; i++)
	{
		str.Format(" Port %X", i);
		m_PortList.AddString(str);
	}
	for( i=0; i< DIPortNum ; i++)
	{
		if( DISetting[i] == 0xFF )
			m_PortList.SetCheck(i, 1);
		else if ( DISetting[i] == 0 )
			m_PortList.SetCheck(i, 0);
		else
			m_PortList.SetCheck(i, 2);
		

		
	}
	switch( DISettingFlag )
	{
	case FallingTrigger:
		SetDlgItemText( IDC_INFO, "Enable or disable Falling trigger for every DI channel:" );
		break;
	case RisingTrigger:
		SetDlgItemText( IDC_INFO, "Enable or disable Rising trigger for every DI channel: " );
		break;
	case FilterEnabled:
		SetDlgItemText( IDC_INFO, "Enable or disable Filter for every DI channel:" );
		break;
   case InterruptEnabled:
      SetDlgItemText( IDC_INFO, "Enable or disable Interrupt for every DI channel:" );
      break;      
	default:
		break;
	}		
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CDISettingDlg::OnSelchangePortList() 
{
	// TODO: Add your control notification handler code here
	
}
void CDISettingDlg::OnChekchangePortList() 
{
	// TODO: Add your control notification handler code here
	for (int i=0; i< DIPortNum; i++)
	{
		int intCheck=m_PortList.GetCheck (i);
		if( intCheck != 2)
		{
			for (int j=0; j<8; j++)
			{
				m_ChanList.SetCheck( i*8+j, intCheck );
			}
		}
		
	}
	
}


void CDISettingDlg::OnOK() 
{
	// TODO: Add extra validation here
	USHORT DIValue = 0;
	for (int i=0; i< DIChanNum; i++)
	{
		int intCheck=m_ChanList.GetCheck (i);

		DIValue = 1 << ( i % 8 );		
		DIValue = ~DIValue;
		DISetting[i / 8 ] &=  DIValue;

		if( intCheck == 0) 
			DIValue = 0 << ( i%8 );
		else
			DIValue = 1 << ( i%8 );
		DISetting[i / 8 ] |=  DIValue;
		
	}	
	CDialog::OnOK();
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?