亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? comport.cpp

?? 一個讀寫GPS并顯示地理位置和分析的代碼
?? CPP
?? 第 1 頁 / 共 2 頁
字號:
#include "stdafx.h"
#include <crtdbg.h>
#include <tchar.h>

//////////////////////////////////////////////////////////////////////
// Include module headerfile

#include "ComPort.h"


//////////////////////////////////////////////////////////////////////
// Disable warning C4127: conditional expression is constant, which
// is generated when using the _RPTF and _ASSERTE macros.

#pragma warning(disable: 4127)


//////////////////////////////////////////////////////////////////////
// Code

CComPort::CComPort ()
{
	// Reset data
	m_lLastError     = ERROR_SUCCESS;
	m_hFile          = 0;
	m_eEvent         = EEventNone;
	m_hevtOverlapped = 0;
}

CComPort::~CComPort ()
{
	// If the device is already closed,
	// then we don't need to do anything.
	if (m_hFile)
	{
		// Display a warning
		_RPTF0(_CRT_WARN,"CComPort::~CComPort - Serial port not closed\n");

		// Close implicitly
		Close();
	}
}

LONG CComPort::Open (LPCTSTR lpszDevice, DWORD dwInQueue, DWORD dwOutQueue)
{
	// Reset error state
	m_lLastError = ERROR_SUCCESS;

	// Check if the port isn't already opened
	if (m_hFile)
	{
		m_lLastError = ERROR_ALREADY_INITIALIZED;
		_RPTF0(_CRT_WARN,"CComPort::Open - Port already opened\n");
		return m_lLastError;
	}
	// Open the device
	m_hFile = ::CreateFile(lpszDevice,
						   GENERIC_READ|GENERIC_WRITE,
						   0,
						   0,
						   OPEN_EXISTING,
						   FILE_FLAG_OVERLAPPED,
						   0);
	if (m_hFile == INVALID_HANDLE_VALUE)
	{
		// Reset file handle
		m_hFile = 0;

		// Display error
		m_lLastError = ::GetLastError();
		_RPTF0(_CRT_WARN, "CComPort::Open - Unable to open port\n");
		return m_lLastError;
	}

	// We cannot have an event handle yet
	_ASSERTE(m_hevtOverlapped == 0);

	// Create the event handle for internal overlapped operations (manual reset)
	m_hevtOverlapped = ::CreateEvent(0,true,false,0);
	if (m_hevtOverlapped == 0)
	{
		// Obtain the error information
		m_lLastError = ::GetLastError();
		_RPTF0(_CRT_WARN,"CComPort::Open - Unable to create event\n");

		// Close the port
		::CloseHandle(m_hFile);
		m_hFile = 0;

		// Return the error
		return m_lLastError;
	}

	// Setup the COM-port
	if (!::SetupComm(m_hFile,dwInQueue,dwOutQueue))
	{
		// Display a warning
		long lLastError = ::GetLastError();
		_RPTF0(_CRT_WARN,"CComPort::Open - Unable to setup the COM-port\n");

		// Close the port
		Close();

		// Save last error from SetupComm
		m_lLastError = lLastError;
		return m_lLastError;
	}

	// Setup the default communication mask
	SetMask();

	// Setup the device for default settings
	Setup();

	// Non-blocking reads is default
	SetupReadTimeouts(EReadTimeoutNonblocking);

	// Default is no handshaking
	SetupHandshaking(EHandshakeOff);

	// Return successful
	return m_lLastError;
}

LONG CComPort::Close (void)
{
	// Reset error state
	m_lLastError = ERROR_SUCCESS;

	// If the device is already closed,
	// then we don't need to do anything.
	if (m_hFile == 0)
	{
		// Display a warning
		_RPTF0(_CRT_WARN,"CComPort::Close - Method called when device is not open\n");
		return m_lLastError;
	}

	// Free event handle
	::CloseHandle(m_hevtOverlapped);
	m_hevtOverlapped = 0;

	// Close COM port
	::CloseHandle(m_hFile);
	m_hFile = 0;

	// Return successful
	return m_lLastError;
}

