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

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

?? serialport.cpp

?? 接受GPGGA語句的VC程序
?? CPP
?? 第 1 頁 / 共 2 頁
字號:
//CSerialPortEx類是在Remon Spekreijse設計的CSerialPort類基礎上設計的,并增加
//了對二進制數據傳輸和塊讀寫方式的支持和其他功能函數。關于CSerialPort類的聲明如下:
/*
**	FILENAME			SerialPort.cpp
**
**	PURPOSE				This class can read, write and watch one serial port.
**						It sends messages to its owner when something happends on the port
**						The class creates a thread for reading and writing so the main
**						program is not blocked.
**
**	CREATION DATE		15-09-1997
**	LAST MODIFICATION	12-11-1997
**
**	AUTHOR				Remon Spekreijse
**
**
*/

#include "stdafx.h"
#include "SerialPort.h"

#include <assert.h>
 
//
// Constructor
//
CSerialPortEx::CSerialPortEx()
{
	m_hComm = NULL;

	// initialize overlapped structure members to zero
	m_ov.Offset = 0;
	m_ov.OffsetHigh = 0;

	m_ov.hEvent = NULL;
	// create events
	m_hWriteEvent = NULL;
	m_hShutdownEvent = NULL;

	m_szWriteBuffer = NULL;

	m_bThreadAlive = FALSE;
	m_bBlockRead=FALSE;
}

//
// Delete dynamic memory
//
CSerialPortEx::~CSerialPortEx()
{
	do
	{
		SetEvent(m_hShutdownEvent);
	} while (m_bThreadAlive);

	TRACE("Thread ended\n");

	delete [] m_szWriteBuffer;
}

