리크 테스트 gui
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

319 lines
7.9 KiB

// pci8554Dlg.cpp : implementation file
//
#include "stdafx.h"
#include <time.h>
#include "pci8554.h"
#include "pci8554Dlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
enum { IDD = IDD_ABOUTBOX };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
// Implementation
protected:
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()
// Cpci8554Dlg dialog
Cpci8554Dlg::Cpci8554Dlg(I16 hCard, CWnd* pParent /*=NULL*/)
: CDialog(Cpci8554Dlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_hCard = hCard;
m_OperationMode = 0;
}
void Cpci8554Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_COMBO_MODE, m_cbMode);
}
BEGIN_MESSAGE_MAP(Cpci8554Dlg, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
ON_WM_DESTROY()
ON_CBN_SELCHANGE(IDC_COMBO_MODE, &Cpci8554Dlg::OnModeSelchange)
ON_BN_CLICKED(IDC_BT_START, &Cpci8554Dlg::OnBnClickedBtStart)
END_MESSAGE_MAP()
// Cpci8554Dlg message handlers
BOOL Cpci8554Dlg::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)
{
BOOL bNameValid;
CString strAboutMenu;
bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
ASSERT(bNameValid);
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
m_cbMode.SetCurSel( m_OperationMode );
return TRUE; // return TRUE unless you set the focus to a control
}
void Cpci8554Dlg::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 Cpci8554Dlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<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 function to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR Cpci8554Dlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
void Cpci8554Dlg::OnDestroy()
{
CDialog::OnDestroy();
// TODO: Add your message handler code here
}
void Cpci8554Dlg::OnModeSelchange()
{
// TODO: Add your control notification handler code here
int nIndex;
CString strTmp;
nIndex = m_cbMode.GetCurSel();
switch( nIndex )
{
case 0:
SetDlgItemText( IDC_STATIC_INTRO, TEXT("Generate 250 KHz square wave, The clock source of the counter #1 is set to C8M.") );
m_OperationMode = 0;
break;
case 1:
SetDlgItemText( IDC_STATIC_INTRO, TEXT("Generate one pulse every hour.\n\t<1> the clock source of the counter #1 is set to C8M\n\t<2> the clock source of counter #2, #3 is from #1, #2.") );
m_OperationMode = 1;
break;
case 2:
SetDlgItemText( IDC_STATIC_INTRO, TEXT("Measure pulse width.\n\t<1> the clock source of the counter #1 is set to C8M\n\t<2> the signal to be measured is connected to GATE1.") );
m_OperationMode = 2;
break;
case 3:
SetDlgItemText( IDC_STATIC_INTRO, TEXT("Measure signal frequency\n\t<1> Connect the signal to be measured to ECLK1\n\t<2> the clock source of the counter #2,#3 set to C8M, COUT2\n\t<3> the gate source of the counter #1 set to the inverse of COUT3\n\t<4> the gate source of the counter #2, #3 set to High.") );
m_OperationMode = 3;
break;
}
}
void Cpci8554Dlg::OnBnClickedBtStart()
{
// TODO: Add your control notification handler code here
U16 under_flow;
U32 old_value, new_value, value;
double pulse_width, period, frequency;
CString strTmp;
GetDlgItem(IDC_BT_START)->EnableWindow(FALSE);
switch (m_OperationMode)
{
case 0: //Square Wave
CTR_8554_CK1_Config(m_hCard, CK1_C8M);
CTR_8554_ClkSrc_Config(m_hCard, 1, CK1);
CTR_8554_ClkSrc_Config(m_hCard, 2, CK1);
CTR_8554_ClkSrc_Config(m_hCard, 3, CK1);
CTR_8554_ClkSrc_Config(m_hCard, 4, CK1);
CTR_8554_ClkSrc_Config(m_hCard, 5, CK1);
CTR_8554_ClkSrc_Config(m_hCard, 6, CK1);
CTR_8554_ClkSrc_Config(m_hCard, 7, CK1);
CTR_8554_ClkSrc_Config(m_hCard, 8, CK1);
CTR_8554_ClkSrc_Config(m_hCard, 9, CK1);
CTR_8554_ClkSrc_Config(m_hCard, 10, CK1);
CTR_Setup(m_hCard, 1, 3, 32, BIN);
CTR_Setup(m_hCard, 2, 3, 32, BIN);
CTR_Setup(m_hCard, 3, 3, 32, BIN);
CTR_Setup(m_hCard, 4, 3, 32, BIN);
CTR_Setup(m_hCard, 5, 3, 32, BIN);
CTR_Setup(m_hCard, 6, 3, 32, BIN);
CTR_Setup(m_hCard, 7, 3, 32, BIN);
CTR_Setup(m_hCard, 8, 3, 32, BIN);
CTR_Setup(m_hCard, 9, 3, 32, BIN);
CTR_Setup(m_hCard, 10, 3, 32, BIN);
SetDlgItemText( IDC_STATIC_STATUS, TEXT("*** 250 KHz square wave is ready on the COUT1 ~ 11 ***") );
break;
case 1: //Pluse Generator
CTR_8554_CK1_Config(m_hCard, CK1_C8M);
CTR_8554_ClkSrc_Config(m_hCard, 1, CK1);
CTR_8554_ClkSrc_Config(m_hCard, 2, COUTN_1);
CTR_8554_ClkSrc_Config(m_hCard, 3, COUTN_1);
CTR_Setup(m_hCard, 1, 3, 200, 0);
CTR_Setup(m_hCard, 2, 3, 200, 0);
CTR_Setup(m_hCard, 3, 3, 200, 0);
SetDlgItemText( IDC_STATIC_STATUS, TEXT("*** A pulse per second is ready on the COUT3 ***") );
break;
case 2: //Measure Pulse Width
CTR_8554_CK1_Config(m_hCard, CK1_C8M);
CTR_8554_ClkSrc_Config(m_hCard, 1, CK1);
CTR_Setup(m_hCard, 1, 2, 0, BIN);
under_flow = 0;
wait_pulse_start();
time( &m_time1 );
CTR_Read(m_hCard, 1, &old_value);
while (1)
{
CTR_Read(m_hCard, 1, &new_value);
time( &m_time2 );
period = difftime( m_time2, m_time1 );
if ( (new_value == old_value) || (period > 5.0) )
break;
if ( old_value < new_value ) under_flow++;
old_value = new_value;
}
if (period < 5.0)
{
pulse_width = (65536 - new_value + under_flow * 65536 + 1) * 0.125;
strTmp.Format( TEXT("*** High level pulse width = %f micro-second ***"), pulse_width);
SetDlgItemText( IDC_STATIC_STATUS, strTmp );
}
else
SetDlgItemText( IDC_STATIC_STATUS, TEXT("*** Measure inappropriate pulse width ***") );
break;
case 3: //Measure Frequency
CTR_8554_ClkSrc_Config(m_hCard, 1, ECKN);
CTR_8554_CK1_Config(m_hCard, CK1_C8M);
CTR_8554_ClkSrc_Config(m_hCard, 2, CK1);
CTR_8554_ClkSrc_Config(m_hCard, 3, COUTN_1);
CTR_Setup(m_hCard, 1, 2, 65535, 0);
CTR_Setup(m_hCard, 2, 2, 4, 0);
CTR_Setup(m_hCard, 3, 0, 65535, 0);
Sleep(1000);
CTR_Read(m_hCard, 1, &value);
period = 65535 - (value&0xffff);
frequency = period * 2000000 / 65535;
strTmp.Format( TEXT("Measured Signal Frequency = %f Hz."), frequency);
SetDlgItemText( IDC_STATIC_STATUS, strTmp );
break;
}
GetDlgItem(IDC_BT_START)->EnableWindow(TRUE);
}
void Cpci8554Dlg::wait_pulse_start(void)
{
U32 oldvalue,newvalue;
do
{
CTR_Read( m_hCard, 1, &oldvalue );
CTR_Read( m_hCard, 1, &newvalue );
} while( newvalue != oldvalue );
do
{
CTR_Read( m_hCard, 1, &oldvalue );
CTR_Read( m_hCard, 1, &newvalue );
} while( newvalue == oldvalue );
}