LONG CComPort::Setup (EBaudrate eBaudrate, EDataBits eDataBits, EParity eParity, EStopBits eStopBits)
{
	// Reset error state
	m_lLastError = ERROR_SUCCESS;

	// Check if the device is open
	if (m_hFile == 0)
	{
		// Set the internal error code
		m_lLastError = ERROR_INVALID_HANDLE;

		// Issue an error and quit
		_RPTF0(_CRT_WARN,"CComPort::Setup - Device is not opened\n");
		return m_lLastError;
	}

	// Obtain the DCB structure for the device
	CDCB dcb;
	if (!::GetCommState(m_hFile,&dcb))
	{
		// Obtain the error code
		m_lLastError = ::GetLastError();

		// Display a warning
		_RPTF0(_CRT_WARN,"CComPort::Setup - Unable to obtain DCB information\n");
		return m_lLastError;
	}

	// Set the new data
	dcb.BaudRate = DWORD(eBaudrate);
	dcb.ByteSize = BYTE(eDataBits);
	dcb.Parity   = BYTE(eParity);
	dcb.StopBits = BYTE(eStopBits);

	// Determine if parity is used
	dcb.fParity  = (eParity != EParNone);

	// Set the new DCB structure
	if (!::SetCommState(m_hFile,&dcb))
	{
		// Obtain the error code
		m_lLastError = ::GetLastError();

		// Display a warning
		_RPTF0(_CRT_WARN,"CComPort::Setup - Unable to set DCB information\n");
		return m_lLastError;
	}

	// Return successful
	return m_lLastError;
}

LONG CComPort::SetEventChar (BYTE bEventChar, bool fAdjustMask)
{
	// Reset error state
	m_lLastError = ERROR_SUCCESS;

	// Check if the device is open
	if (m_hFile == 0)
	{
		// Set the internal error code
		m_lLastError = ERROR_INVALID_HANDLE;

		// Issue an error and quit
		_RPTF0(_CRT_WARN,"CComPort::SetEventChar - Device is not opened\n");
		return m_lLastError;
	}

	// Obtain the DCB structure for the device
	CDCB dcb;
	if (!::GetCommState(m_hFile,&dcb))
	{
		// Obtain the error code
		m_lLastError = ::GetLastError();

		// Display a warning
		_RPTF0(_CRT_WARN,"CComPort::SetEventChar - Unable to obtain DCB information\n");
		return m_lLastError;
	}

	// Set the new event character
	dcb.EvtChar = char(bEventChar);

	// Adjust the event mask, to make sure the event will be received
	if (fAdjustMask)
	{
		// Enable 'receive event character' event.  Note that this
		// will generate an EEventNone if there is an asynchronous
		// WaitCommEvent pending.
		SetMask(GetEventMask() | EEventRcvEv);
	}

	// Set the new DCB structure
	if (!::SetCommState(m_hFile,&dcb))
	{
		// Obtain the error code
		m_lLastError = ::GetLastError();

		// Display a warning
		_RPTF0(_CRT_WARN,"CComPort::SetEventChar - Unable to set DCB information\n");
		return m_lLastError;
	}

	// Return successful
	return m_lLastError;
}

LONG CComPort::SetMask (DWORD dwMask)
{
	// Reset error state
	m_lLastError = ERROR_SUCCESS;

	// Check if the device is open
	if (m_hFile == 0)
	{
		// Set the internal error code
		m_lLastError = ERROR_INVALID_HANDLE;

		// Issue an error and quit
		_RPTF0(_CRT_WARN,"CComPort::SetMask - Device is not opened\n");
		return m_lLastError;
	}

	// Set the new mask. Note that this will generate an EEventNone
	// if there is an asynchronous WaitCommEvent pending.
	if (!::SetCommMask(m_hFile,dwMask))
	{
		// Obtain the error code
		m_lLastError = ::GetLastError();

		// Display a warning
		_RPTF0(_CRT_WARN,"CComPort::SetMask - Unable to set event mask\n");
		return m_lLastError;
	}

	// Return successful
	return m_lLastError;
}

