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

📄 nextdlg.cpp

📁 NI公司的PCI-6120四通道电压测量卡控制程序。该程序主要用VC实现对PCI-6120测量卡控制
💻 CPP
字号:
// NextDlg.cpp : implementation file
//

#include "stdafx.h"
#include "PCI_6120.h"
#include "NextDlg.h"
#include "nidaqex.h"

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

/////////////////////////////////////////////////////////////////////////////
// CNextDlg dialog


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


void CNextDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CNextDlg)
	DDX_Control(pDX, IDC_LIST1, m_list);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CNextDlg, CDialog)
	//{{AFX_MSG_MAP(CNextDlg)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_DO, OnDLineOutput)
	ON_BN_CLICKED(IDC_DPortOutput, OnDPortOutput)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CNextDlg message handlers

void CNextDlg::OnButton1() 
{
    i16 iStatus = 0;
    i16 iRetVal = 0;
    i16 iDevice = 1;
    i32 lTimeout = 180;
    i16 iInputMode = 0;
    i16 iInputRange = 20;
    i16 iPolarity = 0;
    i16 iDriveAIS = 0;
    i16 iChan = 0;
    i16 iGain = 1;
    static i16 piBuffer[30] = {0};
    static f64 pdVoltBuffer[30] = {0.0};
    f64 dAvgVoltage = 0.0;
    i16 iIgnoreWarning = 0;

    /* This sets a timeout limit (#Sec * 18ticks/Sec) so that if there
     is something wrong, the program won't hang on the DAQ_Op call. */
    
	iDevice= GetDlgItemInt(IDC_COMBO_DEVICE);
    iStatus = Timeout_Config(iDevice, lTimeout);
    iRetVal = NIDAQErrorHandler(iStatus, "Timeout_Config",
     iIgnoreWarning);

	iChan= GetDlgItemInt(IDC_COMBO_CHAN2);
	iInputMode= GetDlgItemInt(IDC_COMBO_inputMode);
	iInputRange= GetDlgItemInt(IDC_COMBO_inputRange);
    iStatus = AI_Configure(iDevice, iChan, iInputMode, iInputRange,iPolarity, iDriveAIS);
    iRetVal = NIDAQErrorHandler(iStatus, "AI_Configure",
     iIgnoreWarning);

    /* Acquire data from a single channel. */
    u32 ulCount = 30;
    f64 dSampRate = 300.0;
	dSampRate= GetDlgItemInt(IDC_COMBO_SampRate);
	ulCount= GetDlgItemInt(IDC_COMBO_ulCount);
    iStatus = DAQ_Op(iDevice, iChan, iGain, piBuffer, ulCount, dSampRate);
    iRetVal = NIDAQErrorHandler(iStatus, "DAQ_Op", iIgnoreWarning);
    

    /* The attenuation on the SCC-A10 is compensated internally in
     DAQ_VScale, provided that you have configured your SCC-A10 in the
     NI-DAQ Configuration Utility. If you have not configured your SCC-A10
     in the NI-DAQ Configuration Utility, the scaled data will be off by a
     factor of 10. */
	f64 dGainAdjust = 1.0;
    f64 dOffset = 0.0;
    iStatus = DAQ_VScale(iDevice, iChan, iGain, dGainAdjust, dOffset,
     ulCount, piBuffer, pdVoltBuffer);
    iRetVal = NIDAQErrorHandler(iStatus, "DAQ_VScale",
     iIgnoreWarning);

    iRetVal = NIDAQMean(pdVoltBuffer, ulCount, WFM_DATA_F64, &dAvgVoltage);
	CString str;
	str.Format(" The plot shows all channel data in order.");
    //printf(" The plot shows all channel data in order.\n");
	m_list.AddString(str);
    /* Plot acquired data */

    iRetVal = NIDAQPlotWaveform(pdVoltBuffer, ulCount, WFM_DATA_F64);
    str.Format(" The average voltage reading is %lf V.", dAvgVoltage);
    //printf(" The average voltage reading is %lf V.\n", dAvgVoltage);
	m_list.AddString(str);
    /* Disable timeouts. */

    iStatus = Timeout_Config(iDevice, -1);	
}

