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

📄 outputdatadlg.cpp

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

#include "stdafx.h"
#include "DataAcquire.h"
#include "OutputDataDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// COutputDataDlg dialog


COutputDataDlg::COutputDataDlg(CWnd* pParent /*=NULL*/)
	: CDialog(COutputDataDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(COutputDataDlg)
	m_analOutput = 0.0;
	m_digitalOutput = _T("0");
	m_high = 0.0;
	m_low = 0.0;
	m_deviceName = _T("NO DEVICE");
	m_errorCode = 0;
	m_errorMessage = _T("");
	//}}AFX_DATA_INIT
}


void COutputDataDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(COutputDataDlg)
	DDX_Control(pDX, IDC_CHANNEL, m_channel);
	DDX_Control(pDX, IDC_OUTCHANNEL, m_outChannel);
	DDX_Control(pDX, IDC_INTERNAL, m_internal);
	DDX_Control(pDX, IDC_EXTERNAL, m_external);
	DDX_Control(pDX, IDC_ADVAOCTRL1, m_AdvAO);
	DDX_Text(pDX, IDC_ANALOUTPUT, m_analOutput);
	DDX_Text(pDX, IDC_DIGTALOUTPUT, m_digitalOutput);
	DDX_Text(pDX, IDC_HIGH, m_high);
	DDX_Text(pDX, IDC_LOW, m_low);
	DDX_Text(pDX, IDC_DEVICENAME, m_deviceName);
	DDX_Text(pDX, IDC_ERRORCODE, m_errorCode);
	DDX_Text(pDX, IDC_ERRORMESSAGE, m_errorMessage);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(COutputDataDlg, CDialog)
	//{{AFX_MSG_MAP(COutputDataDlg)
	ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
	ON_BN_CLICKED(IDC_SELDEVICE, OnSeldevice)
	ON_BN_CLICKED(IDC_INTERNAL, OnInternal)
	ON_BN_CLICKED(IDC_EXTERNAL, OnExternal)
	ON_BN_CLICKED(IDC_UPDATE, OnUpdate)
	ON_BN_CLICKED(IDC_ANALSEND, OnAnalsend)
	ON_BN_CLICKED(IDC_DIGITALSEND, OnDigitalsend)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// COutputDataDlg message handlers

void COutputDataDlg::OnButton5() 
{
	// TODO: Add your control notification handler code here
	
}

void COutputDataDlg::OnSeldevice() 
{
	// TODO: Add your control notification handler code here
		try
	{
		long channelCount;
		char  strTemp[100];
		char str[10] ;
		m_AdvAO.SelectDevice();
		m_deviceName = m_AdvAO.GetDeviceName();
		UpdateData( FALSE );
		channelCount = m_AdvAO.GetChannelMaxNumber();
		m_channel.ResetContent();
		m_outChannel.ResetContent();
		for ( int i=0; i < channelCount ; i++)
		{
			 _itoa( i, strTemp, 10 );
			strcpy( str, "Channel" );
			strcat( str, strTemp );   
			m_channel.AddString(str);
			m_outChannel.AddString(str);
		}
		if ( channelCount > 0)
		{
			long i;
			m_channel.SetCurSel( 0 );
			m_outChannel.SetCurSel( 0 );
			m_AdvAO.GetValueRange( m_channel.GetCurSel(), &m_low, &m_high );
			UpdateData( FALSE );
		//	m_AdvAO.SetChannelNow(  m_selChan.GetCurSel() );
		/*		i = m_AdvAO.GetDataPhysics();
		if ( i == 0)
			{
				m_voltageType.SetCheck(1);
				m_currentType.SetCheck(0);
			}
			else
			{
				m_voltageType.SetCheck(0);
				m_currentType.SetCheck(1);
			}*/
			i = m_AdvAO.GetDataReferenceSource();
			if ( i == 0)
			{
				m_internal.SetCheck(1);
				m_external.SetCheck(0);
			}
			else
			{
				m_internal.SetCheck(0);
				m_external.SetCheck(1);
			}
		}
	}
	catch ( ... )
	{
		m_errorCode = m_AdvAO.GetLastErrorCode();
		m_errorMessage = m_AdvAO.GetLastErrorMessage();
		UpdateData( FALSE );
	}
}