LONG CComPort::WaitEvent (LPOVERLAPPED lpOverlapped, DWORD dwTimeout)
{
	// Reset error state
	m_lLastError = ERROR_SUCCESS;

	// Check if the device is open
	if (m_hFile == 0)
	{
		// Set the internal error code
		m_lLastError = ERROR_INVALID_HANDLE;

		// Issue an error and quit
		_RPTF0(_CRT_WARN,"CComPort::WaitEvent - Device is not opened\n");
		return m_lLastError;
	}

	// Wait for the event to happen
	OVERLAPPED ovInternal;
	if (lpOverlapped == 0)
	{
		// Setup our own overlapped structure
		memset(&ovInternal,0,sizeof(ovInternal));
		ovInternal.hEvent = m_hevtOverlapped;

		// Use our internal overlapped structure
		lpOverlapped = &ovInternal;
	}

	// Make sure the overlapped structure isn't busy
	_ASSERTE(HasOverlappedIoCompleted(lpOverlapped));

	// Wait for the COM event
	if (!::WaitCommEvent(m_hFile,LPDWORD(&m_eEvent),lpOverlapped))
	{
		// Set the internal error code
		long lLastError = ::GetLastError();

		// Overlapped operation in progress is not an actual error
		if (lLastError != ERROR_IO_PENDING)
		{
			// Save the error
			m_lLastError = lLastError;

			// Issue an error and quit
			_RPTF0(_CRT_WARN,"CComPort::WaitEvent - Unable to wait for COM event\n");
			return m_lLastError;
		}

		// We need to block if the client didn't specify an overlapped structure
		if (lpOverlapped == &ovInternal)
		{
			// Wait for the overlapped operation to complete
			switch (::WaitForSingleObject(lpOverlapped->hEvent,dwTimeout))
			{
			case WAIT_OBJECT_0:
				// The overlapped operation has completed
				break;

			case WAIT_TIMEOUT:
				// Cancel the I/O operation
				::CancelIo(m_hFile);

				// The operation timed out. Set the internal error code and quit
				m_lLastError = ERROR_TIMEOUT;
				return m_lLastError;

			default:
				// Set the internal error code
				m_lLastError = ::GetLastError();

				// Issue an error and quit
				_RPTF0(_CRT_WARN,"CComPort::WaitEvent - Unable to wait until COM event has arrived\n");
				return m_lLastError;
			}
		}
	}
	else
	{
		// The operation completed immediatly. Just to be sure
		// we'll set the overlapped structure's event handle.
		::SetEvent(lpOverlapped->hEvent);
	}

	// Return successfully
	return m_lLastError;
}


LONG CComPort::SetupHandshaking (EHandshake eHandshake)
{
	// Reset error state
	m_lLastError = ERROR_SUCCESS;

	// Check if the device is open
	if (m_hFile == 0)
	{
		// Set the internal error code
		m_lLastError = ERROR_INVALID_HANDLE;

		// Issue an error and quit
		_RPTF0(_CRT_WARN,"CComPort::SetupHandshaking - Device is not opened\n");
		return m_lLastError;
	}

	// Obtain the DCB structure for the device
	CDCB dcb;
	if (!::GetCommState(m_hFile,&dcb))
	{
		// Obtain the error code
		m_lLastError = ::GetLastError();

		// Display a warning
		_RPTF0(_CRT_WARN,"CComPort::SetupHandshaking - Unable to obtain DCB information\n");
		return m_lLastError;
	}

	// Set the handshaking flags
	switch (eHandshake)
	{
	case EHandshakeOff:
		dcb.fOutxCtsFlow = false;					// Disable CTS monitoring
		dcb.fOutxDsrFlow = false;					// Disable DSR monitoring
		dcb.fDtrControl = DTR_CONTROL_DISABLE;		// Disable DTR monitoring
		dcb.fOutX = false;							// Disable XON/XOFF for transmission
		dcb.fInX = false;							// Disable XON/XOFF for receiving
		dcb.fRtsControl = RTS_CONTROL_DISABLE;		// Disable RTS (Ready To Send)
		break;

	case EHandshakeHardware:
		dcb.fOutxCtsFlow = true;					// Enable CTS monitoring
		dcb.fOutxDsrFlow = true;					// Enable DSR monitoring
		dcb.fDtrControl = DTR_CONTROL_HANDSHAKE;	// Enable DTR handshaking
		dcb.fOutX = false;							// Disable XON/XOFF for transmission
		dcb.fInX = false;							// Disable XON/XOFF for receiving
		dcb.fRtsControl = RTS_CONTROL_HANDSHAKE;	// Enable RTS handshaking
		break;

	case EHandshakeSoftware:
		dcb.fOutxCtsFlow = false;					// Disable CTS (Clear To Send)
		dcb.fOutxDsrFlow = false;					// Disable DSR (Data Set Ready)
		dcb.fDtrControl = DTR_CONTROL_DISABLE;		// Disable DTR (Data Terminal Ready)
		dcb.fOutX = true;							// Enable XON/XOFF for transmission
		dcb.fInX = true;							// Enable XON/XOFF for receiving
		dcb.fRtsControl = RTS_CONTROL_DISABLE;		// Disable RTS (Ready To Send)
		break;

	default:
		// This shouldn't be possible
		_ASSERTE(false);
		m_lLastError = E_INVALIDARG;
		return m_lLastError;
	}

	// Set the new DCB structure
	if (!::SetCommState(m_hFile,&dcb))
	{
		// Obtain the error code
		m_lLastError = ::GetLastError();

		// Display a warning
		_RPTF0(_CRT_WARN,"CComPort::SetupHandshaking - Unable to set DCB information\n");
		return m_lLastError;
	}

	// Return successful
	return m_lLastError;
}