//
// Initialize the port. This can be port 1 to 4.
//
BOOL CSerialPortEx::InitPort(CWnd* pPortOwner,	// the owner (CWnd) of the port (receives message)
						   UINT  portnr,		// portnumber (1..4)
						   UINT  baud,			// baudrate
						   char  parity,		// parity 
						   UINT  databits,		// databits 
						   UINT  stopbits,		// stopbits 
						   DWORD dwCommEvents,	// EV_RXCHAR, EV_CTS etc
						   UINT  writebuffersize)	// size to the writebuffer
{
	assert(portnr > 0 && portnr < 5);
	assert(pPortOwner != NULL);

	// if the thread is alive: Kill
	if (m_bThreadAlive)
	{
		do
		{
			SetEvent(m_hShutdownEvent);
		} while (m_bThreadAlive);
		TRACE("Thread ended\n");
	}

	// create events
	if (m_ov.hEvent != NULL)
		ResetEvent(m_ov.hEvent);
	m_ov.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);

	if (m_hWriteEvent != NULL)
		ResetEvent(m_hWriteEvent);
	m_hWriteEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
	
	if (m_hShutdownEvent != NULL)
		ResetEvent(m_hShutdownEvent);
	m_hShutdownEvent = CreateEvent(NULL, TRUE, FALSE, NULL);

	// initialize the event objects
	m_hEventArray[0] = m_hShutdownEvent;	// highest priority
	m_hEventArray[1] = m_ov.hEvent;
	m_hEventArray[2] = m_hWriteEvent;

	// initialize critical section
	InitializeCriticalSection(&m_csCommunicationSync);
	
	// set buffersize for writing and save the owner
	m_pOwner = pPortOwner;

	if (m_szWriteBuffer != NULL)
		delete [] m_szWriteBuffer;
	m_szWriteBuffer =new BYTE[writebuffersize];

	m_nPortNr = portnr;

	m_nWriteBufferSize = writebuffersize;
	m_dwCommEvents = dwCommEvents;

	BOOL bResult = FALSE;
	char *szPort = new char[50];
	char *szBaud = new char[50];

	// now it critical!
	EnterCriticalSection(&m_csCommunicationSync);

	// if the port is already opened: close it
	if (m_hComm != NULL)
	{
		CloseHandle(m_hComm);
		m_hComm = NULL;
	}

	// prepare port strings
	sprintf(szPort, "COM%d", portnr);
	sprintf(szBaud, "baud=%d parity=%c data=%d stop=%d", baud, parity, databits, stopbits);

	// get a handle to the port
	m_hComm = CreateFile(szPort,						// communication port string (COMX)
					     GENERIC_READ | GENERIC_WRITE,	// read/write types
					     0,								// comm devices must be opened with exclusive access
					     NULL,							// no security attributes
					     OPEN_EXISTING,					// comm devices must use OPEN_EXISTING
					     FILE_FLAG_OVERLAPPED,			// Async I/O
					     0);							// template must be 0 for comm devices

	if (m_hComm == INVALID_HANDLE_VALUE)
	{
		// port not found
		delete [] szPort;
		delete [] szBaud;

		return FALSE;
	}

	// set the timeout values
	m_CommTimeouts.ReadIntervalTimeout = 1000;
	m_CommTimeouts.ReadTotalTimeoutMultiplier = 1000;
	m_CommTimeouts.ReadTotalTimeoutConstant = 1000;
	m_CommTimeouts.WriteTotalTimeoutMultiplier = 1000;
	m_CommTimeouts.WriteTotalTimeoutConstant = 1000;

	// configure
	if (SetCommTimeouts(m_hComm, &m_CommTimeouts))
	{						   
		if (SetCommMask(m_hComm, dwCommEvents))
		{
			if (GetCommState(m_hComm, &m_dcb))
			{
				m_dcb.fRtsControl = RTS_CONTROL_ENABLE;		// set RTS bit high!
				if (BuildCommDCB(szBaud, &m_dcb))
				{
					if (SetCommState(m_hComm, &m_dcb))
						; // normal operation... continue
					else
						ProcessErrorMessage("SetCommState()");
				}
				else
					ProcessErrorMessage("BuildCommDCB()");
			}
			else
				ProcessErrorMessage("GetCommState()");
		}
		else
			ProcessErrorMessage("SetCommMask()");
	}
	else
		ProcessErrorMessage("SetCommTimeouts()");

	delete [] szPort;
	delete [] szBaud;

	// flush the port
	PurgeComm(m_hComm, PURGE_RXCLEAR | PURGE_TXCLEAR | PURGE_RXABORT | PURGE_TXABORT);

	// release critical section
	LeaveCriticalSection(&m_csCommunicationSync);

	TRACE("Initialisation for communicationport %d completed.\nUse Startmonitor to communicate.\n", portnr);

	return TRUE;
}

