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

📄 interruptdlg.cpp

📁 WinCE下获取IO中断,使用EVC写的
💻 CPP
字号:
// InterruptDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Interrupt.h"
#include "InterruptDlg.h"
#include "pkfuncs.h"

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


UCHAR ucData[0x100]={0};
HANDLE hSerialEvent;
HANDLE hKillDispatchThread;
HANDLE hTransmitEvent;
HANDLE hReadEvent;
HANDLE hThread1;
DWORD  idThread1;
DWORD dwIntID=0x10+0x0B;


int g_nINT = 0;

/////////////////////////////////////////////////////////////////////////////
// CInterruptDlg dialog

CInterruptDlg::CInterruptDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CInterruptDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CInterruptDlg)
		// 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 CInterruptDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CInterruptDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CInterruptDlg, CDialog)
	//{{AFX_MSG_MAP(CInterruptDlg)
	ON_BN_CLICKED(IDC_START, OnStart)
	ON_BN_CLICKED(IDC_STOP, OnStop)
	ON_BN_CLICKED(IDC_CLEAR, OnClear)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CInterruptDlg message handlers

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

	// 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
	
	CenterWindow(GetDesktopWindow());	// center to the hpc screen

	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}


void CriticalProc(DWORD iCaller)
{
	//EnterCriticalSection(&csObject1);

	RETAILMSG(1, (_T("%d \\\r\n"), iCaller));
	Sleep(5); // simulate work
	RETAILMSG(1, (_T("%d /\r\n"), iCaller));

	//LeaveCriticalSection(&csObject1);
}

bool c;
DWORD Thread1Proc(LPVOID lpv)
{
    ULONG               WaitReturn;

	while (TRUE)
	{
        WaitReturn = WaitForSingleObject(hSerialEvent, INFINITE);
		//Do counter Here Please
		g_nINT++;

		CString str;
		str.Format(_T("%d"),g_nINT);


		CEdit *tCount = (CEdit*)lpv;
		
		tCount->SetWindowText(str);

        InterruptDone(dwIntID);

		Sleep(10);

		if(c)
		{
			ExitThread(0);
		}
		
	}

	return 0;
}






void CInterruptDlg::OnStart() 
{
	// TODO: Add your control notification handler code here
	c = false;
	CEdit *tCount = (CEdit*)GetDlgItem(IDC_G_NINT);

	hSerialEvent = CreateEvent(0,FALSE,FALSE,NULL);
    hKillDispatchThread = CreateEvent(0, FALSE, FALSE, NULL);
    hTransmitEvent = CreateEvent(0, FALSE, FALSE, NULL);
    hReadEvent = CreateEvent(0, FALSE, FALSE, NULL);
    if ( !InterruptInitialize(dwIntID,
                              hSerialEvent,
                              0,
                              0) ) {
        DEBUGMSG(1,
                 (TEXT("Error initializing interrupt\r\n")));
    }
	InterruptDone(dwIntID);

	hThread1 = CreateThread(
					NULL,
					0,
					(LPTHREAD_START_ROUTINE)Thread1Proc,
					(LPVOID*)tCount,
					0,
					&idThread1);
}

void CInterruptDlg::OnStop() 
{
	// TODO: Add your control notification handler code here
	c = true;
	CloseHandle(hSerialEvent);
	CloseHandle(hKillDispatchThread);
	CloseHandle(hTransmitEvent);
	CloseHandle(hReadEvent);
}

void CInterruptDlg::OnClear() 
{
	// TODO: Add your control notification handler code here
	g_nINT = 0;
	CEdit *tCount = (CEdit*)GetDlgItem(IDC_G_NINT);
		
	tCount->SetWindowText(_T("0"));
}

⌨️ 快捷键说明

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