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

📄 pci_6120dlg.cpp

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

#include "stdafx.h"
#include "PCI_6120.h"
#include "PCI_6120Dlg.h"
#include "nidaqex.h"
#include "NextDlg.h"
#include "DllFuncTypeDefine.h"
#include "SPI.h"

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

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPCI_6120Dlg dialog

CPCI_6120Dlg::CPCI_6120Dlg(CWnd* pParent /*=NULL*/)
	: CDialog(CPCI_6120Dlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CPCI_6120Dlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CPCI_6120Dlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPCI_6120Dlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CPCI_6120Dlg, CDialog)
	//{{AFX_MSG_MAP(CPCI_6120Dlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON_READ_VOLTAGE, OnButtonReadVoltage)
	ON_BN_CLICKED(IDC_AI_Configure, OnAIConfigure)
	ON_CBN_SELCHANGE(IDC_COMBO_DEVICE, OnSelchangeComboDevice)
	ON_BN_CLICKED(IDC_InitDABrds, OnInitDABrds)
	ON_BN_CLICKED(IDC_GetNIDAQVersion, OnGetNIDAQVersion)
	ON_BN_CLICKED(IDC_GetDAQDeviceInfo, OnGetDAQDeviceInfo)
	ON_BN_CLICKED(IDC_SeDAQDeviceInfo, OnSeDAQDeviceInfo)
	ON_BN_CLICKED(IDC_Scan_setup, OnScansetup)
	ON_BN_CLICKED(IDC_AI_Read_VScan, OnAIReadVScan)
	ON_BN_CLICKED(IDC_AutoUpdate, OnAutoUpdate)
	ON_WM_TIMER()
	ON_BN_CLICKED(IDC_ReadPort, OnReadPort)
	ON_BN_CLICKED(IDC_Read, OnRead)
	ON_BN_CLICKED(IDC_NEXT, OnNext)
	ON_BN_CLICKED(IDC_DIG_Prt_Config, OnDIGPrtConfig)
	ON_BN_CLICKED(IDC_BUTTON_READ_VOLTAGE2, OnButtonReadVoltage2)
	ON_BN_CLICKED(IDC_AI_Read_Scan, OnAIReadScan)
	ON_BN_CLICKED(IDC_AI_VScale, OnAIVScale)
	ON_CBN_SELCHANGE(IDC_COMBO_inputRange, OnSelchangeCOMBOinputRange)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPCI_6120Dlg message handlers

BOOL CPCI_6120Dlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
//device
	SetDlgItemInt(IDC_COMBO_DEVICE, 1);
//ai_VRead chan
	SetDlgItemInt(IDC_COMBO_CHAN, 0);
//ai_configure chan
	SetDlgItemInt(IDC_COMBO_CHAN2, 0);
//gain
	SetDlgItemInt(IDC_COMBO_GAIN, 1);
//scan_setup gainArray
	SetDlgItemInt(IDC_COMBO_GAIN1, 1);
	SetDlgItemInt(IDC_COMBO_GAIN2, 1);
	SetDlgItemInt(IDC_COMBO_GAIN3, 1);
	SetDlgItemInt(IDC_COMBO_GAIN4, 1);
//ai_config
	SetDlgItemInt(IDC_COMBO_inputMode, 0);
	SetDlgItemInt(IDC_COMBO_polarity, 0);
	SetDlgItemInt(IDC_COMBO_driveAIS, 0);
	SetDlgItemInt(IDC_COMBO_inputRange, 10);
//dig_config
	SetDlgItemInt(IDC_COMBO_mode2, 0);
	SetDlgItemInt(IDC_COMBO_port, 0);
	SetDlgItemInt(IDC_COMBO_dir, 0);
