리크 테스트 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.

316 lines
6.9 KiB

// 7350IntDlg.cpp : implementation file
//
#include "stdafx.h"
#include "7350Int.h"
#include "7350IntDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
int gIntCount;
HANDLE ghIntEvent[2];
BOOLEAN gbExitThread;
U32 gCOSEventOutLen = 100; //100 system clock - 100 * 8 ns
U32 gCOSLData = 0;
I16 g_hCard = -1;
DWORD WINAPI IntThread( LPVOID lpParam )
{
while ( gbExitThread == FALSE )
{
if ( WaitForSingleObject(ghIntEvent[0], INFINITE) == WAIT_OBJECT_0 )
{
gIntCount++;
DIO_GetCOSLatchData32(g_hCard, 0, &gCOSLData);
// ResetEvent(ghIntEvent[0]);
}
}
return (DWORD) 0;
}
// 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()
// C7350IntDlg dialog
C7350IntDlg::C7350IntDlg(I16 hCard, CWnd* pParent /*=NULL*/)
: CDialog(C7350IntDlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
g_hCard = hCard;
m_hThread = NULL;
m_nTimer = -1;
m_dwOutVal = 0x00000000;
}
void C7350IntDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(C7350IntDlg, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
ON_WM_DESTROY()
ON_WM_TIMER()
ON_BN_CLICKED(IDC_BT_OUTPUT, &C7350IntDlg::OnOutput)
END_MESSAGE_MAP()
// C7350IntDlg message handlers
BOOL C7350IntDlg::OnInitDialog()
{
CString strTemp;
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
// TODO: Add extra initialization here
I16 err;
err = DIO_VoltLevelConfig(g_hCard, P7350_PortDIO, VoltLevel_3R3);
if( err!=NoError )
{
strTemp.Format( TEXT("DIO_VoltLevelConfig(P7350_PortDIO) Error = %d"), err);
AfxMessageBox( strTemp );
return TRUE;
}
err = DIO_VoltLevelConfig(g_hCard, P7350_PortAFI, VoltLevel_3R3);
if(err!=NoError)
{
strTemp.Format( TEXT("DIO_VoltLevelConfig(P7350_PortAFI) Error = %d"), err);
AfxMessageBox( strTemp );
return TRUE;
}
/*Configure 7350 DIO Port*/
err = DIO_PortConfig(g_hCard, P7350_DIO_A, OUTPUT_PORT);
if( err!=NoError )
{
strTemp.Format( TEXT("DIO_PortConfig(P7350_DIO_A) Error = %d"), err);
AfxMessageBox( strTemp );
return TRUE;
}
err = DIO_PortConfig(g_hCard, P7350_DIO_B, INPUT_PORT);
if( err!=NoError )
{
strTemp.Format( TEXT("DIO_PortConfig(P7350_DIO_B) Error = %d"), err);
AfxMessageBox( strTemp );
return TRUE;
}
DO_WritePort(g_hCard, P7350_DIO_A, 0);
Sleep(1);
/*
* Setup COS for Port B
*/
err = DIO_SetCOSInterrupt32(g_hCard, 0, 0xff00, &(ghIntEvent[0]), 0);
if( err!=NoError )
{
strTemp.Format( TEXT("DIO_SetCOSInterrupt32() Error = %d"), err);
AfxMessageBox( strTemp );
return TRUE;
}
/*
* Set COS event out to AFI port
*/
err = DIO_7350_AFIConfig(g_hCard, P7350_AFI_0, 1, P7350_AFI_COSTrigOut, gCOSEventOutLen);
if( err!=NoError )
{
strTemp.Format( TEXT("DIO_7350_AFIConfig() Error = %d"), err);
AfxMessageBox( strTemp );
return TRUE;
}
gbExitThread = FALSE;
m_hThread = CreateThread( NULL, // default security attributes
0, // use default stack size
IntThread, // thread function name
NULL, // argument to thread function
0, // use default creation flags
NULL); // returns the thread identifier
m_nTimer = SetTimer( 1, 50, NULL );
return TRUE; // return TRUE unless you set the focus to a control
}
void C7350IntDlg::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 C7350IntDlg::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 C7350IntDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
void C7350IntDlg::OnDestroy()
{
CDialog::OnDestroy();
// TODO: Add your message handler code here
DIO_SetCOSInterrupt32(g_hCard, 0, 0, NULL, 0);
DIO_7350_AFIConfig(g_hCard, P7350_AFI_0, 0, 0, 0);
if( m_nTimer != -1 )
{
KillTimer( m_nTimer );
m_nTimer = -1;
}
if( m_hThread != NULL )
{
gbExitThread = TRUE; // termnate the IntThread
SetEvent( ghIntEvent[0] );
if (WaitForSingleObject(m_hThread, 5000) == WAIT_OBJECT_0)
{
CloseHandle( m_hThread );
m_hThread = NULL;
}
}
}
void C7350IntDlg::OnTimer(UINT_PTR nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CString strTemp;
U32 DIRead;
strTemp.Format( TEXT("INT Count = %d"), gIntCount );
SetDlgItemText( IDC_STATIC_05, strTemp );
DI_ReadPort(g_hCard, P7350_DIO_B, &DIRead);
strTemp.Format( TEXT("INT Count = 0x%08X"), DIRead );
SetDlgItemText( IDC_STATIC_06, strTemp );
strTemp.Format( TEXT("Latched Data = 0x%08X"), gCOSLData );
SetDlgItemText( IDC_STATIC_07, strTemp );
CDialog::OnTimer(nIDEvent);
}
void C7350IntDlg::OnOutput()
{
// TODO: Add your control notification handler code here
m_dwOutVal ++;
m_dwOutVal = (m_dwOutVal % 256);
DO_WritePort(g_hCard, P7350_DIO_A, m_dwOutVal);
}