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

📄 watchthread.cpp

📁 本程序的开发环境是VC++,实现的功能是串口通信.
💻 CPP
字号:
// WatchThread.cpp : implementation file
//

#include "stdafx.h"
#include "矩阵控制器.h"
#include "WatchThread.h"
#include "SerialCom.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CWatchThread

IMPLEMENT_DYNCREATE(CWatchThread, CWinThread)

CWatchThread::CWatchThread()
{
}

CWatchThread::~CWatchThread()
{
}

BOOL CWatchThread::InitInstance()
{
	// TODO:  perform and per-thread initialization here
	DWORD dwTransfer,dwEvtMask;
	OVERLAPPED os;

	os.hEvent=CreateEvent(NULL,
		                  TRUE,
						  FALSE,
						  NULL);

	if (os.hEvent==NULL) return FALSE;
	if (!SetCommMask(m_pCom->m_hCom,EV_RXCHAR)) return FALSE;

	while (m_pCom->m_bconnected)
	{
		if (!WaitCommEvent(m_pCom->m_hCom,&dwEvtMask,&os))
		{
			if (GetLastError()==ERROR_IO_PENDING)
				GetOverlappedResult(m_pCom->m_hCom,&os,&dwTransfer,TRUE);
		} 
		if ((dwEvtMask &EV_RXCHAR)==EV_RXCHAR)
		{
			WaitForSingleObject(m_pCom->m_hPostEvent,0xFFFFFFFF);
			ResetEvent(m_pCom->m_hPostEvent);
			PostMessage(m_pCom->m_pWnd->m_hWnd,WM_COMMNOTIFY,0,0);
		}
	}
	CloseHandle(os.hEvent);
	return FALSE;
}

int CWatchThread::ExitInstance()
{
	// TODO:  perform any per-thread cleanup here
	return CWinThread::ExitInstance();
}

BEGIN_MESSAGE_MAP(CWatchThread, CWinThread)
	//{{AFX_MSG_MAP(CWatchThread)
		// NOTE - the ClassWizard will add and remove mapping macros here.
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CWatchThread message handlers

⌨️ 快捷键说明

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