//ic
	SetDlgItemInt(IDC_EDIT_SEGMENT, 1);
	IsPowerOn= false;

	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CPCI_6120Dlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CPCI_6120Dlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CPCI_6120Dlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CPCI_6120Dlg::OnButtonReadVoltage() 
{
	i16 status= 0;
//	i16	deviceNumber= 0;
	i16 chan= 0;
	i16 gain= 0;
	f64 voltage= 0;
	CString str;

	deviceNumber= GetDlgItemInt(IDC_COMBO_DEVICE);
	chan= GetDlgItemInt(IDC_COMBO_CHAN);
	gain= GetDlgItemInt(IDC_COMBO_GAIN);
	//-2 (for gain of 0.2)
	//-1 (for gain of 0.5) 1, 2, 5, 10, 20, 50	
	status = AI_VRead (deviceNumber, chan, gain, &voltage);
/*	if(status<0)
	{
		str.Format("Read voltage error: %d", status);
		AfxMessageBox(str);
		return;
	}*/
	i16 iIgnoreWarning = 0;
	i16 iRetVal = NIDAQErrorHandler(status, "AI_VRead", iIgnoreWarning);

	str.Format("%lf", voltage);
	SetDlgItemText(IDC_EDIT_VOLTAGE, str);
}
/*
void CPCI_6120Dlg::OnButtonReadVoltageGroup() 
{
	i16 status= 0;

//	i16	deviceNumber= 0;
	i16 numChans	= 4;
	i16 chanVector[4]= {0,1,2,3};
	i16 gainVector[4]= {0};
	f64 reading[4]	 = {0};
	CString str;

	deviceNumber= GetDlgItemInt(IDC_COMBO_DEVICE);
	
	gainVector[0]= GetDlgItemInt(IDC_COMBO_GAIN1);
	gainVector[1]= GetDlgItemInt(IDC_COMBO_GAIN2);
	gainVector[2]= GetDlgItemInt(IDC_COMBO_GAIN3);
	gainVector[3]= GetDlgItemInt(IDC_COMBO_GAIN4);
	//select chan
	status = SCAN_Setup (deviceNumber, numChans, chanVector, gainVector);
	if(status<0)
	{
		str.Format("SCAN_Setup error: %d", status);
		AfxMessageBox(str);
		return;
	}
	//read AI_scan select chan
	status = AI_VRead_Scan (deviceNumber, reading);
	if(status<0)
	{
		str.Format("Read voltage error: %d", status);
		AfxMessageBox(str);
		return;
	}

	//chan0
	str.Format("%lf", reading[0]);
	SetDlgItemText(IDC_EDIT_CHAN1, str);	
	//chan1
	str.Format("%lf", reading[1]);
	SetDlgItemText(IDC_EDIT_CHAN2, str);
	//chan2
	str.Format("%lf", reading[2]);
	SetDlgItemText(IDC_EDIT_CHAN3, str);	
	//chan3
	str.Format("%lf", reading[3]);
	SetDlgItemText(IDC_EDIT_CHAN4, str);

}
*/
void CPCI_6120Dlg::OnAIConfigure() 
{
	i16 status= 0;
//	i16	deviceNumber= 0;
	i16 chan= 0;
//	i16 gain= 0;
	f64 voltage= 0;
	CString str;


	deviceNumber= GetDlgItemInt(IDC_COMBO_DEVICE);

	chan= GetDlgItemInt(IDC_COMBO_CHAN2);
//	gain= GetDlgItemInt(IDC_COMBO_GAIN);
	
	i16 inputMode= 0;	//0 diff, 1 signed-ended(RSE), 2 NRSE
	i16 polarity= 0;	//0 bipolar, 1 unipolar
	i16	inputRange= 40;	
	i16	driveAIS= 0;	//0: Do not drive AISENSE to ground, 1: Drive AISENSE to ground
	inputMode= GetDlgItemInt(IDC_COMBO_inputMode);
	polarity= GetDlgItemInt(IDC_COMBO_polarity);
	driveAIS= GetDlgItemInt(IDC_COMBO_driveAIS);
	inputRange= GetDlgItemInt(IDC_COMBO_inputRange);
	//str.Format("Range: %d", inputRange);	MessageBox(str);
	status = AI_Configure(deviceNumber, chan, inputMode, inputRange, polarity, driveAIS);
	i16 iIgnoreWarning = 0;
	i16 iRetVal = NIDAQErrorHandler(status, "AI_Configure", iIgnoreWarning);
	str.Format("inputRange: %d", inputRange);
	MessageBox(str);
}