//
//  The CommThread Function.
//
UINT CSerialPortEx::CommThread(LPVOID pParam)
{
	// Cast the void pointer passed to the thread back to
	// a pointer of CSerialPort class
	CSerialPortEx *port = (CSerialPortEx*)pParam;
	
	// Set the status variable in the dialog class to
	// TRUE to indicate the thread is running.
	port->m_bThreadAlive = TRUE;	
		
	// Misc. variables
	DWORD BytesTransfered = 0; 
	DWORD Event = 0;
	DWORD CommEvent = 0;
	DWORD dwError = 0;
	COMSTAT comstat;
	BOOL  bResult = TRUE;
		
	// Clear comm buffers at startup
	if (port->m_hComm)		// check if the port is opened
		PurgeComm(port->m_hComm, PURGE_RXCLEAR | PURGE_TXCLEAR | PURGE_RXABORT | PURGE_TXABORT);

	// begin forever loop.  This loop will run as long as the thread is alive.
	for (;;) 
	{ 

		// Make a call to WaitCommEvent().  This call will return immediatly
		// because our port was created as an async port (FILE_FLAG_OVERLAPPED
		// and an m_OverlappedStructerlapped structure specified).  This call will cause the 
		// m_OverlappedStructerlapped element m_OverlappedStruct.hEvent, which is part of the m_hEventArray to 
		// be placed in a non-signeled state if there are no bytes available to be read,
		// or to a signeled state if there are bytes available.  If this event handle 
		// is set to the non-signeled state, it will be set to signeled when a 
		// character arrives at the port.

		// we do this for each port!

		bResult = WaitCommEvent(port->m_hComm, &Event, &port->m_ov);

		if (!bResult)  
		{ 
			// If WaitCommEvent() returns FALSE, process the last error to determin
			// the reason..
			switch (dwError = GetLastError()) 
			{ 
			case ERROR_IO_PENDING: 	
				{ 
					// This is a normal return value if there are no bytes
					// to read at the port.
					// Do nothing and continue
					break;
				}
			case 87:
				{
					// Under Windows NT, this value is returned for some reason.
					// I have not investigated why, but it is also a valid reply
					// Also do nothing and continue.
					break;
				}
			default:
				{
					// All other error codes indicate a serious error has
					// occured.  Process this error.
					port->ProcessErrorMessage("WaitCommEvent()");
					break;
				}
			}
		}
		else
		{
			// If WaitCommEvent() returns TRUE, check to be sure there are
			// actually bytes in the buffer to read.  
			//
			// If you are reading more than one byte at a time from the buffer 
			// (which this program does not do) you will have the situation occur 
			// where the first byte to arrive will cause the WaitForMultipleObjects() 
			// function to stop waiting.  The WaitForMultipleObjects() function 
			// resets the event handle in m_OverlappedStruct.hEvent to the non-signelead state
			// as it returns.  
			//
			// If in the time between the reset of this event and the call to 
			// ReadFile() more bytes arrive, the m_OverlappedStruct.hEvent handle will be set again
			// to the signeled state. When the call to ReadFile() occurs, it will 
			// read all of the bytes from the buffer, and the program will
			// loop back around to WaitCommEvent().
			// 
			// At this point you will be in the situation where m_OverlappedStruct.hEvent is set,
			// but there are no bytes available to read.  If you proceed and call
			// ReadFile(), it will return immediatly due to the async port setup, but
			// GetOverlappedResults() will not return until the next character arrives.
			//
			// It is not desirable for the GetOverlappedResults() function to be in 
			// this state.  The thread shutdown event (event 0) and the WriteFile()
			// event (Event2) will not work if the thread is blocked by GetOverlappedResults().
			//
			// The solution to this is to check the buffer with a call to ClearCommError().
			// This call will reset the event handle, and if there are no bytes to read
			// we can loop back through WaitCommEvent() again, then proceed.
			// If there are really bytes to read, do nothing and proceed.
		
			bResult = ClearCommError(port->m_hComm, &dwError, &comstat);

			if (comstat.cbInQue == 0)
				continue;
		}	// end if bResult

		// Main wait function.  This function will normally block the thread
		// until one of nine events occur that require action.
		Event = WaitForMultipleObjects(3, port->m_hEventArray, FALSE, INFINITE);

		switch (Event)
		{
		case 0:
			{
				// Shutdown event.  This is event zero so it will be
				// the higest priority and be serviced first.

			 	port->m_bThreadAlive = FALSE;
				
				// Kill this thread.  break is not needed, but makes me feel better.
				AfxEndThread(100);
				break;
			}
		case 1:	// read event
			{
				GetCommMask(port->m_hComm, &CommEvent);
				if (CommEvent & EV_CTS)
					::SendMessage(port->m_pOwner->m_hWnd, WM_COMM_CTS_DETECTED, (WPARAM) 0, (LPARAM) port->m_nPortNr);
				if (CommEvent & EV_RXFLAG)
					::SendMessage(port->m_pOwner->m_hWnd, WM_COMM_RXFLAG_DETECTED, (WPARAM) 0, (LPARAM) port->m_nPortNr);
				if (CommEvent & EV_BREAK)
					::SendMessage(port->m_pOwner->m_hWnd, WM_COMM_BREAK_DETECTED, (WPARAM) 0, (LPARAM) port->m_nPortNr);
				if (CommEvent & EV_ERR)
					::SendMessage(port->m_pOwner->m_hWnd, WM_COMM_ERR_DETECTED, (WPARAM) 0, (LPARAM) port->m_nPortNr);
				if (CommEvent & EV_RING)
					::SendMessage(port->m_pOwner->m_hWnd, WM_COMM_RING_DETECTED, (WPARAM) 0, (LPARAM) port->m_nPortNr);
				
				if (CommEvent & EV_RXCHAR)
					// Receive character event from port.
					if(!port->m_bBlockRead)
						ReceiveChar(port, comstat);
					
				break;
			}  
		case 2: // write event
			{
				// Write character event from port
				WriteChar(port);
				break;
			}

		} // end switch

	} // close forever loop

	return 0;
}