LONG CComPort::SetupReadTimeouts (EReadTimeout eReadTimeout)
{
	// Reset error state
	m_lLastError = ERROR_SUCCESS;

	// Check if the device is open
	if (m_hFile == 0)
	{
		// Set the internal error code
		m_lLastError = ERROR_INVALID_HANDLE;

		// Issue an error and quit
		_RPTF0(_CRT_WARN,"CComPort::SetupReadTimeouts - Device is not opened\n");
		return m_lLastError;
	}

	// Determine the time-outs
	COMMTIMEOUTS cto;
	if (!::GetCommTimeouts(m_hFile,&cto))
	{
		// Obtain the error code
		m_lLastError = ::GetLastError();

		// Display a warning
		_RPTF0(_CRT_WARN,"CComPort::SetupReadTimeouts - Unable to obtain timeout information\n");
		return m_lLastError;
	}

	// Set the new timeouts
	switch (eReadTimeout)
	{
	case EReadTimeoutBlocking:
		cto.ReadIntervalTimeout = 0;
		cto.ReadTotalTimeoutConstant = 0;
		cto.ReadTotalTimeoutMultiplier = 0;
		break;
	case EReadTimeoutNonblocking:
		cto.ReadIntervalTimeout = MAXDWORD;
		cto.ReadTotalTimeoutConstant = 0;
		cto.ReadTotalTimeoutMultiplier = 0;
		break;
	default:
		// This shouldn't be possible
		_ASSERTE(false);
		m_lLastError = E_INVALIDARG;
		return m_lLastError;
	}

	// Set the new DCB structure
	if (!::SetCommTimeouts(m_hFile,&cto))
	{
		// Obtain the error code
		m_lLastError = ::GetLastError();

		// Display a warning

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美午夜视频网站| 亚洲精品写真福利| 最新日韩在线视频| 丝袜美腿亚洲色图| 91网站最新地址| 26uuu亚洲综合色| 亚洲h在线观看| 91视频国产资源| 国产三级三级三级精品8ⅰ区| 亚洲成人免费观看| av动漫一区二区| 国产日韩欧美一区二区三区乱码 | 一本一本久久a久久精品综合麻豆| 91精品国产福利| 亚洲自拍偷拍麻豆| 91婷婷韩国欧美一区二区| 欧美一区二区三区的| 亚洲va国产天堂va久久en| 91麻豆6部合集magnet| 欧美高清在线一区| 国产成人免费xxxxxxxx| 精品盗摄一区二区三区| 青青草精品视频| 欧美二区三区的天堂| 亚洲图片一区二区| 在线视频一区二区免费| 亚洲综合色视频| 欧美在线免费观看亚洲| 一区二区三区在线播放| 色激情天天射综合网| 亚洲欧美成人一区二区三区| 成人午夜激情在线| 中文字幕一区二区三区在线观看| 国产精品影视在线| 中文字幕免费观看一区| 风流少妇一区二区| 国产精品青草久久| 色婷婷久久久亚洲一区二区三区| 综合av第一页| 在线免费观看日本一区| 亚洲国产精品一区二区www在线| 色综合咪咪久久| 亚洲成人av一区| 91精品国产全国免费观看| 麻豆成人久久精品二区三区红 | 91福利精品视频| 夜夜揉揉日日人人青青一国产精品 | 国产盗摄女厕一区二区三区| 久久久电影一区二区三区| 国产精品911| 亚洲三级小视频| 在线视频国产一区| 蜜桃av一区二区三区| 久久久精品中文字幕麻豆发布| 国产精品18久久久久久久久| 一区在线播放视频| 4438亚洲最大| 国产精品一区二区三区99| 亚洲色图制服诱惑| 91精品国产综合久久久久久| 韩国欧美国产1区| 亚洲三级久久久| 欧美老年两性高潮| 国产一区二区三区久久悠悠色av| 亚洲欧洲精品一区二区三区不卡| 欧美日韩一区二区三区高清 | 黄色精品一二区| 亚洲欧美国产高清| 日韩欧美激情在线| 91啪九色porn原创视频在线观看| 日本不卡一二三区黄网| 日本一二三四高清不卡| 欧美久久久一区| 东方aⅴ免费观看久久av| 香蕉久久一区二区不卡无毒影院 | 欧美精品一级二级三级| 国产大陆a不卡| 亚洲大尺度视频在线观看| 国产午夜精品久久| 欧美裸体一区二区三区| 9人人澡人人爽人人精品| 日本视频一区二区三区| 椎名由奈av一区二区三区| 日韩女优毛片在线| 色88888久久久久久影院按摩| 久久99这里只有精品| 一级女性全黄久久生活片免费| 久久久亚洲综合| 欧美一区三区二区| 在线观看不卡视频| 大陆成人av片| 国内外成人在线| 奇米精品一区二区三区在线观看| 亚洲视频在线观看一区| 久久久亚洲国产美女国产盗摄| 678五月天丁香亚洲综合网| 91在线观看视频| 成人一二三区视频| 国产精品亚洲午夜一区二区三区| 婷婷久久综合九色综合绿巨人| 亚洲精选免费视频| 亚洲国产电影在线观看| 久久影院视频免费| 欧美xxxxx裸体时装秀| 91精品国产黑色紧身裤美女| 欧美在线影院一区二区| av电影天堂一区二区在线| 国产成人精品免费| 国产99久久精品| 国产精品一卡二卡在线观看| 久99久精品视频免费观看| 美女爽到高潮91| 精品无人码麻豆乱码1区2区| 美女视频网站久久| 奇米四色…亚洲| 久久99精品久久久久久动态图| 青青草国产成人av片免费| 日韩和欧美一区二区三区| 五月婷婷激情综合| 日韩专区欧美专区| 蜜臀av一级做a爰片久久| 麻豆成人久久精品二区三区小说| 青椒成人免费视频| 寂寞少妇一区二区三区| 国产老肥熟一区二区三区| 国产成人精品一区二区三区网站观看| 国产乱码精品一区二区三区忘忧草 | 日韩一区二区三区电影在线观看 | 国产三级精品三级| 国产亚洲1区2区3区| 国产精品拍天天在线| 亚洲欧美国产77777| 午夜欧美视频在线观看| 男女男精品视频网| 国产精品一区二区久激情瑜伽 | 国产精品美女久久久久高潮| 中文字幕亚洲精品在线观看| 亚洲精品高清视频在线观看| 婷婷久久综合九色综合伊人色| 久久99国产精品尤物| 岛国精品在线观看| 欧美日韩高清影院| 久久午夜免费电影| 亚洲美女电影在线| 美女精品一区二区| 成人美女在线视频| 欧美日韩在线综合| 久久伊99综合婷婷久久伊| 亚洲人成网站精品片在线观看| 视频一区欧美精品| 国产成人在线影院 | 欧美一区二区三区视频在线 | 国产精品国产三级国产aⅴ入口| 一区二区激情视频| 国模娜娜一区二区三区| 91免费精品国自产拍在线不卡| 337p亚洲精品色噜噜| 国产精品久久久久一区二区三区 | 精品一区二区日韩| 99久久综合狠狠综合久久| 欧美日韩成人一区二区| 久久精品视频免费| 亚洲444eee在线观看| 成人听书哪个软件好| 91精品国产综合久久久蜜臀图片| 国产精品卡一卡二| 美女诱惑一区二区| 欧美视频一区二区三区四区| 国产精品私人影院| 美腿丝袜亚洲色图| 欧美亚洲愉拍一区二区| 国产色91在线| 久久电影国产免费久久电影| 欧美三级电影网| 1区2区3区精品视频| 国产精品一二三四| 欧美大白屁股肥臀xxxxxx| 亚洲午夜一区二区| 波多野结衣亚洲一区| 欧美精品一区男女天堂| 日本欧美一区二区在线观看| 91福利资源站| 亚洲三级在线免费观看| 高清不卡一区二区在线| 日韩欧美你懂的| 美腿丝袜亚洲色图| 欧美一区二区美女| 日韩精品亚洲专区| 欧美人狂配大交3d怪物一区| 一区二区中文字幕在线| 成人激情校园春色| 中文文精品字幕一区二区| 麻豆国产精品一区二区三区| 欧美日韩久久一区| 亚洲成人午夜电影| 精品视频在线免费| 午夜av区久久| 欧美一级理论性理论a| 秋霞国产午夜精品免费视频| 777午夜精品视频在线播放|