void CPCI_6120Dlg::OnSelchangeComboDevice() 
{	
}

void CPCI_6120Dlg::OnInitDABrds() 
{
	i16 status= 0;
    i16 deviceNumberCode= 0;	//PCI-6120= 340
	deviceNumber= GetDlgItemInt(IDC_COMBO_DEVICE);

	status = Init_DA_Brds (deviceNumber, &deviceNumberCode);	
	i16 iIgnoreWarning = 0;
	i16 iRetVal = NIDAQErrorHandler(status, "Init_DA_Brds", iIgnoreWarning);
	//if(status== 0;)
	{
		CString str; 
		str.Format("Return status: %d; deviceNumberCode: %d", status,deviceNumberCode);
		AfxMessageBox(str);
	}
}

void CPCI_6120Dlg::OnGetNIDAQVersion() 
{
	i16 status= 0;
	u32 version= 0;
	status = Get_NI_DAQ_Version(&version);
	i16 iIgnoreWarning = 0;
	i16 iRetVal = NIDAQErrorHandler(status, "Get_NI_DAQ_Version", iIgnoreWarning);

	CString str;
	str.Format("NI DAQ Version: %d", version);
	AfxMessageBox(str);
}

void CPCI_6120Dlg::OnGetDAQDeviceInfo() 
{
	i16 status= 0;
	deviceNumber= GetDlgItemInt(IDC_COMBO_DEVICE);

	u32 infoType= 0;
	u32 infoValue= 0;
	status = Get_DAQ_Device_Info (deviceNumber, infoType, &infoValue);
	i16 iIgnoreWarning = 0;
	i16 iRetVal = NIDAQErrorHandler(status, "Get_DAQ_Device_Info", iIgnoreWarning);

	CString str;
	str.Format("infoType: %d", infoType);
	AfxMessageBox(str);
	str.Format("infoValue: %d", infoValue);
	AfxMessageBox(str);
}

void CPCI_6120Dlg::OnSeDAQDeviceInfo() 
{
	i16 status= 0;
	deviceNumber= GetDlgItemInt(IDC_COMBO_DEVICE);

	u32 infoType= 0;
	u32 infoValue= 0;
	status = Set_DAQ_Device_Info (deviceNumber, infoType, infoValue);
	i16 iIgnoreWarning = 0;
	i16 iRetVal = NIDAQErrorHandler(status, "Set_DAQ_Device_Info", iIgnoreWarning);

}

void CPCI_6120Dlg::OnScansetup() 
{
	i16 status= 0;

//	i16	deviceNumber= 0;
	i16 numChans	= 4;
	i16 chanVector[4]= {0,1,2,3};
	i16 gainVector[4]= {0};
	f64 reading[4]	 = {0};
	CString str;

	deviceNumber= GetDlgItemInt(IDC_COMBO_DEVICE);
	
	gainVector[0]= GetDlgItemInt(IDC_COMBO_GAIN1);
	gainVector[1]= GetDlgItemInt(IDC_COMBO_GAIN2);
	gainVector[2]= GetDlgItemInt(IDC_COMBO_GAIN3);
	gainVector[3]= GetDlgItemInt(IDC_COMBO_GAIN4);
	//select chan
	status = SCAN_Setup (deviceNumber, numChans, chanVector, gainVector);
	i16 iIgnoreWarning = 0;
	i16 iRetVal = NIDAQErrorHandler(status, "SCAN_Setup", iIgnoreWarning);
	/*	if(status<0)
	{
		str.Format("SCAN_Setup error: %d", status);
		AfxMessageBox(str);
		return;
	}	
*/
}

⌨️ 快捷键说明

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