//
// start comm watching
//
BOOL CSerialPortEx::StartMonitoring()
{
	if (!(m_Thread = AfxBeginThread(CommThread, this)))
		return FALSE;
	TRACE("Thread started\n");
	return TRUE;	
}

//
// Restart the comm thread
//
BOOL CSerialPortEx::RestartMonitoring()
{

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
99久久99久久精品免费看蜜桃 | 国产精品久久一卡二卡| 亚洲va国产天堂va久久en| 色香色香欲天天天影视综合网| 欧美一区二区三区白人| 国产天堂亚洲国产碰碰| 在线免费观看日本一区| 精品国产不卡一区二区三区| 国产毛片精品视频| 国产91在线观看丝袜| 99久久综合狠狠综合久久| 国产精品欧美久久久久无广告 | 精品欧美一区二区在线观看| 麻豆成人久久精品二区三区红| 91色乱码一区二区三区| 亚洲人吸女人奶水| 久久九九久久九九| 婷婷综合久久一区二区三区| 欧美老年两性高潮| 蜜臀国产一区二区三区在线播放| 日韩午夜精品电影| 精品一区二区三区香蕉蜜桃| 国产亚洲欧洲997久久综合| 国产成人亚洲精品狼色在线| 中文字幕乱码亚洲精品一区| 欧洲精品在线观看| 蜜桃精品在线观看| 中文字幕在线观看不卡视频| 欧美视频在线观看一区| 极品少妇xxxx精品少妇偷拍| 中文字幕在线播放不卡一区| 欧美极品美女视频| 91在线观看视频| 日韩精品色哟哟| 国产精品女同一区二区三区| 欧美私模裸体表演在线观看| 国产精品影视在线| 婷婷成人综合网| 一区二区三区在线视频免费| 久久综合狠狠综合| 在线综合亚洲欧美在线视频| av日韩在线网站| 国产69精品久久久久毛片| 午夜精品福利一区二区三区av | 不卡在线视频中文字幕| 麻豆精品精品国产自在97香蕉| 亚洲亚洲人成综合网络| 欧美高清视频在线高清观看mv色露露十八| 国产高清在线精品| 国产一区二区不卡在线| 日本亚洲天堂网| 日韩av网站免费在线| 视频在线观看一区二区三区| 亚洲欧美日韩久久| 中文字幕一区二区三区乱码在线| 久久久99精品免费观看| 精品嫩草影院久久| 精品欧美一区二区在线观看| 7777精品伊人久久久大香线蕉超级流畅 | 18成人在线视频| 欧美天堂一区二区三区| 99精品视频一区二区三区| 成人高清免费观看| 在线区一区二视频| 欧美浪妇xxxx高跟鞋交| 日韩一区二区三区免费观看| 91麻豆精品国产自产在线 | 亚洲444eee在线观看| 丝袜美腿亚洲色图| 国产在线精品一区二区| 成人深夜在线观看| 精品视频在线免费看| 日韩欧美高清一区| 天堂蜜桃91精品| 日本亚洲一区二区| 成人免费视频一区二区| 欧美日韩视频在线一区二区| 日韩精品一区二区三区三区免费| 中文字幕欧美日韩一区| 亚洲成人一二三| 91影视在线播放| 欧美成人三级在线| 亚洲一二三四久久| 福利一区二区在线观看| 91精品国产91热久久久做人人| 欧美激情一区二区在线| 麻豆精品一二三| 91福利在线看| 亚洲欧美另类久久久精品| 麻豆一区二区三区| 国产三级精品视频| 午夜在线电影亚洲一区| 91色porny在线视频| 国产清纯白嫩初高生在线观看91| 国产乱码精品一区二区三 | 欧美久久久久久蜜桃| 亚洲精品日日夜夜| 色94色欧美sute亚洲线路一ni | 欧美色网一区二区| 中文字幕亚洲成人| 99这里只有久久精品视频| 国产日韩欧美精品综合| 国内精品自线一区二区三区视频| 日韩亚洲欧美高清| 美女脱光内衣内裤视频久久网站| 欧美丰满高潮xxxx喷水动漫| 亚洲一区二区三区四区五区黄| 欧美综合视频在线观看| 亚洲一二三四区不卡| 欧美一级夜夜爽| 激情都市一区二区| √…a在线天堂一区| 欧美日韩一本到| 麻豆精品精品国产自在97香蕉| 欧美大胆人体bbbb| 99久久婷婷国产精品综合| 亚洲欧洲中文日韩久久av乱码| 在线看日韩精品电影| 久久狠狠亚洲综合| 欧美久久久久中文字幕| 视频在线观看国产精品| 亚洲欧美日韩系列| 欧美日韩一区二区在线视频| 日本欧美一区二区| 国产精品午夜久久| 欧美日韩aaa| 成人av动漫在线| 免费看日韩精品| 成人免费在线视频观看| 精品三级在线观看| 欧美色图在线观看| 国产精品69毛片高清亚洲| 亚洲一区二区综合| 国产日韩欧美精品一区| 91麻豆精品国产无毒不卡在线观看| 成人av网站免费观看| 久久99精品国产91久久来源| 天天综合天天做天天综合| 在线看不卡av| 成人国产精品免费观看| 激情久久久久久久久久久久久久久久| 亚洲欧美日韩在线不卡| 中文字幕免费在线观看视频一区| 日韩视频中午一区| 91精品免费观看| 欧美日韩aaaaa| 欧美日韩精品专区| 欧美日韩的一区二区| 欧美在线不卡视频| 欧美日韩中文字幕一区二区| 91一区一区三区| 欧美怡红院视频| 51精品秘密在线观看| 91极品视觉盛宴| 欧美日韩成人一区| 日韩小视频在线观看专区| 日韩丝袜美女视频| 欧美成人精品福利| 日韩欧美不卡在线观看视频| 日韩一区二区免费高清| 日韩欧美高清在线| 中文字幕制服丝袜一区二区三区| 亚洲色图欧洲色图婷婷| 亚洲另类在线制服丝袜| 美女脱光内衣内裤视频久久网站| 久久9热精品视频| 成人中文字幕电影| 欧美色图激情小说| 久久欧美中文字幕| 亚洲另类在线视频| 免费在线观看不卡| 99久久777色| 精品99久久久久久| 亚洲卡通动漫在线| 国产福利91精品一区二区三区| 色哟哟一区二区三区| 日韩欧美国产综合| 亚洲激情第一区| 福利一区二区在线| 欧美大片免费久久精品三p| 亚洲欧美日韩电影| 国产黄色91视频| 3d成人h动漫网站入口| 亚洲精品日产精品乱码不卡| 韩国三级电影一区二区| 欧美日本一区二区| 亚洲午夜精品久久久久久久久| 精品一区二区三区免费| 欧美一级免费大片| 一卡二卡欧美日韩| 色老汉av一区二区三区| 欧美极品另类videosde| 在线观看日韩av先锋影音电影院| 精品欧美乱码久久久久久1区2区| 在线观看亚洲一区| 日韩精品中文字幕一区| 中文字幕一区二| 日韩高清欧美激情| 懂色av一区二区在线播放| 欧美性视频一区二区三区|