void CNextDlg::OnDLineOutput() 
{
    /*
     * Local Variable Declarations: 
     */

    i16 iStatus = 0;
    i16 iRetVal = 0;
    i16 iDevice = 1;
    i16 iPort = 0;
    i16 iLine = 0;
    i16 iDir = 1;
    i16 iStateON = 1;
    i16 iStateOFF = 0;
    i16 iIgnoreWarning = 0;

    /* Configure line as output. */

    /* NOTE: Some devices do not support DIG_Line_Config.  Use
     DIG_Prt_Config instead. */

	iPort= GetDlgItemInt(IDC_COMBO_port);
	iLine= GetDlgItemInt(IDC_COMBO_line);
	iDir= GetDlgItemInt(IDC_COMBO_dir);

	iDevice= GetDlgItemInt(IDC_COMBO_DEVICE);
    iStatus = DIG_Line_Config(iDevice, iPort, iLine, iDir);

    iRetVal = NIDAQErrorHandler(iStatus, "DIG_Line_Config",
     iIgnoreWarning);

 //   printf(" The digital state on port %d line %d is set to %d\n", iPort, iLine, iStateON);
	CString str;

	//str.Format("%d",iDir);	MessageBox(str);
	if(iDir== 0)	
	{
	//input
	//if( GetDlgItemInt(IDC_COMBO_ONOFF)==1)
	i16	iState= 0;
	{
		//status = DIG_In_Line (deviceNumber, port, line, state)
		iStatus = DIG_In_Line(iDevice, iPort, iLine, &iState);
		SetDlgItemInt(IDC_COMBO_ONOFF, iState);
		str.Format(" The digital state on port %d line %d is get to %d", iPort, iLine, iState);
		m_list.AddString(str);
	}
 
    iRetVal = NIDAQErrorHandler(iStatus, "DIG_Out_Line",
     iIgnoreWarning);
	}
	else
	{
	//output
	if( GetDlgItemInt(IDC_COMBO_ONOFF)==1)
	{
		iStatus = DIG_Out_Line(iDevice, iPort, iLine, iStateON);
		str.Format(" The digital state on port %d line %d is set to %d", iPort, iLine, iStateON);
		m_list.AddString(str);
	}
    else
	{
		iStatus = DIG_Out_Line(iDevice, iPort, iLine, iStateOFF);
		str.Format(" The digital state on port %d line %d is set to %d", iPort, iLine, iStateOFF);
		m_list.AddString(str);
	}
    iRetVal = NIDAQErrorHandler(iStatus, "DIG_Out_Line",
     iIgnoreWarning);
	}
  //  printf(" Hit any key to change it to %d\n", iStateOFF);

  //  iRetVal = NIDAQWaitForKey(0.0);

 //   printf(" The digital state on port %d line %d is set to %d\n", iPort, iLine, iStateOFF);

	
}

void CNextDlg::OnDPortOutput() 
{
    i16 iStatus = 0;
    i16 iRetVal = 0;
    i16 iDevice = 1;
    i16 iPort = 0;
    i16 iMode = 0;
    i16 iDir = 1;
    i32 iPattern = 0;
    i32 iNumLoops = 16;
    i16 iIgnoreWarning = 0;
    i16 iYieldON = 1;

    /* Configure port as output, no handshaking. */
	iPort= GetDlgItemInt(IDC_COMBO_port2);
	iMode= GetDlgItemInt(IDC_COMBO_mode);
	iDir= GetDlgItemInt(IDC_COMBO_dir2);

	iDevice= GetDlgItemInt(IDC_COMBO_DEVICE);
    iStatus = DIG_Prt_Config(iDevice, iPort, iMode, iDir);
    iRetVal = NIDAQErrorHandler(iStatus, "DIG_Prt_Config",
     iIgnoreWarning);
	CString str;
	m_list.AddString("DIG_Prt_Config");

	//str.Format("%d",iDir);	MessageBox(str);
	iNumLoops= GetDlgItemInt(IDC_COMBO_pattern);
	if(iDir== 1)		
	{//output
    //while ((iPattern < iNumLoops) && (iStatus == 0)) {
	while ((iPattern < iNumLoops)){
        iStatus = DIG_Out_Prt(iDevice, iPort, iPattern);
        iRetVal = NIDAQErrorHandler(iStatus, "DIG_Out_Prt",
         iIgnoreWarning);
		str.Format(" The digital pattern on port %d is set to (DECIMAL) %ld", iPort, iPattern);
		m_list.AddString(str);
        //printf(" The digital pattern on port %d is set to (DECIMAL) %ld\n", iPort, iPattern);
		m_list.AddString("NIDAQDelay(1.0)");
        iRetVal = NIDAQDelay(1.0);

        ++iPattern;
		m_list.AddString("NIDAQYield(iYieldON)");
        iRetVal = NIDAQYield(iYieldON);
    }
	}
	else
	{//input
	i32 Pattern= 0;
	iPattern =0;
    while ((iPattern < iNumLoops) && (iStatus == 0)) {
        iStatus = DIG_In_Prt(iDevice, iPort, &Pattern);
        iRetVal = NIDAQErrorHandler(iStatus, "DIG_In_Prt",
         iIgnoreWarning);
		str.Format(" The digital pattern on port %d is get to (DECIMAL) %ld", iPort, Pattern);
		m_list.AddString(str);
        //printf(" The digital pattern on port %d is set to (DECIMAL) %ld\n", iPort, iPattern);
		m_list.AddString("NIDAQDelay(1.0)");
        iRetVal = NIDAQDelay(1.0);

        ++iPattern;
		m_list.AddString("NIDAQYield(iYieldON)");
        iRetVal = NIDAQYield(iYieldON);
	}
	}
}

void CNextDlg::OnButton2() 
{
	m_list.ResetContent();	
}

BOOL CNextDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	SetDlgItemInt(IDC_COMBO_DEVICE, 1);
	SetDlgItemInt(IDC_COMBO_CHAN2, 0);
	SetDlgItemInt(IDC_COMBO_inputMode, 0);
	SetDlgItemInt(IDC_COMBO_inputRange, 42);
	SetDlgItemInt(IDC_COMBO_SampRate, 300);
	SetDlgItemInt(IDC_COMBO_ulCount, 30);	

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

⌨️ 快捷键说明

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