⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 inputseldlg.cpp

📁 研华4711a数据采集卡输出和输入界面
💻 CPP
字号:
// InputSelDlg.cpp : implementation file
//

#include "stdafx.h"
#include "DataAcquire.h"
#include "InputSelDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CInputSelDlg dialog

CInputSelDlg::CInputSelDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CInputSelDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CInputSelDlg)
	m_devName = _T("No Device");
	m_devNumber = _T("0");
	//}}AFX_DATA_INIT
}


void CInputSelDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CInputSelDlg)
	DDX_Control(pDX, IDC_CHANNEL4, m_channel4);
	DDX_Control(pDX, IDC_CHANNEL3, m_channel3);
	DDX_Control(pDX, IDC_CHANNEL2, m_channel2);
	DDX_Control(pDX, IDC_CHANNEL1, m_channel1);
	DDX_Control(pDX, IDC_SIGNALCONNECTION, m_cmbSignalConnection);
	DDX_Control(pDX, IDC_ADVAI1, m_AdvAI);
	DDX_Text(pDX, IDC_DEVICENAME, m_devName);
	DDX_Text(pDX, IDC_DEVICENUMBER, m_devNumber);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CInputSelDlg, CDialog)
	//{{AFX_MSG_MAP(CInputSelDlg)
	ON_BN_CLICKED(IDC_SET_RANGE, OnSetRange)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_CBN_SELCHANGE(IDC_CHANNEL1, OnSelchangeChannelnow)
	ON_BN_CLICKED(IDC_SCAN, OnScan)
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CInputSelDlg message handlers

void CInputSelDlg::OnSetRange() 
{
	// TODO: Add your control notification handler code here
	double lowBound = 0;
	double highBound = 0;
	long   gainCode = 0;
	CString strTemp;

	GetDlgItemText(IDC_LOWBOUNDARY, strTemp );
	lowBound = atof( strTemp );
	GetDlgItemText(IDC_HIGHBOUNDARY, strTemp );
	highBound = atof( strTemp );
	// Set the actual input value range
	m_AdvAI.SetValueRange( m_AdvAI.GetChannelNow(),lowBound,highBound);
	// Get the input value range of the current channel
	m_AdvAI.GetValueRange( m_AdvAI.GetChannelNow(),&lowBound,&highBound,&gainCode);
	// Update UI components' content
	strTemp.Format( _T("%.2f"),lowBound);
	SetDlgItemText(IDC_LOWBOUNDARY, strTemp );
	strTemp.Format( _T("%.2f"),highBound);
	SetDlgItemText(IDC_HIGHBOUNDARY, strTemp );

	SetDlgItemText(IDC_DATAVALUERANGE, m_AdvAI.GetDataValueRange());
}

void CInputSelDlg::OnButton1() 
{
	// TODO: Add your control notification handler code here
		m_AdvAI.SelectDevice();
	// Update UI components' content
	    SetProperties();
}

void CInputSelDlg::SetProperties()
{
    	CString strTemp;
	char str[100];
	char strT[100];
	int i;
	long channelNow;
	try{
		// Update UI components' content
		strTemp.Format(_T("%ld"), m_AdvAI.GetDeviceNumber() );	
		SetDlgItemText( IDC_DEVICENUMBER, strTemp );
		strTemp.Format(_T("%s"), m_AdvAI.GetDeviceName() );	
		SetDlgItemText( IDC_DEVICENAME, strTemp );
		strTemp.Format(_T("%ld"), m_AdvAI.GetResolution() );
		SetDlgItemText( IDC_RESOLUTION, strTemp );
		m_cmbSignalConnection.SetCurSel( m_AdvAI.GetChannelSignalConnection() );
	
	   m_channel1.ResetContent();
  
       for( i = 0; i<m_AdvAI.GetChannelMaxNumber(); i++ )
		{
			_itoa( i, str, 10 );
			strcpy( strT, "Channel " );
			strcat( strT, str );
			m_channel1.AddString( strT );
			m_channel2.AddString( strT );
			m_channel3.AddString( strT );
			m_channel4.AddString( strT );
		}
		// Set the default selected channel
		if (m_channel1.GetCount() > 0 )
		{
		    channelNow=m_AdvAI. GetChannelNow();
			m_channel1.SetCurSel(channelNow);
		}

		// Set the default selected channel
		if ( m_channel2.GetCount() > 0 )
		{
			channelNow=m_AdvAI. GetChannelNow();
			m_channel2.SetCurSel(channelNow);
		}

		if ( m_channel3.GetCount() > 0 )
		{
			channelNow=m_AdvAI. GetChannelNow();
			m_channel3.SetCurSel(channelNow);
		}

		if ( m_channel4.GetCount() > 0 )
		{
			channelNow=m_AdvAI. GetChannelNow();
			m_channel4.SetCurSel(channelNow);
		}



		OnSelchangeChannelnow();
	}
	catch( CException * err )
	{
		strTemp.Format(_T("%ld"), m_AdvAI.GetLastErrorCode() );	
		SetDlgItemText( IDC_ERRORCODE, strTemp );
		strTemp.Format(_T("%s"), m_AdvAI.GetLastErrorMessage() );	
		SetDlgItemText( IDC_ERRORMESSAGE, strTemp );
	//	MessageBox(strTemp,"ERROR",MB_OK);
		err->Delete();
	}
}