void COutputDataDlg::OnInternal() 
{
	// TODO: Add your control notification handler code here
	m_external.SetCheck( 0 );
	m_AdvAO.SetDataReferenceSource( 0 );
}

void COutputDataDlg::OnExternal() 
{
	// TODO: Add your control notification handler code here
	m_internal.SetCheck( 0 ) ;
	m_AdvAO.SetDataReferenceSource( 1 );
}

void COutputDataDlg::OnUpdate() 
{
	// TODO: Add your control notification handler code here
	try
	{
		if ( m_channel.GetCount() > 0)
		{  
			UpdateData( TRUE );
			m_AdvAO.SetValueRange( m_channel.GetCurSel(), m_low, m_high );
		}
	}
	catch( ... )
	{	
		m_errorCode = m_AdvAO.GetLastErrorCode();
		m_errorMessage = m_AdvAO.GetLastErrorMessage();
		UpdateData( FALSE );
	}
}

void COutputDataDlg::OnAnalsend() 
{
	// TODO: Add your control notification handler code here
	try
	{
		if ( m_outChannel.GetCount() > 0 )
		{
		UpdateData( TRUE );
		int i = m_outChannel.GetCurSel();
		m_AdvAO.SetChannelNow( m_outChannel.GetCurSel() );
		m_AdvAO.SetDataAnalog( m_analOutput);
		}
	}
	catch( ... )
	{
		m_errorCode = m_AdvAO.GetLastErrorCode();
		m_errorMessage = m_AdvAO.GetLastErrorMessage();
		UpdateData( FALSE );
	}
}

void COutputDataDlg::OnDigitalsend() 
{
	// TODO: Add your control notification handler code here
	try
	{
		if ( m_outChannel.GetCount() > 0 )
		{
		UpdateData( TRUE );
	//	char mm[10]="aa";
	//	int i = atoi(mm);
	//	CString mm = "ff";
        int i = StringtoInt( m_digitalOutput);
		m_AdvAO.SetChannelNow( m_outChannel.GetCurSel() );
		m_AdvAO.SetDataDigital( i );
		}
	}
	catch( ... )
	{		
		m_errorCode = m_AdvAO.GetLastErrorCode();
		m_errorMessage = m_AdvAO.GetLastErrorMessage();
		UpdateData( FALSE );
	}
}

int COutputDataDlg::StringtoInt(CString intString)
{
	int lenth;
	int ret;
	int outInt;
	CString  Strtemp ;
	CString temp;
	lenth = intString.GetLength();
/*	Strtemp = new CString[lenth];
	if ( Strtemp ==NULL )
	{
		MessageBox(" ");
		exit( 1 );
	} */
	Strtemp = intString;
	outInt = 0;
	int i;
	for(  i = 0;i < lenth ;i++)
	{   
		temp = Strtemp.Mid( i, 1);
		ret = -1;
		if ( temp == "0")
			ret = 0;
		if ( temp == "1")
			ret = 1;
		if ( temp == "2")
			ret = 2;
		if ( temp == "3")
			ret = 3;
		if ( temp == "4")
			ret = 4;
		if ( temp == "5")
			ret = 5;
		if (temp == "6")
			ret = 6;
		if ( temp == "7")
			ret = 7;
		if ( temp == "8")
			ret = 8;
		if ( temp == "9")
			ret = 9;
		if ( temp == "a" ||temp == "A")
			ret = 10;
		if ( temp == "b" || temp == "B")
			ret = 11;
		if ( temp == "c" || temp == "C")
			ret = 12;
		if ( temp == "d" || temp == "D")
			ret = 13;
		if ( temp == "e" || temp == "E")
			ret = 14;
		if ( temp == "f" || temp == "F")
			ret = 15;
		if ( ret != -1 )
		{
			outInt = outInt * 16  + ret;
		}
		else
			MessageBox("Please input legal number!");
	}
	return outInt;
}

⌨️ 快捷键说明

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