void CInputSelDlg::OnSelchangeChannelnow() 
{
	double lowBound = 0;
	double highBound = 0;
	long   gainCode = 0;
	long   channelNow;
	CString strTemp;
	
	// Set the current channel
	channelNow = m_channel1.GetCurSel();
	m_AdvAI.SetChannelNow( channelNow );
	// Update the range text
	strTemp = m_AdvAI.GetDataValueRange();   
	// Update the signal connection selection
	SetDlgItemText( IDC_DATAVALUERANGE, strTemp );
	m_cmbSignalConnection.SetCurSel( m_AdvAI.GetChannelSignalConnection() );
	// Get the input value range of the current channel
	m_AdvAI.GetValueRange( channelNow,&lowBound,&highBound,&gainCode);
	// Update the range value text
	strTemp.Format( _T("%.2f"),highBound);
	SetDlgItemText( IDC_HIGHBOUNDARY,strTemp );
	strTemp.Format( _T("%.2f"),lowBound);
	SetDlgItemText( IDC_LOWBOUNDARY,strTemp );
}

BOOL CInputSelDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	m_cmbSignalConnection.AddString("Single-Ended");
	m_cmbSignalConnection.AddString("Differential");

	TimerFlag=0;
//	SetProperties();
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CInputSelDlg::OnScan() 
{
	// TODO: Add your control notification handler code here
	 m_Timer=1;
	// Begin the scanning process
	if ( !TimerFlag )
	{
		TimerFlag = TRUE;              // Enable timer
		SetTimer( m_Timer,500, NULL);
		SetDlgItemText( IDC_SCAN, "停止");
	}
	// Stop previous scanning process
	else
	{
		TimerFlag = FALSE;             // Disable timer
		KillTimer( m_Timer );
		SetDlgItemText( IDC_SCAN, "开始");
	}
}

void CInputSelDlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	double dataAnalog1;
	double dataAnalog2;
	double dataAnalog3;
	double dataAnalog4;
	double cha1=1;
	double cha2=1;
	CString strTemp;
	
	// Update the sampling data
	try
	{
	    m_AdvAI.SetChannelNow(m_channel1.GetCurSel());
		dataAnalog1 = m_AdvAI.GetDataAnalog();
		strTemp.Format(_T("%.6f"),dataAnalog1 );
		SetDlgItemText( IDC_DATAANALOG1, strTemp);

		 m_AdvAI.SetChannelNow(m_channel2.GetCurSel());
		dataAnalog2 = m_AdvAI.GetDataAnalog();
		strTemp.Format(_T("%.6f"),dataAnalog2 );
		SetDlgItemText( IDC_DATAANALOG2, strTemp);
			
         m_AdvAI.SetChannelNow(m_channel3.GetCurSel());
		dataAnalog3 = m_AdvAI.GetDataAnalog();
		strTemp.Format(_T("%.6f"),dataAnalog3 );
		SetDlgItemText( IDC_DATAANALOG3, strTemp);

		 m_AdvAI.SetChannelNow(m_channel4.GetCurSel());
		dataAnalog4= m_AdvAI.GetDataAnalog();
		strTemp.Format(_T("%.6f"),dataAnalog4 );
		SetDlgItemText( IDC_DATAANALOG4, strTemp);

        cha1=dataAnalog1-dataAnalog2;
	    strTemp.Format(_T("%.6f"),cha1 );
		SetDlgItemText( IDC_CHA1, strTemp);
		
		 cha2=dataAnalog3-dataAnalog4;
	    strTemp.Format(_T("%.6f"),cha2 );
		SetDlgItemText( IDC_CHA2, strTemp);
    /*	dataDigital = m_AdvAI.GetDataDigital();
		strTemp.Format(_T("%x"), dataDigital );
		SetDlgItemText( IDC_DATADIGITAL, strTemp);
		
		dataDigital1 = m_AdvAI.GetDataDigital();
		strTemp.Format(_T("%x"), dataDigital1 );
		SetDlgItemText( IDC_DATADIGITAL1, strTemp);*/
	}
	catch (CException * err) 
	{
		TimerFlag = FALSE;             // Disable timer
		KillTimer( m_Timer );
		SetDlgItemText( IDC_SCAN, "Start");
		strTemp.Format(_T("%ld"), m_AdvAI.GetLastErrorCode() );	
		SetDlgItemText( IDC_ERRORCODE, strTemp );
		strTemp.Format(_T("%s"), m_AdvAI.GetLastErrorMessage() );	
		SetDlgItemText( IDC_ERRORMESSAGE, strTemp );
		MessageBox(strTemp,"ERROR",MB_OK);
		err->Delete();
		
	}
	CDialog::OnTimer(nIDEvent);
}

⌨️ 快捷键说明

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